我使用selenium webDriver运行测试自动化。它在intellij,我的计算机cmd以及服务器cmd(Jenkins通过bat脚本在其上运行)上完美运行。但是,当使用Jenkins运行我的bat文件时,它将引发此异常。
这是我的错误日志(出于安全原因,我更改了一些名称):
Feb 13, 2019 1:25:45 PM org.openqa.selenium.support.ui.ExpectedConditions findElement
WARNING: WebDriverException thrown by findElement(By.cssSelector: a[class="icon-info"])
org.openqa.selenium.UnhandledAlertException: Dismissed user prompt dialog: https://myAuthentification.com is requesting your username and password.:
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:13:22.693Z'
System info: host: 'HOSTSRV', ip: '129.103.116.133', os.name: 'Windows Server 2012 R2', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_141'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 65.0, javascriptEnabled: true, moz:accessibilityChecks: false, moz:geckodriverVersion: 0.23.0, moz:headless: false, moz:processID: 21192, moz:profile: C:\Windows\Temp\rust_mozpro..., moz:shutdownTimeout: 60000, moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, platformVersion: 6.3, rotatable: false, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: f3bbe8e0-771b-484e-82c4-ab165de1cb23
我已经更新了Jenkins和所有插件,更新了firefox,并尝试过switchTo()。alert.accept()是否在不同位置工作。
这是我现在的方法:
protected void checkForEntitlementAutoIt(WebDriver driver) {
// waits for alert to be present, if not throws exception
WebDriverWait wait = new WebDriverWait(driver, Settings.waitAlert);
Alert alert;
try {
try {
wait.until(ExpectedConditions.alertIsPresent());
driver.switchTo().alert();
} catch (Exception e) {
e.printStackTrace();
}
Log.message(driver, "Alert is present.");
} catch(Exception e) {
Log.message(driver, "Alert not present.");
throw e;
}
/* searches for login data
* -> if script present, use script
* -> if not use data in object "login"
*/
try {
if(script != null && new File(script).exists()) {
Log.message(driver, "Executing script.exe ...");
Process runExe = Runtime.getRuntime().exec(script);
runExe.waitFor();
} else {
AutoItScript script = new AutoItScript(login.getEmail(), login.getPW());
script.create();
script.run();
script.delete();
}
//wait for alert again to check if success
try {
wait.until(ExpectedConditions.alertIsPresent());
driver.switchTo().alert().accept();
} catch (Exception e) {
e.printStackTrace();
}
} catch(org.openqa.selenium.NoAlertPresentException E) {
Log.message(driver, "No alert: Authentication succeeded.");
} catch(org.openqa.selenium.TimeoutException E) {
Log.message(driver, "Timeout: Authentication succeeded.");
} catch(InterruptedException | IOException e) {
e.printStackTrace();
Log.message(driver, "Err: Something went wrong. Exiting...");
System.exit(0);
}
}
应该切换到警报窗口,然后执行登录脚本,然后接受警报
答案 0 :(得分:0)
所以我终于找到了一个解决方案,它几乎是太简单了,我不知道为什么我没有更早地这样做(可能是因为我非常关注为什么没有警报的原因)。
我试图找到另一种方法来将我的凭据输入到警报中(在我以前执行带有用户名和密码的额外脚本之前)。
现在,我只是从脚本中获取用户名和密码,并使用“ sendKeys”参数将其放入警报中。有效。
之前
try {
Process execScript = Runtime.getRuntime().exec("autoit/autoit.exe " + this.path + this.file);
execScript.waitFor();
Log.message("Executed script " + this.file + ".");
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
之后
try {
driver.switchTo().alert().sendKeys(this.user+Keys.TAB+this.pw);
Log.message("send keys");
} catch (Exception e) {
e.printStackTrace();
}