- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个这样的测试用例:
这是代码的相关部分:
public JpoPO() {
driver.get(Settings.JPO_TEST_URL);
PageFactory.initElements(driver, this);
System.out.println("[INFO] Homepage initialized.");
zatvoriModal();
refreshIfNeeded();
zatvoriModal();
(new WebDriverWait(driver, 30)).until(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector("#loading")));
System.out.println("[DEBUG] broj .ng-scope elemenata: " +driver.findElements(By.cssSelector(".ng-scope")).size());
System.out.println("[OK] JpoPO() initialized.");
}
这是 refreshIfNeeded()
部分:
public void refreshIfNeeded() {
if(System.getProperty("os.name").equals("Linux")){
System.out.println("### A"+now());
int broj = driver.findElements(By.cssSelector(".ng-scope")).size();
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("location.reload()");
//driver.findElement(By.cssSelector("header")).sendKeys(Keys.F5);
driver.get(driver.getCurrentUrl());
waitForNoSpinner();
System.out.println("[DEBUG] location reloaded, .ng-scope elements: "+broj);
System.out.println("### B"+now());
}else{
System.out.println("[] Starting refreshIfNeeded()");
Date ts1 = new Date();
int count = 0;
while (driver.findElements(By.cssSelector(".ng-scope")).size()==0 && count < 10){
driver.navigate().refresh();
zatvoriModal();
try {
(new WebDriverWait(driver, 10)).until(ExpectedConditions.numberOfElementsToBeMoreThan(By.cssSelector(".ng-scope"), 0));
Date ts2 = new Date();
long trajanje = ts2.getTime() - ts1.getTime();
System.out.println(String.format("[INFO] Učitavanje sadržaja: %s ms.", trajanje));
} catch (Exception e){
try {
Thread.sleep(3000);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
System.out.println("[] Count: "+count);
count++;
}
}
}
在我的Windows 机器上本地 运行时一切正常,但是当它在远程 Jenkins linux 机器上运行时刷新没有' 似乎工作。
这是 Jenkins 控制台输出:
16:18:48 [INFO] Homepage initialized.
16:18:48 ### A2019-10-30T16:18:48.904
16:18:49 [INFO] Spinner (ili uvjet čekanja) je trajao: 117 ms. (waitForNoSpinner-try)
16:18:49 [INFO] Spinner (ili uvjet čekanja) je trajao: 89 ms. (waitForNoSpinner-finally)
16:18:49 [DEBUG] location reloaded, .ng-scope elements: 0
16:18:49 ### B2019-10-30T16:18:49.417
16:18:49 [DEBUG] broj .ng-scope elemenata: 0
16:18:49 [OK] JpoPO() initialized.
尝试查找除非刷新页面否则不存在的元素时,测试在以下步骤中失败。这也通过我无法分享的屏幕截图得到了证实。
有多种使用 Selenium here 刷新页面的方法,但没有一种有效。
似乎 js.executeScript("location.reload()")
和 driver.navigate().refresh()
都不起作用。
我正在使用以下 Chromedriver 选项:
if(System.getProperty("os.name").equals("Linux")){
options.addArguments("--headless");
options.addArguments("--proxy-server='direct://'");
options.addArguments("--proxy-bypass-list=*");
options.addArguments("--window-size=1200,800");
WebDriverManager.chromedriver().version("77.0.3865.40").setup();
}
编辑:
当我尝试使用 Robot 类刷新时,我会得到一个 java.awt.AWTException: headless environment
所以我添加了 System.setProperty("java.awt.headless", "false");
到我的代码。
现在我得到一个
java.awt.AWTError: Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.
我对 Linux 几乎一无所知,难道这就是原因吗?
最佳答案
您在刷新之前存储 .ng-scope
元素的大小,之后不获取大小。这就是您在日志中得到 0 的原因。您应该搜索 waitForNoSpinner
之后的元素以获取更新大小值:
if(System.getProperty("os.name").equals("Linux")){
System.out.println("### A"+now());
int broj = driver.findElements(By.cssSelector(".ng-scope")).size();
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("location.reload()");
//driver.findElement(By.cssSelector("header")).sendKeys(Keys.F5);
driver.get(driver.getCurrentUrl());
waitForNoSpinner();
broj = wait.until(ExpectedConditions.numberOfElementsToBeMoreThan(By.cssSelector(".ng-scope"), 0)).size();
System.out.println("[DEBUG] location reloaded, .ng-scope elements: "+ broj);
System.out.println("### B"+now());
}
这是替代的refreshIfNeeded
方法,其中waitForNoSpinner
和zatvoriModal
基于操作系统。如果 waitForNoSpinner
和 zatvoriModal
之间没有区别,则将 if
替换为其中之一。如果在 20 秒后找不到 .ng-scope
,方法将抛出 TimeoutException
:
public void refreshIfNeeded() {
WebDriverWait wait = new WebDriverWait(driver, 20, 1000);
System.out.println("[DEBUG] check .ng-scope elements and refresh if not located");
wait.until(d -> {
if (d.findElements(By.cssSelector(".ng-scope")).isEmpty()) {
System.out.println("[DEBUG] no .ng-scope elements, refresh..");
driver.navigate().refresh();
waitForNoSpinner();
/*if (System.getProperty("os.name").equals("Linux")) {
waitForNoSpinner();
} else {
zatvoriModal();
}*/
}
return !d.findElements(By.cssSelector(".ng-scope")).isEmpty();
});
System.out.println("[DEBUG] .ng-scope elements: " + driver.findElements(By.cssSelector(".ng-scope")).size());
}
带循环:
public void refreshIfNeeded() throws InterruptedException {
WebDriverWait wait = new WebDriverWait(driver, 20, 1000);
System.out.println("[DEBUG] check .ng-scope elements and refresh if not located");
for (int i=0; i < 10; i++) {
try {
wait.until(d -> {
if (d.findElements(By.cssSelector(".ng-scope")).isEmpty()) {
System.out.println("[DEBUG] no .ng-scope elements, refresh..");
driver.navigate().refresh();
if (System.getProperty("os.name").equals("Linux")) {
waitForNoSpinner();
} else {
zatvoriModal();
}
}
return !d.findElements(By.cssSelector(".ng-scope")).isEmpty();
});
break;
} catch (Exception e) {
Thread.sleep(3000);
}
}
}
关于linux - Selenium 不会刷新 Jenkins 上的页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58629302/
Selenium IDE、Selenium RC 和 Selenium WebDriver 有什么区别;我们可以在什么样的项目中使用它们?任何建议将不胜感激。 最佳答案 Selenium IDE 是一
我的 Selenium 服务器在远程服务器上运行。我从我的本地 PC 启动我的 Selenium 脚本,它从网站获取数据。 例如,我的 Selenium 脚本执行这段 JS 代码: JSON.stri
Selenium 中“//div[.//a[text()='SELENIUM']]”和“//div[//a[text()='SELENIUM']]”有什么区别xpath。 有人可以澄清我在 xpath
我正在创建自动冒烟测试。我读到在单元测试中使用多个断言不是一个好的做法,这条规则是否也适用于使用 selenium 的 webdriver 测试? 在我的冒烟测试中,有时我会使用 20 多个断言来验证
我在一个变量中存储了一个值,在另一个变量中存储了第二个值,现在我想将这两个数字相加。我无法做到这一点,我尝试过下面的代码,但它不起作用 store 6 w sto
Selenium 中的回车键和回车键有什么区别? This related SO answer并且提供的链接说明它们是不同的。我还注意到,在使用 Firefox 24.2 时,回车键将发送一个 HTM
以下是我遇到异常的详细信息: 当我使用以下命令启动节点时,出现如下错误: F:\SeleniumGrid\Jars>java -jar selenium-server-standalone-3.0.0
我是 的新手 Selenium 我对版本号有点困惑。 Selenium 2.0 2011年发布。我刚刚下载了 Selenium IDE Firefox 扩展,版本为 1.7.2 .是否还有 IDE 的
我正在使用 Selenium 运行Codeception 2。我可以看到 Selenium 打开了浏览器并运行了测试。然后,我从代码接收中得到一个错误,即存在失败的断言。 我知道有一个HTML文件可以
Closed. This question needs to be more focused。它当前不接受答案。 想要改善这个问题吗?更新问题,使它仅关注editing this post的一个问题。
我想关闭弹出窗口(已知的窗口名称),然后返回到原始窗口。 我该怎么办? 如果我无法获得窗口中关闭按钮的常量。那么有没有达到目标的一般行为? 最佳答案 你有没有尝试过: selenium.Close()
我正在用webdriver做一个测试机器人。我有一个场景,它单击一个按钮,打开一个新窗口,并且它通过特定的xpath搜索元素,但是有时没有这样的元素,因为可以将其禁用,并且出现此错误:org.open
我是第一次使用Selenium,对这些选项不知所措。我在Firefox中使用IDE。 当我的页面加载时,它随后通过JSONP请求获取值,并在其中填充选择中的选项。 我如何让Selenium等待选择中的
我开始使用nightwatch.js编写e2e测试,我注意到我想在目标浏览器的控制台(开发人员工具)中手动检查一些错误。但总是在我打开开发者控制台时,浏览器会自动关闭它。这是selenium还是nig
我正在尝试使用以下方式刮除Glassdoor的评论: https://github.com/MatthewChatham/glassdoor-review-scraper 但是我得到了错误并且不知道如
背景 我设置了一个Selenium Grid项目,以在两种不同的浏览器Chrome和Firefox中执行测试。我正在使用Gradle执行测试。该测试将成功执行两次,一次按预期在Chrome中执行,一次
当测试失败时,运行 selenium 测试的浏览器将关闭。这在尝试调试时没有帮助。我知道我可以在失败时选择屏幕截图,但如果没有整个上下文,这并没有帮助。在浏览器仍然可用的情况下,我可以回击并检查发生了
使用 Selenium Web 驱动程序而不是 Selenium RC 启动新的测试框架是个好主意吗?对于 Selenium Web 驱动程序,并非所有 Selenium 方法都已实现。那么使用 Se
我使用 selenium 页面对象模型来定义所有页面元素。我对元素命名所遵循的命名约定不太相信,并且感觉太长了。请对此提出建议。 @FindBy(xpath = "//tbody[@id='tabvi
有一个带有按钮的 html 页面,我的 Selenium 测试正在测试,当单击按钮时,会执行一个操作。 问题是,看起来点击发生在 javascript 执行之前 - 在处理程序绑定(bind)到页面之
我是一名优秀的程序员,十分优秀!