How to use webdriver mobile web on desktop browser

不羁岁月 提交于 2019-12-08 01:14:31

问题


I am using selenium webdriver for functional test automation of AUT (Application Under Test). AUT is responsive web and i am almost done with different test case for desktop browser.

Now the same test cases are applicable for mobile browser as well because the AUT can be accessed from mobile browser. As it is responsive web when we open in mobile browser the UI has some different representation. So we need to run those test for mobile browsers as well. For manual testing team using safari browser's user agent feature

Safari Browser menu - > Develop -> User Agent

and it satisfies our need for manual testing.

If we can do the similar thing with automation, i.e. running test on desktop browser with some twik, then it is also accepted to considered as mobile web automation done. My question is how can i do the same thing like modify header, while using web driver. The url is the same because there is only one web app.

My automated test are working fine on firefox using FirefoxDriver and chromeDriver. Both browser has similar development tools available but i am not able to utilise it through automation.

We are using selenium 2.53.0. Our IVY file has following dependencies related to selenium.

<dependency org="org.seleniumhq.selenium" name="selenium-remote-driver" rev="2.53.0"/>
<dependency org="org.seleniumhq.selenium" name="selenium-java" rev="2.53.0"/>

Can anybody provide suggestions and help that how can i run my test to achieve it and what are the related code changes i need to do?

Thanks.


回答1:


Google Chrome provides a mechanism for emulating mobile devices when you instantiate the driver, see the full docs here.

Example:

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);
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
WebDriver driver = new ChromeDriver(capabilities);


来源:https://stackoverflow.com/questions/37319027/how-to-use-webdriver-mobile-web-on-desktop-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!