java - thread.sleep() 不起作用 - selenium @After,在移动模式下
问题描述
我想在每次运行@Test
. 但我不希望它立即关闭,但要等几秒钟才能关闭。显而易见的选择是使用Thread.sleep()
,但不幸的是,因为我在移动模式下运行它(在移动显示中打开 chrome,就像使用F12它打开一样不起作用!WebDriver 立即关闭并且根本不等待。
当我Thread.sleep()
在常规模式(桌面)下使用时,它工作得很好,但现在不行。所以我的问题是:如何让移动模式的 WebDriver 在关闭前等待几秒钟?
@After
public void tearDown() throws Exception{
Thread.sleep(3000);
driverWrapper_M.quit();
}
这是我的初始化方法(这就是激活移动模式的方法)
public void init(){
Map<String, String> mobileEmulation = new HashMap<String, String>();
mobileEmulation.put("deviceName", "Galaxy S5");
Map<String, Object> chromeOptions = new HashMap<String, Object>();
chromeOptions.put("mobileEmulation", mobileEmulation);
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
remoteWebDriver = new RemoteWebDriver(capabilities);
}
解决方案
推荐阅读
- visual-c++ - 数数说 Leet-C
- sql - Oracle SQL Select:获取连接表的重复结果
- javascript - 在 typecipt 中为类创建动态方法
- python - Pygame:使用 blit 时图像未显示
- webassembly - 如何检测 WASM 部署到的设备?
- asp.net-core - 在 ASP.NET Core MVC 中客户端中止请求时出现未处理的 TaskCancelledException
- ios - 如何使用swift限制仅调用从AppStore安装的应用程序的api
- javascript - XMLHttpRequest 阻止我的曲线显示在脚本中
- javascript - 从使用 URL.createObjectURL 创建的 blob URL 中获取 Blob 对象
- ethereum - NFT:尝试运行 create_collectibles 脚本会引发执行恢复错误:这是来自 Patrick Collins Youtube 教程