Selenium run H5 Web page using Google Chrome's own phone simulator

Source: Internet
Author: User

Background: The first to use mobile phone simulation H5 page run automation, found often because of the app connection or network reasons, such as a series of circumstances, resulting in M version (H5 page) Use cases run, want to run through the browser's own mobile phone simulator, to ensure stability

The browser comes with an emulator such as:

Code implementation Logic

 Public classruntest {webdriver driver; @BeforeClass Public voidBeforeclass () {System.setproperty ("Webdriver.chrome.driver", "Resources/chromedriver.exe"); Map<string, string> mobileemulation =NewHashmap<string, string>(); //set up your device, for example: Google Nexus 7/apple iPhone 6//mobileemulation.put ("DeviceName", "Google Nexus 7");Mobileemulation.put ("DeviceName", "Apple IPhone 6 Plus"); Here is the name of the emulator to use, which is the top Model MAP in the emulator in the browser<string, object> chromeoptions =NewHashmap<string, object>(); Chromeoptions.put ("Mobileemulation", mobileemulation); Desiredcapabilities Capabilities=Desiredcapabilities.chrome ();        Capabilities.setcapability (chromeoptions.capability, chromeoptions); Try{System.out.println ("Start driver~~~"); Driver=NewChromedriver (capabilities); System.out.println ("Start Driver Success ~ ~ ~"); } Catch(Exception e) {System.out.println ("Startup driver failed ~ ~ ~");        System.out.println (E.getmessage ()); }} @Test Public voidrun () {Driver.get ("http://m.baidu.com/"); System.out.println ("Use the browser, go to the Baidu page"); }

Effect

Selenium run H5 Web page using Google Chrome's own phone simulator

Related Article

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.