private WebDriver driver;
@BeforeMethod
public void setUp() throws Exception {
// set up appium
BasicConfigurator.configure();
File appDir = new File("This PC\\GT-I9100\\Phone\\360");
File app = new File(appDir, "app-release.apk"); //my case “demo1.apk”
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("device","Android");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability(CapabilityType.VERSION, "4.2");
capabilities.setCapability(CapabilityType.PLATFORM, "WINDOW");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("app-package", "app-release.apk"); //my case com.gorillalogic.monkeytalk.demo1
capabilities.setCapability("app-activity", "Login"); //my case RootActivity
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
@AfterMethod
public void tearDown() throws Exception {
driver.quit();
}
@Test
public void loginTest() throws Throwable
{
System.out.println("Hello");
System.out.println(driver);
setUp();
}
@Test
public void formTest() throws InterruptedException
{
System.out.println("Hello");
System.out.println(driver);
/ *在appium移动自动化测试的selenium web驱动程序中获取驱动程序值为null
获取驱动程序值为null。 使用的设备名称然后我也得到空值 我连接了我的真实设备。* /
答案 0 :(得分:1)
在实例化AndroidDriver()...
时添加try / catch块也许那里出了点问题。试试这段代码
new DesiredCapabilities();
DesiredCapabilities capabilities = DesiredCapabilities.android();
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME,"Android");
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME,"Chrome");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME,"0123456789ABCDEF");
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION,"4.4");
try
{
linker = new URL("http://127.0.0.1:4723/wd/hub");
driver = new AndroidDriver(linker, capabilities);
driver.manage().timeouts().pageLoadTimeout(120, TimeUnit.SECONDS);
}
catch (MalformedURLException e)
{
System.out.println("URL init error");
}
干杯