簡體   English   中英

使用 Selenium Java 在測試中途終止網絡連接

[英]Kill network connection in the middle of the test using Selenium Java

我試圖在測試過程中殺死我的網絡。 當我殺死網絡時,系統應該會提示一個對話框,說網絡已經消失。 當我手動執行此操作時,我得到了對話框。 我使用了以下代碼,

 public void exitBrowserTab() throws IOException { WebDriver driver = new ChromeDriver(); driver.get("url"); driver.findElement(By.id("login-username")).sendKeys("username"); driver.findElement(By.id("login-password")).sendKeys("password"); driver.findElement(By.id("signin-button")).click(); Map map = new HashMap(); map.put("offline", true); map.put("latency", 5); map.put("download_throughput", 500); map.put("upload_throughput", 1024); CommandExecutor executor = ((ChromeDriver)driver).getCommandExecutor(); Response response = executor.execute(new Command(((ChromeDriver)driver).getSessionId(), "setNetworkConditions", ImmutableMap.of("network_conditions", ImmutableMap.copyOf(map)))); }

當我運行這段代碼時,它不會給我那個對話框。 但是,當我刷新頁面時,它告訴我沒有網絡。

我做錯了什么?

手動步驟 -

  1. Go 到 url
  2. 登錄成功
  3. 網絡掉線
  4. 出現對話框

我可以使用 bash 命令關閉互聯網,

Runtime.getRuntime().exec("cmd /c ipconfig /release");

並使用它重新打開,

Runtime.getRuntime().exec("cmd /c ipconfig /renew");

這將自動關閉您的 wifi 並再次打開。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM