My core code:
public GeneralPage clickAnyPossibleElement(By selector) {
getDriver().waitForPageLoaded();
repeatable.repeat(() -> {
List<WebElement> webElementList = getDriver().findDynamicElements(selector);
boolean wasClicked = false;
for (WebElement webElement : webElementList) {
try {
webElement.click();
wasClicked = true;
BFLogger.logDebug("Clicked: " + webElement);
break;
} catch (Throwable e) { //catch all, some of selenium exceptions extend Error
BFLogger.logDebug("Tried to click: " + webElement + " but failed!");
}
}
if (!wasClicked) {
throw new RuntimeException("Could not click none of elements: " + webElementList);
}
},
8,
5000
);
ExceptionSuppressor.silentSleep(DEFAULT_SLEEP_TIME);
return this;
}
public void enterID() throws Exception{
ExceptionSuppressor.silentSleep(5000);
WebTable table = tableFactory.getTable("workPage","mainTable");
String ID = System.getProperty("ID");
String expression = "${Case number} = '"+ ID +"'";
table.enterSelectedIssue(expression);
}
public SelectionResult enterSelectedIssue(String expression) throws Exception {
Map<String, String> predicates = null;
predicates = ExpressionParser.parseSelectorExpression(expression);
if (predicates.size() == 0) throw new RuntimeException("Expression:" + expression + " doesn't match any column");
return this.enterSelectedRow(predicates);
}
private SelectionResult enterSelectedRow(Map<String, String> predicates) {
if (rowList.size() == 0) throw new AssertionError("Couldn't find such row!");
SelectionResult selectionResult = new SelectionResult();
Actions action = new Actions(getDriver());
for (int i = 0; i < rowList.size(); i++) {
if (verifyRow(predicates, i)) {
List<WebElement> row = rowList.get(i);
WebElement cell = row.get(1);
action.doubleClick(cell).perform();
selectionResult.addMatchedRow(i);
break;
}
}
return selectionResult;
}
I'd like to merge it and get test like:
- Open page then click on text based on selector
- If Case from method 'enterSelectedRow' is not visible click again on text based on selector
- If Case is still not visible click on this text again. Do it 10 times.
I'm trying to use code like bellow:
private SelectionResult Test(Map<String, String> predicates, By selector) {
SelectionResult selectionResult = new SelectionResult();
Actions action = new Actions(getDriver());
repeatable.repeat(() -> {
if (rowList.size() == 0) {
do {
getDriver().findElement(selector).click();
} while (rowList.size() == 0);
for (int i = 0; i < rowList.size(); i++) {
if (verifyRow(predicates, i)) {
List<WebElement> row = rowList.get(i);
WebElement cell = row.get(1);
action.doubleClick(cell).perform();
selectionResult.addMatchedRow(i);
break;
}
}
}},8,5000 );
return selectionResult;
}
public SelectionResult enterSelectedIssueText(String expression,By selector) throws Exception {
Map<String, String> predicates = null;
predicates = ExpressionParser.parseSelectorExpression(expression);
if (predicates.size() == 0) throw new RuntimeException("Expression:" + expression + " doesn't match any column");
System.out.println(selector);
return this.Test(predicates,selector);
}
@When("Open tab with name \"(.*)\"")
public void clickAnyWithText(String text) throws Exception {
WebTable table = tableFactory.getTable("workPage","mainTable");
// String ID = System.getProperty("ID");
By selector = By.xpath("//*[text()='" + text + "']");
String expression = "${Number of case} = 'CASE/12/2020/0212'";
table.enterSelectedIssueText(expression,selector);
}
But every time my case is passing.
Actual result: Selector is visible, my test clicks on this text and then test pass even if case is not visible.
Expected result:
My test click on text based on selector and if case is not visible test should click on text again and do it 10 times.
Aucun commentaire:
Enregistrer un commentaire