通过 Selenium 对 Web 应用程序进行 Safari 移动仿真 [英] Safari mobile emulation for web app via Selenium

查看:135
本文介绍了通过 Selenium 对 Web 应用程序进行 Safari 移动仿真的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要测试 Web 应用的响应式设计.我知道浏览器不像真实设备甚至设备模拟器那样模拟,但我不需要它.注意:我希望不在模拟器中运行 Safari,而是在 Safari 中激活移动模拟器

Need to test responsive design for web app. I understand that browser didn't emulate like real device or even device emulator, but i don't need it. Note: i'm looking for not to run Safari inside emulator, but to activate mobile emulation in Safari

问题 1:是否可以使用预定义的移动仿真通过 selenium 启动 Safari,例如在 Chrome here

question 1: Is it possible to start Safari via selenium with predefined mobile emulation, like in Chrome here

Map<String, String> mobileEmulation = new HashMap<>();
mobileEmulation.put("deviceName", "Nexus 5");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setExperimentalOption("mobileEmulation", mobileEmulation);
WebDriver driver = new ChromeDriver(chromeOptions);

如果回答(假设为否),问题 2:将 Safari 窗口大小调整为所需的设备视口大小是否足够?

if answer no(assume it will be no), question 2: is it enough to resize Safari window to required device viewport size?

推荐答案

设置浏览器宽度是不够的,因为当今的许多网页都使用用户代理作为确定正在查看页面的设备的方法.Afaik,没有办法,我一直在努力寻找解决方案.Safari 不提供自动控制来设置用户代理或其桌面浏览器的移动模式.

Setting the browser width isn't enough as many of today's web pages use the useragent as a means to determine the device that is viewing the page. Afaik, there is no way and I've been trying to find a solution to this for a while. Safari doesn't give automated control to set the user agent nor the mobile mode of its desktop browser.

这里有一种方法可以做你想做的事:https://webkit.org/blog/9395/webdriver-is-coming-to-safari-in-ios-13/

There is a way to do what you want here though: https://webkit.org/blog/9395/webdriver-is-coming-to-safari-in-ios-13/

但要求是您需要将 iPhone 连接到您的笔记本电脑来运行测试,并且您需要将这些功能添加到您的配置中

But the requirement is you need an iPhone connected to your laptop to run the test from and you need to add these capabilities to your configuration

safari:deviceType
safari:useSimulator

阅读 safaridriver 的 man 文件以了解更多信息.

Read the man file for safaridriver for more info.

如果需要设置useragent,可以通过命令行进行,但是需要在https://tarunlalwani.com/post/selenium-change-user-agent-different-browsers/

If you need to set the useragent, you can do it via the command line, but you need to reset it after https://tarunlalwani.com/post/selenium-change-user-agent-different-browsers/

这篇关于通过 Selenium 对 Web 应用程序进行 Safari 移动仿真的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆