gpt4 book ai didi

android - Appium:为什么我在提供了所有相关值后仍会在日志中看到 desiredcapabilties 错误?

转载 作者:行者123 更新时间:2023-11-29 20:12:08 25 4
gpt4 key购买 nike

我运行了以下代码,通过 Appium 为 Android 自动化了一个简单的测试:

package appiumtest;

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.*;
import io.appium.java_client.android.AndroidDriver;

import io.appium.java_client.AppiumSetting;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.*;
import org.testng.*;
//import org.junit.*;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.*;

public class AppiumTest {

public static void main(String[] args) throws InterruptedException, MalformedURLException{
// TODO Auto-generated method stub

AppiumTest testcases = new AppiumTest();
testcases.launchtest();
}

public void launchtest() throws InterruptedException, MalformedURLException{
File app = new File("D:\\Radio\\ebayTest.apk");

DesiredCapabilities capabilities = new DesiredCapabilities();

AndroidDriver driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);

capabilities.setCapability(CapabilityType.BROWSER_NAME,"");
capabilities.setCapability("platformname", "Android");
capabilities.setCapability(CapabilityType.VERSION,"4.4.2");
capabilities.setCapability("deviceName", "07d4bb0a00caa300");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appPackage", "com.ebay.mobile");
capabilities.setCapability("appActivity", ".activities.eBay");

Thread.sleep(3000);

System.out.println("App launched");

WebElement signin = driver.findElement(By.id("button_sign_in"));
signin.click();
Thread.sleep(4000);
}
}

现在在运行测试后,我不断地在日志和 Appium 服务器窗口中看到如下所示的错误消息:

Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: The following desired capabilities are required, but were not provided: deviceName) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 200 milliseconds

为什么我会看到这条错误消息?我在 Desired Capabilities 中提供了正确的设备名称参数,如“adb devices”中所示。

最佳答案

在设置所有功能之前,您使用这些功能初始化了驱动程序。

移动这一行 AndroidDriver driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);在这一行之后 capabilities.setCapability("appActivity", ".activities.eBay");

关于android - Appium:为什么我在提供了所有相关值后仍会在日志中看到 desiredcapabilties 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34589596/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com