Now a days many apps are hybrid. Hybrid apps means app containing Web Views. We have seen in previous post that how to perform different kinds of interaction with native android app using Appium but now it time see the how to perform web interaction on Web Views. We just have to notify the appium that we will be testing Web Views from the specific point in the test case and appium WebDriver handles it for us.Let us how to do with a simple example.
How to Inspect Web Views in Chrome Browser -
1. Go to chrome browser
2. Connect the Device with USB Debugging ON
3. Type this url -chrome://inspect/devices#devices
4. click on any url listed on web page.
5. Then click on any UI element and you will get associated html source code which you can use to write your own xpath.
![]() |
Enable USB Debugging |
3. Type this url -chrome://inspect/devices#devices
![]() |
Chrome inspector |
4. click on any url listed on web page.
![]() |
Chrome inspector console |
5. Then click on any UI element and you will get associated html source code which you can use to write your own xpath.
App under testing -
Suppose
you have a app with a Web page Displaying a Login screen which displays
page Title "WELCOME". The app also displays two text-boxes first to
enter email id and second to enter password and there are two button
"Cancel" and "Submit". After click on Submit the page shows
"Successfully Logged In".
How to Switch To Web Views -
Check
out the code sample given below which switched to web view and then
test cases perform actions mentioned in your code on directly on the Web
Views.
// Switch to WebView
Set<String> contextNames = driver.getContextHandles();
System.out.println(contextName s.size());
for (String contextName : contextNames) {
System.out.println(contextName );
if (contextName.contains(" WEBVIEW")){
driver.context(contextName);
}
Test Scenario-
1. First test that title "WELCOME" is displayed.
2.Test that two text-boxes are displayed and two buttons are also displayed.
3. Enter email is and password.
4. click on Submit
5. Test Success Message is displayed.
Appium Test Case-
@Test public void testWebViews()throws Exception { // Switch to WebView Set<String> contextNames = driver.getContextHandles(); System.out.println(contextNames.size()); for (String contextName : contextNames) { System.out.println(contextName); if (contextName.contains("WEBVIEW")){ driver.context(contextName); } } // check WELCOME text is present Assert.assertEquals("WELCOME", driver.findElement(By.id("welcome_text")).getText()); //Check UI elements text boxes and buttons are present on the page Assert.assertTrue(driver.findElementById("email_edit").isDisplayed()); Assert.assertTrue(driver.findElementById("password_edit").isDisplayed()); Assert.assertTrue(driver.findElementById("cancel_button").isDisplayed()); Assert.assertTrue(driver.findElementById("submit_button").isDisplayed()); //enter email id and password driver.findElementById("email_edit").sendKeys("anujabhatt88@gmail.com"); driver.findElementById("password_edit").sendKeys("12345"); // /click on submit button driver.findElementById("submit_button").click(); //Explicit wait for submission Thread.sleep(3000); //Check for successful submission Assert.assertEquals("Successfully Logged In",driver.findElementById("display_text")); }
Now you can start testing web views in Appium :-)
If you find this post helpful then pleas share your feedback in comments section below. Do follow me on social media for latest post updates. Thanks :-)
Nice Article.
ReplyDeleteCould you please explain how can we identify web element in hybrid app when we switch to web view.
Thanks!!
Hi,
DeleteThanks for visiting my blog. You can use chrome inspector to create xpath to find web elements . check out http://qaautomated.blogspot.in/2016/02/how-to-locate-android-app-ui-elements.html
Great Article IoT Projects for Students
DeleteDeep Learning Projects for Final Year
JavaScript Training in Chennai
JavaScript Training in Chennai
The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training
This comment has been removed by a blog administrator.
ReplyDeleteI wondered upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon.
ReplyDeleteMobile App Development Company
Mobile App Development Companies
Best informative post that I have never seen. You are great with your this job.I am happy to see and follow your post every time. Thank you.
ReplyDeletedigital marketing services in delhi
ReplyDeleteHealth Is God aims to deliver the best possible health reviews of the supplement collections and other wellness production that range from skincare to brain, muscle, male enhancement and brain health conditions. You, the user are of utmost importance to us, and we are committed to being the portal that sustains your healthy lifestyle. Visit for more- Health is God
Fantastic article to go through, I would appreciate the writer's mind and the skills he has presented this great article to get its look in better style. It really brushed up my mind and I am now feeling very much relaxed after getting complete summary regarding every singl aspect of the article, once again I would like to thank you for such great creativity. Fmovies
ReplyDelete"I like this post,And I guess that they having fun to read this post,they shall take a good site to make a information,thanks for sharing it to me.
ReplyDeleteRead more here:
kim kardashian sex tape
porn sex video hd
mia khalifa sex video
sunny leone sexy movie
It is a great job, I like your posts and wish you all the best. and I hope you continue this job well.
ReplyDeleteNutraT line
Hello, I am thomus jons thank you for this informative post. That is a great job. Wish you more success.Thank you so much and for you all the best. Takes Down
ReplyDelete123movies