use of org.openqa.selenium.support.pagefactory.ByChained in project selenium_java by sergueik.
the class NgScrollableIntegrationTest method testRowColumnsWithByChained.
@Ignore
@Test
public void testRowColumnsWithByChained() {
// Wait page to load
wait.until(ExpectedConditions.visibilityOf(ngDriver.findElement(By.className("table-container"))));
List<WebElement> nameRows = ngDriver.findElements(new ByChained(NgBy.repeater("row in rowCollection"), NgBy.binding("row.firstName")));
rowCnt = 0;
for (WebElement rowElement : nameRows) {
if (rowCnt++ > maxRows) {
break;
}
try {
if (!rowElement.isDisplayed()) {
break;
}
highlight(rowElement);
System.err.println(String.format("First name in row %d: %s ", rowCnt, rowElement.getText()));
} catch (StaleElementReferenceException e) {
System.err.println("Exception(ignored) " + e.toString());
}
}
}
use of org.openqa.selenium.support.pagefactory.ByChained in project selenium_java by sergueik.
the class NgScrollableIntegrationTest method testCountRows.
// @Ignore
@Test
public void testCountRows() {
// Wait page to load
wait.until(ExpectedConditions.visibilityOf(ngDriver.findElement(By.className("table-container"))));
List<WebElement> rows = ngDriver.findElements(NgBy.repeater("row in rowCollection"));
List<WebElement> lastNameRows = ngDriver.findElements(new ByChained(By.className("table-container"), NgBy.repeater("row in rowCollection"), NgBy.binding("row.lastName")));
System.err.println("Rows: " + rows.size());
System.err.println("Last names: " + lastNameRows.size());
}
use of org.openqa.selenium.support.pagefactory.ByChained in project selenium_java by sergueik.
the class SuvianTest method test41.
// debugging map inspired by the ByChained
@Test(enabled = true)
public void test41() {
// Arrange
driver.get("https://www.virtuosoft.eu/code/bootstrap-autohidingnavbar/");
wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.cssSelector("[class = 'table table-striped table-bordered docs']"))));
WebElement element = driver.findElements(By.cssSelector("[class = 'table table-striped table-bordered docs']")).get(1);
actions.moveToElement(element).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).build().perform();
actions.moveToElement(element).sendKeys(Keys.ARROW_UP).sendKeys(Keys.ARROW_UP).sendKeys(Keys.ARROW_UP).sendKeys(Keys.ARROW_UP).build().perform();
// Act
element = driver.findElements(By.cssSelector("li")).get(12);
wait.until(ExpectedConditions.elementToBeClickable(element));
highlight(element);
// Assert
assertThat(element.getText(), equalTo("BLOG"));
element = driver.findElements(By.cssSelector("div.navbar-fixed-top div.navbar-collapse li a[href='/blog/']")).get(0);
wait.until(ExpectedConditions.elementToBeClickable(element));
highlight(element);
// Assert
assertThat(element.getText(), equalTo("BLOG"));
// Assert
element = driver.findElements(new ByChained(By.cssSelector("body"), By.cssSelector("div.navbar"), By.cssSelector("div.navbar-collapse"), By.cssSelector("li"), By.xpath(String.format("//a[contains(text()[normalize-space()],'%s')]", "Blog")))).get(0);
wait.until(ExpectedConditions.elementToBeClickable(element));
highlight(element);
// Assert
assertThat(element.getText(), equalTo("BLOG"));
element = driver.findElements(new ByChained(By.cssSelector("body"), By.cssSelector("div.navbar-fixed-top"), By.cssSelector("div.navbar-collapse"), By.cssSelector("li"))).stream().filter(o -> o.findElements(By.cssSelector("a")).size() > 0).map(o -> {
System.err.println(o.getAttribute("innerHTML"));
return o;
}).filter(o -> o.findElements(By.xpath(String.format("//a[contains(text()[normalize-space()],'%s')]", "Blog"))).size() > 0).map(o -> o.findElements(By.xpath(String.format("//a[contains(text()[normalize-space()],'%s')]", "Blog"))).get(0)).collect(Collectors.toList()).get(0);
wait.until(ExpectedConditions.elementToBeClickable(element));
highlight(element);
// Assert
assertThat(element.getText(), equalTo("BLOG"));
element.click();
}
use of org.openqa.selenium.support.pagefactory.ByChained in project selenium_java by sergueik.
the class SuvianTest method test6_4.
// Selecting check boxes by their sibling labels, ByChained
@Test(enabled = true)
public void test6_4() {
// Arrange
List<String> hobbies = new ArrayList<>(Arrays.asList("Singing", "Dancing"));
driver.get("http://suvian.in/selenium/1.6checkbox.html");
try {
WebElement checkElement = wait.until(new ExpectedCondition<WebElement>() {
@Override
public WebElement apply(WebDriver _driver) {
return _driver.findElements(By.cssSelector("div.container div.row div.intro-message h3")).stream().filter(_element -> _element.getText().toLowerCase().indexOf("select your hobbies") > -1).findFirst().get();
}
});
System.err.println("element check: " + checkElement.getAttribute("innerHTML"));
} catch (Exception e) {
System.err.println("Exception: " + e.toString());
}
// Act
WebElement formElement = driver.findElement(By.cssSelector("input[id]")).findElement(By.xpath(".."));
assertThat(formElement, notNullValue());
highlight(formElement, 1000);
List<WebElement> inputElements = formElement.findElements(By.cssSelector("label[for]")).stream().filter(_element -> hobbies.contains(_element.getText())).collect(Collectors.toList());
// C#: dataMap = elements.ToDictionary(x => x.GetAttribute("for"), x =>
// x.Text);
Map<String, String> dataMap = inputElements.stream().map(_element -> {
System.err.println("input element id: " + _element);
System.err.println("input element text: " + _element.getText());
System.err.println("input element 'for' attribute: " + _element.getAttribute("for"));
System.err.println("input element HTML: " + _element.getAttribute("outerHTML"));
System.err.println("input element XPath: " + xpathOfElement(_element));
System.err.println("input element CSS: " + cssSelectorOfElement(_element));
return _element;
}).collect(Collectors.toMap(_element -> _element.getText(), _element -> _element.getAttribute("for")));
List<WebElement> checkboxes = new ArrayList<>();
for (String hobby : hobbies) {
try {
System.err.println("finding: " + dataMap.get(hobby));
checkboxes.add(driver.findElements(new ByChained(By.cssSelector("input[id]"), By.xpath(".."), By.cssSelector(String.format("input#%s", dataMap.get(hobby))))).get(0));
} catch (InvalidSelectorException e) {
System.err.println("ignored: " + e.toString());
}
try {
checkboxes.add(formElement.findElement(// will not throw exception
By.xpath(String.format("input[@id='%s']", dataMap.get(hobby)))));
} catch (Exception e) {
System.err.println("ignored: " + e.toString());
}
}
Consumer<WebElement> act = _element -> {
highlight(_element);
_element.click();
};
checkboxes.stream().forEach(act);
// Assert
assertTrue(formElement.findElements(By.cssSelector("input[type='checkbox']")).stream().filter(o -> o.isSelected()).count() == hobbies.size());
}
use of org.openqa.selenium.support.pagefactory.ByChained in project selenium_java by sergueik.
the class NgScrollableIntegrationTest method testEvaluateRowData.
@Ignore
@Test
public void testEvaluateRowData() {
// Wait page to load
wait.until(ExpectedConditions.visibilityOf(ngDriver.findElement(By.className("table-container"))));
List<WebElement> nameRows = ngDriver.findElements(new ByChained(NgBy.repeater("row in rowCollection"), NgBy.binding("row.firstName")));
rowCnt = 0;
for (WebElement rowElement : nameRows) {
if (rowCnt++ > maxRows) {
break;
}
NgWebElement ngRowElement = new NgWebElement(ngDriver, rowElement);
System.err.println(String.format("Row %d Name: %s %s", rowCnt, (String) ngRowElement.evaluate("row.firstName"), (String) ngRowElement.evaluate("row.lastName")));
}
}
Aggregations