"Pro-Test" Appium test Android Hybrid app, the second switch to WebView failed

Source: Internet
Author: User

Problem to solve: Appium When testing Android hybrid app, the second time switching to WebView failed

Cause Analysis: When testing Android hybrid applications with Appium, automated tests can be performed normally when the program switches to WebView for the first time. However, when the program switches to WebView for the second time, Appium will automatically find the HTML page that was opened for the first time, so appium cannot locate the element in the HTML page we opened the second time.

Appium The first time you switch to an HTML page, it will be reborn as a chromedriver; when you switch to HTML for the second time, the existing chromedriver is used. But in fact, in our application every time we open an activity, we usually recreate a webchromeclient, so we'll change it to create a new chromedriver anyway.

Resolution steps: Modify Appium source code

Appium files under the installation directory

Appium\node_modules\appium\lib\devices\android\android-hybrid.js, there is a function in the file:

Androidhybrid. Startchromedriverproxy =function (Context, CB) {cb =_. once (CB); Logger. Debug ("Connecting to chrome-backed WebView");if (This. Chromedriver!==null) {return CB (new Error ( "We already h        Ave A Chromedriver instance running ")); } if (thiscontext]) {//in the case where we ' ve a Lready set up a chromedriver for a context, //we want to reconnect to it, not create a W Hole New One this.setupexistingchromedriver (context, CB); } else {thiscontext, CB); }};                

Switch

Androidhybrid.startchromedriverproxy =function (Context, CB) {cb = _.once (CB); Logger.debug ("Connecting to chrome-backed WebView");if (this.chromedriver!== null) { Return CB (new error ( "We already       Have a Chromedriver instance running ")); } //if (This.sessionchromedrivers[context]) {////In The case where we ' ve already set up a chromedriver for a context, ////We want to recon       Nect to it, not create a whole new one //this.setupexistingchromedriver (context, CB);        //} else {//this.setupnewchromedriver (context, CB);        //}      this.setupnewchromedriver (context, CB); };

"pro-Test" Appium test Android Hybrid app, the second switch to WebView failed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.