当我在jenkins上运行自动化测试时,有时会跳过一些测试。我收到以下错误:org.openqa.selenium.WebDriverException:chrome无法访问。
如果在google上读取该内容,则会在初始化webdriver实例时出现错误。这使得测试跳过并使chromedriver.exe进程仍在运行。
有没有办法处理异常,所以当发生这种情况时,我可以杀死进程?或者如何解决问题,以便不跳过测试。下面是我如何初始化chromedriver的代码。
private void chromeDriverSetUp(){
System.setProperty(DRIVER_PATH_PROPERTY_NAME, DRIVER_PATH);
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("nativeEvents", true);
ChromeOptions options = new ChromeOptions();
options.addArguments("--lang=es");
options.addArguments("--disable-extensions");
options.addArguments("start-maximized");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(capabilities);
}
这是抛出异常时失败的方法:
@Parameters({"subModel", "moduleName", "testName", "testLinkName"})
@BeforeMethod
public void handleTestMethodName(Method method, String subModel, String moduleName, String testName, String testLinkName) throws Exception
{
this.subModel=subModel;
this.moduleName = moduleName;
this.testName = testName;
this.testLinkName = testLinkName;
this.testMethod = method.getName();
this.testClass = method.getDeclaringClass().getSimpleName();
initializeSelenium();
String modulo = "";
if(subModel.equalsIgnoreCase("ISSUER")){
modulo = PropertiesManager.getInstance().getProperty(EPropertiesNames.MOD_ISSUER);
}else{
modulo = PropertiesManager.getInstance().getProperty(EPropertiesNames.MOD_ACQUIRER);
}
setCMSModulo(modulo);
startAccess();
}