我正在尝试在我的Android设备上运行测试并使用Selenium Webdriver和Java。目前,只启动.apk。 Selendroid Inspector无法加载属性。它显示加载进度条,无法加载Web元素查看器。 相关登录系统代码:
'Ext.define('TutorialApp.view.login.Login', {
extend: 'Ext.window.Window',
xtype: 'login',
requires: [
'TutorialApp.view.login.LoginController',
'Ext.form.Panel'
],
controller: 'login',
bodyPadding: 10,
title: 'Login Window',
closable: false,
autoShow: true,
items: {
xtype: 'form',
reference: 'form',
items: [{
xtype: 'textfield',
name: 'username',
fieldLabel: 'Username',
allowBlank: false
}, {
xtype: 'textfield',
name: 'password',
inputType: 'password',
fieldLabel: 'Password',
allowBlank: false
}, {
xtype: 'displayfield',
hideEmptyLabel: false,
value: 'Enter any non-blank password'
}],
buttons: [{
text: 'Login',
formBind: true,
listeners: {
click: 'onLoginClick'
}
}]
}
});
这是我的代码:
import io.selendroid.SelendroidCapabilities;
import io.selendroid.SelendroidConfiguration;
import io.selendroid.SelendroidDriver;
import io.selendroid.SelendroidLauncher;
import io.selendroid.device.DeviceTargetPlatform;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
public class NewTest {
private WebDriver driver;
@BeforeSuite
public void setUp() throws Exception {
SelendroidConfiguration config = new SelendroidConfiguration();
config.addSupportedApp("test.apk");
SelendroidLauncher selendroidServer = new SelendroidLauncher(config);
selendroidServer.launchSelendroid();
SelendroidCapabilities capa = new SelendroidCapabilities();
capa.setAut("de.bgk:1.0.4");
capa.setPlatformVersion(DeviceTargetPlatform.ANDROID19);
capa.setEmulator(false);
driver = new SelendroidDriver(capa);
}
@Test
public void selendroidTest() throws Exception {
System.out.print("Start executing test");
Thread.sleep(10000);
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("username")));
driver.findElement(By.name("username")).sendKeys("user");
driver.findElement(By.name("password")).sendKeys("password");
driver.findElement(By.linkText("Login")).click();
}
@AfterSuite
public void tearDown() {
driver.quit();
}
}
如何使用Java解决Selendroid中的这个问题?将不胜感激任何帮助。