Skip to content

Instantly share code, notes, and snippets.

@jimevans
Created November 2, 2021 22:55
Show Gist options
  • Save jimevans/d573a1862aafa5cb7bda00f645ab40b8 to your computer and use it in GitHub Desktop.
Save jimevans/d573a1862aafa5cb7bda00f645ab40b8 to your computer and use it in GitHub Desktop.
IWebDriver driver = new RemoteWebDriver(new Uri("http://localhost:4444"), new ChromeOptions());
ICustomDriverCommandExecutor customCommandDriver = driver as ICustomDriverCommandExecutor;
customCommandDriver.RegisterCustomDriverCommands(ChromeDriver.CustomCommandDefinitions);
ChromiumNetworkConditions networkConditions = new ChromiumNetworkConditions();
networkConditions.IsOffline = true;
Dictionary<string, Object> parameters = new Dictionary<string, object>();
parameters.Add("network_conditions", networkConditions);
customCommandDriver.ExecuteCustomDriverCommand(ChromeDriver.SetNetworkConditionsCommand, parameters);
try
{
driver.Url = "https://www.saucedemo.com";
Console.WriteLine("The navigation should have thrown an exception");
}
catch (WebDriverException)
{
customCommandDriver.ExecuteCustomDriverCommand(ChromeDriver.DeleteNetworkConditionsCommand, null);
}
driver.Url = "https://www.saucedemo.com";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment