简体   繁体   中英

Testing Chrome using Selenium-WebDriver while offline in C#

I am using Chrome, and I would like to be able to run automation tests in C# that tests while the application is offline (I am testing a mobile app with PhoneGap ), and later on get online to complete the tests. Is it possible using WebDriver in Selenium 2 ?

In Google Chrome you can set on developers tool like shown bellow:在此处输入图像描述

But I don't know how to set it automatically on Selenium.

I know there is a way to check if application is online/offline by checking the navigator.onLine property, but I would like to "fake" it's values for testing purposes;

Selenium is only for web based applications, which means that you cannot run your automation tests when application is offline.

It just replicates the user actions / behavior. If your user can access your site being in offline mode, then selenium also can do & vice-versa.

@Tito @Vikram piece of code that works perfect for me:

var driver = new ChromeDriver();
driver.NetworkConditions = new ChromeNetworkConditions()
        { IsOffline = true, DownloadThroughput = 5000, UploadThroughput = 5000, Latency = TimeSpan.FromMilliseconds(5) };

now you are in offline mode. to switch it back you need to set IsOffline = false.

In Selenium4 for C# the property NetworkConditions they promised will be in IWebDriver interface

var driver = new ChromeDriver(); driver.NetworkConditions = new ChromeNetworkConditions() { IsOffline = true, DownloadThroughput = 5000, UploadThroughput = 5000, Latency = TimeSpan.FromMilliseconds(5) };

I can not get this code to work on my .NET6.0 Selenium 4.3.0

Does ChromeNetworkConditions() still exist? If yes, what is the library I should import?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM