As mobile device usage continues to increase, the testing of mobile pages becomes increasingly important.
For the Internet company m Station test, if not through the dedicated Appium and other mobile testing tools, whether there is a convenient way to do? The answer, of course, is yes.
Using Chrome driver and chrome and going to Chrome's toggle device mode mode, you'll be able to simulate the phone side, directly below the code.
public class Test{public static void Main (String args[]) {system.setproperty ("Webdriver.chrome.driver", "e:/software/ Automation software/chromedriver.exe "); map<string, string> mobileemulation = new hashmap<string, string> (); Mobileemulation.put ("DeviceName", " Google Nexus 5 "); map<string, object> chromeoptions = new hashmap<string, object> (); Chromeoptions.put ("MobileEmulation", mobileemulation);D esiredcapabilities capabilities = Desiredcapabilities.chrome (); Capabilities.setcapability ( Chromeoptions.capability, chromeoptions); Webdriver Driver = new Chromedriver (capabilities); Navigation navigation=driver.navigate (); Navigation.to ("https://m.baidu.com/"); String Title=driver.gettitle (); System.out.println ("title:" +title);}}
Speaking of the chrome version and the Chromedriver version I used, these two will have pits if they don't fit well.
Chrome version:
Chrome Driver:
Go to this place http://chromedriver.storage.googleapis.com/index.html do not open their own way, haha, download version 2.15 I am the Windows platform, download the 32 that, This way selenium every time the browser is mobile phone mode, you can operate on the mobile phone some tests.
How to use selenium to drive Chrome browser and open mode for phone mode