【发布时间】:2016-12-21 05:58:48
【问题描述】:
我尝试使用 appium 自动化混合应用程序。我已经完成了整个设置,并且还使用示例 apk 文件进行了测试。我在为我的混合应用程序获取对象属性时遇到问题。我无法使用 Appium 检查器或 uiautomatorviewer 检查 id。它只为我的应用显示一个类。
我还需要启用 WebView 调试,用于制作 setWebContentsDebugging 已启用
在 WebView 类上为真。谁能帮助我如何做到这一点?
有些博客说要保留 driver.context("web_view");但我不清楚如何得到它。请帮助解决这个问题。 谢谢。
这是我的 java 类
public class myMavenTest {
private WebDriver driver;
//i think is not the way to do this.so i comented this.
/*public void onCreate(){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){
if(0 != (getApplicationInfo().flags = ApplicationInfo.FLAG_DEBUGGABLE)){
WebView.setWebContentsDebuggingEnabled(true);
}
}
}*/
@BeforeTest
public void setUp() throws Exception
{
System.out.println("in the setup function");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("deviceName","My Android");
capabilities.setCapability("platformVersion","5.1");
capabilities.setCapability("platformName","Android");
capabilities.setCapability("appPackage","com.mysoftware.testapp");
capabilities.setCapability("appActivity","com.mysoftware.testapp.MainActivity");
try
{
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(5,TimeUnit.SECONDS);
//Thread.sleep(10000);
}
catch(MalformedURLException e)
{
e.printStackTrace();
}
}
@Test
public void Loginforsample() throws Exception
{
System.out.println("in the login() function");
//i tried using classname of my app. but it is not recognizing
driver.findElement(By.className("ink-dark")).click();
//After the button clicks need to enter the text
driver.findElement(By.xpath("//need to find xpath'")).sendKeys("My first Automation");
//tried using selendroid.apk works fine here.
/*driver.findElement(By.id("io.selendroid.testapp:id/startUserRegistration")).click();*/
Thread.sleep(10000);
}
@AfterTest
public void tearDown() throws InterruptedException
{
Thread.sleep(10000);
driver.quit();
}
}
【问题讨论】:
标签: java android selenium-webdriver appium