我们如何使用 Chrome 中的 webdriver 运行自动化测试来测试也应该在离线模式下工作的应用程序?

发布于 2025-01-05 18:04:51 字数 332 浏览 6 评论 0原文

我尝试添加 ' profile['network.manage-offline-status'] = true' 但这似乎并未将 chrome 浏览器转为离线模式

        profile = Selenium::WebDriver::Chrome::Profile.new
        profile['default_search_provider.enabled'] = false
        profile['network.manage-offline-status'] = true
        profile['homepage'] = 'about:blank'

I have tried adding ' profile['network.manage-offline-status'] = true' but this doesn't seem to be turning the chrome browser to offline mode

        profile = Selenium::WebDriver::Chrome::Profile.new
        profile['default_search_provider.enabled'] = false
        profile['network.manage-offline-status'] = true
        profile['homepage'] = 'about:blank'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

并安 2025-01-12 18:04:51

谷歌搜索该配置文件设置,看起来这只是 Firefox 设置,因此对 Chrome 实例没有影响。

阅读一些有关 Chrome 的信息,似乎没有简单的选项可以进入“离线模式”。

您可以通过 watir-webdriver 手动断开计算机与 Internet 的连接来测试功能,但这对于自动化测试来说并不是一个好的解决方案。

Googling that profile setting, it looks like it's only a Firefox setting, so will have no effect on an instance of Chrome.

Reading a little about Chrome, it appears there is no simple option for going into an "offline mode".

You could test the functionality through watir-webdriver by manually disconnecting your computer from the Internet, but that's not a good solution for automated tests.

吻风 2025-01-12 18:04:51

如果您使用 Chrome 浏览器和 java selenium 那么下面是我使用的代码:

((JavascriptExecutor) driver).executeScript("app.isConnected = true;");

“app.isConnected = true;” : 是我用来转到离线然后返回在线的控制台命令

if you are using Chrome browser and java selenium then below is the code which I have used:

((JavascriptExecutor) driver).executeScript("app.isConnected = true;");

"app.isConnected = true;" : is the console command which I am using to goto Offline and then back to Online

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文