4

I had developed a hybrid app using ionic framework . Now its time to test my app, so I had choose appium to Automate it. I had kept appium setup ready and my app is installed in my device is connected through usb.

I had written a sample test to chick the login button and send keys to the required fields like email and pwd. I had use uiautomatorviewer to find my elements with id. eg: driver.findElement(By.id("io.mysoft.testapp:id/login")).click();

Everything is clear and perfect up to now but my sample test failed showing me errors like

FAILED: Loginforsample
org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 5.51 seconds

After a long research I came to know that we have to switch to WEB_VIEW in the testing logic by driver.context("WEB_VIEW");. I also tried to get WEB_VIEW using following code:

Set<String> contextNames = ((AppiumDriver) driver).getContextHandles();
        for (String contextName : contextNames) {
            System.out.println("FIRST" + contextNames);//output is //NATIV_APP
            ((AppiumDriver) driver).context(contextName);     
        }

I am getting only NATIV_APP form the array but no WEB_VIEW printed. I have researched on that to enable WEB_VIEW debugging we have to call the static method setWebContentsDebuggingEnabled on the webView Class so that our will be on webView to find elements and test it clear.

I am an angular developer I choose ionic to develop hybrid apps. There is no classes or anything in my app ie no java here while coding. And the question that eats my brain is how to enable setWebContentsDebuggingEnabled in my ionic app(hybrid)? is there any way to get the web_view from ionic hybrid apps? I think this is the main reason for my test got failed. Please please any one has a solution on that. I had been working on that for the past one week.

Thanks in advance.

Sukumar MS
  • 748
  • 1
  • 11
  • 42
  • Your first test may only fail because your test start before the web_view is rendred. For example wait or delay your test(rendered page). This may the only reason why org.openqa.selenium.NoSuchElementException is present. Hope it helps. – Destrif Jan 30 '17 at 16:51
  • thanks for reply. i tried it but i am not getting WEB_VIEW from method call getContentHanles(); – Sukumar MS Jan 31 '17 at 03:17
  • i haven't enable webview in my app, can u tell me how to do that @destrif – Sukumar MS Jan 31 '17 at 04:15

1 Answers1

1

You need to enable setWebContentsDebuggingEnabled in android app. Please refer this link for enabling in android app.

Also, Once you get the WEB_VIEW you can directly find elements inside the Web View. For that, you need to update your Android SDK. The latest UIAutomator has inbuilt capabilities to find the elements inside web view without switching the context.

You need Android device with OS Version 6.0+ to automate the script and after automating the script you can use the same for devices with lower OS versions than 6.0.

I have already answered the similar question here. You can refer this.

I hope this helps :)

Community
  • 1
  • 1
Vinod
  • 956
  • 7
  • 15