我有一个静态的 ExcelUnits 类。我从 Excel 中得到一个列表,我想用这个列表进行测试。一切正常。定位器对于只有 1 个 html 标签来说太晚了。这需要 20 到 30 秒。这太多了。如果我在 testng 提供者之外尝试这个定位器,它会立即找到这个定位器。如果是因为Testng,为什么这个定位器在很长的时间内找到,而其他定位器在很短的时间内找到?
我的数据提供者
@DataProvider(name = "setConnectionListForRemove")
public Object[][] setConnectionListForRemove() throws Exception { return ExcelUtils.setConnectionListForRemove(); }
@Test(优先级 = 9, dataProvider = "setConnectionListForRemove") public void setConnectionListForRemove(String firstName, String lastName, String company, String position, int rowNumber) 抛出 InterruptedException,IOException {
searchPage.clickShowKeywordsButton();
Log4j.info("Clicked Showing Keywords List Button");
searchPage.setConnectionsKnowledge(firstName, lastName, position, company);
Log4j.info("Connection related data has been entered.");
searchPage.clickKeywordsResult();
Log4j.info("Clicked the Show results button.");
boolean checkConnectionInformetion = searchPage.CheckConnectionInformation();
Log4j.info("Checked About Connection Informations");
if (!checkConnectionInformetion) {
boolean checkPosition = searchPage.checkCurrentTitleWithPosition();
if (!checkPosition) {
searchPage.clickOpenProfile();
} } `
我找到定位器的速度很慢。定位器:
By getCurrentTitleElement = By.xpath("(//div[contains(@class,'entity-result__primary-subtitle t-14 t-black t-normal')])[1]");
public boolean checkCurrentTitleWithPosition() {
String currentTitle = (getText(getCurrentTitleElement) == null) ? "" : getText(getCurrentTitleElement);
return Arrays.stream(properties.getProperty("Positions")
.split(",")).anyMatch(position -> find(currentTitle, position)); // this is my positions list and the list at properties.file.
}
这是我的getText方法
public String getText(By key) {
WebElement element = findElement(key);
if (element != null)
return findElement(key).getText();
return null;
}
这是我的 findElement 方法
public WebElement findElement(By key) {
WebElement element = presenceElement(key);
scrollToElement(element);
return element;
}
这是我的 presenceElement 方法
public WebElement presenceElement(By key) {
WebElement element = null;
try {
element = wait.until(ExpectedConditions.presenceOfElementLocated(key));
} catch (TimeoutException e) {
}
return element;
}
有人有想法吗?