Automated test settings Browser properties to simulate H5 testing on mobile devices

Source: Internet
Author: User

Due to the need to test H5, you need to set the screen size of the page to simulate the phone browser. The Chrome browser comes with an emulator, which is the icon for the small mobile phone number on the F12 development toolbar. Manually Click to select the phone model to simulate. But if you need to set the browser to automate the script to automatically turn into a mobile browser screen size is, how to do it. Hate research debugging finally found a most complete answer. Find a lot of pits on the internet, will lose the most critical step. The setup code is posted here. Pro-Test available

Browser Setup code (for example in Chrome)

//设置浏览器driver       System.setProperty("webdriver.chrome.driver", "tools/chromedriver.exe");     //浏览器选项设置     ChromeOptions options = new ChromeOptions();     options.addArguments("lang_zh_CN.UTF-8");     //这步是关键哦,指定的浏览器size,对应手机型号的size     options.addArguments("window-size=375,667");     options.addArguments("user-agent=\"Mozilla/5.0 (iPhone; CPU iPhone OS 11_2 like Mac OS X) AppleWebKit/604.4.7 (KHTML, like Gecko) Version/11.0 Mobile/15C114 Safari/604.1\"");     DesiredCapabilities cap = DesiredCapabilities.chrome();     cap.setCapability(ChromeOptions.CAPABILITY, options);     WebDriver driver = new ChromeDriver(options);//   driver.manage().window().maximize();     driver.get("https://www.baidu.com");

The effect of opening after operation see:

Automated test settings Browser properties to simulate H5 testing on mobile devices

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.