首页 > 解决方案 > 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);
}

标签: javaseleniumselenium-webdriverautomation

解决方案


推荐阅读