Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Set browser properties for automated testing to simulate H5 testing on mobile devices

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

Due to the need to test H6, you need to set the page to simulate the screen size of the mobile browser. The chrome browser comes with a simulator, that is, the icon of the small mobile number on the development toolbar after F12. After manual click, you can choose the mobile phone model to simulate. But if you need to set the screen size of the browser to automatically change to the mobile browser when executing the automation script, how to do it. I hate to research and debug and finally find the most complete answer. Look for a lot of holes on the Internet, will lose the most crucial step. The setting code is posted here. Self-testing is available

Browser setting code (take chrome browser as an example)

/ / set browser driver System.setProperty ("webdriver.chrome.driver", "tools/chromedriver.exe"); / / set browser options ChromeOptions options = new ChromeOptions (); options.addArguments ("lang_zh_CN.UTF-8"); / / this step is critical. Specify browser size, corresponding to the size options.addArguments of the phone model ("window-size=375667"). Options.addArguments ("user-agent=\" Mozilla/5.0 (iPhone; CPU iPhone OS 1132 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 it after running is shown below:

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report