use of com.github.sergueik.jprotractor.NgWebElement in project selenium_java by sergueik.
the class NgButtonIntegrationTest method testButtonNgIf.
@Test
public void testButtonNgIf() {
// if (isCIBuild) { // Alert not handled by PhantomJS
// return;
// }
getPageContent("ng_watch_ng_if.htm");
WebElement button = seleniumDriver.findElement(By.cssSelector("button.btn"));
ngDriver.waitForAngular();
CommonFunctions.highlight(button);
NgWebElement ng_button = new NgWebElement(ngDriver, button);
assertThat(ng_button, notNullValue());
assertThat(ng_button.getAttribute("ng-click"), equalTo("house.frontDoor.open()"));
assertThat(ng_button.getText(), equalTo("Open Door"));
ngDriver.waitForAngular();
try {
state = ((Boolean) ng_button.evaluate("!house.frontDoor.isOpen")).booleanValue();
} catch (Exception ex) {
System.err.println("evaluate was not handled : " + ex.getStackTrace().toString());
}
assertTrue(state);
button.click();
try {
// confirm alert
seleniumDriver.switchTo().alert().accept();
} catch (NoAlertPresentException ex) {
// Alert not present - ignore
} catch (WebDriverException ex) {
System.err.println("Alert was not handled : " + ex.getStackTrace().toString());
return;
}
button = seleniumDriver.findElement(By.cssSelector("button.btn"));
CommonFunctions.highlight(button);
ng_button = new NgWebElement(ngDriver, button);
assertThat(ng_button, notNullValue());
assertThat(ng_button.getAttribute("ng-click"), equalTo("house.frontDoor.close()"));
assertThat(ng_button.getText(), equalTo("Close Door"));
try {
state = ((Boolean) ng_button.evaluate("house.frontDoor.isOpen")).booleanValue();
} catch (Exception ex) {
// [JavaScript Error: "e is null"] ?
System.err.println("evaluate was not handled : " + ex.getStackTrace().toString());
}
assertTrue(state);
}
use of com.github.sergueik.jprotractor.NgWebElement in project selenium_java by sergueik.
the class NgCalculatorIntegrationTest method testAddition.
@Test
public void testAddition() {
NgWebElement element = ngDriver.findElement(NgBy.model("first"));
assertThat(element, notNullValue());
highlight(element);
element.sendKeys("40");
element = ngDriver.findElement(NgBy.model("second"));
assertThat(element, notNullValue());
highlight(element);
element.sendKeys("2");
element = ngDriver.findElement(NgBy.options("value for (key, value) in operators"));
assertThat(element, notNullValue());
element.click();
element = ngDriver.findElement(NgBy.buttonText("Go!"));
assertThat(element, notNullValue());
assertThat(element.getText(), containsString("Go"));
element.click();
element = ngDriver.findElement(NgBy.binding("latest"));
assertThat(element, notNullValue());
assertThat(element.getText(), equalTo("42"));
highlight(element);
}
use of com.github.sergueik.jprotractor.NgWebElement in project selenium_java by sergueik.
the class NgCssContainingTextTest method test5.
@Test
public void test5() {
Object[] results = new Object[] { "Software Engineer", "Senior Javascript Developer" };
String cellTextPackedRegexp = "__REGEXP__/(?:Software Engineer|Senior Javascript Developer)/i";
NgWebElement ngTableElement = null;
// Arrange
try {
WebElement tableElement = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("example")));
ngTableElement = new NgWebElement(ngDriver, tableElement);
} catch (RuntimeException timeoutException) {
return;
}
// Assert
assertThat(ngTableElement, notNullValue());
actions.moveToElement(ngTableElement.getWrappedElement()).build().perform();
List<WebElement> cellElements = ngTableElement.findElements(NgBy.cssContainingText("tbody > tr > td:nth-child(2)", cellTextPackedRegexp));
assertThat(cellElements.size(), greaterThan(0));
cellElements.stream().forEach(CommonFunctions::highlight);
cellElements.stream().map(o -> o.getText()).forEach(System.err::println);
assertThat(cellElements.stream().map(o -> o.getText()).collect(Collectors.toSet()), hasItems(results));
}
use of com.github.sergueik.jprotractor.NgWebElement in project selenium_java by sergueik.
the class NgCssContainingTextTest method test4.
@Test
public void test4() {
NgWebElement ngTableElement = null;
// Arrange
try {
WebElement tableElement = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("example")));
ngTableElement = new NgWebElement(ngDriver, tableElement);
} catch (RuntimeException timeoutException) {
return;
}
// Assert
assertThat(ngTableElement, notNullValue());
actions.moveToElement(ngTableElement.getWrappedElement()).build().perform();
List<WebElement> cellElements = ngTableElement.findElements(NgBy.cssContainingText("tbody > tr > td:nth-child(2)", "Software Engineer"));
assertThat(cellElements.size(), greaterThan(0));
cellElements.stream().forEach(CommonFunctions::highlight);
cellElements.stream().map(o -> o.getText()).forEach(System.err::println);
}
use of com.github.sergueik.jprotractor.NgWebElement in project selenium_java by sergueik.
the class NgDatePickerIntegrationTest method testHighlightCurrentMonthDays.
// @Ignore
@Test
public // uses Embedded calendar
void testHighlightCurrentMonthDays() {
NgWebElement ng_datepicker = null;
// Arrange
final String searchText = "Embedded calendar";
try {
(new WebDriverWait(driver, 5)).until(new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver d) {
// cannot use Java streams here ?
Iterator<WebElement> elements = d.findElements(By.className("col-sm-6")).iterator();
Boolean result = false;
WebElement element = null;
while (elements.hasNext() && !result) {
element = elements.next();
String text = element.getText();
result = text.contains(searchText);
}
if (result) {
actions.moveToElement(element).build().perform();
}
return result;
}
});
} catch (Exception e) {
System.err.println("Exception: " + e.toString());
}
// Act
try {
ng_datepicker = ngDriver.findElement(NgBy.model("data.embeddedDate", "[data-ng-app]"));
assertThat(ng_datepicker, notNullValue());
actions.moveToElement(ng_datepicker.getWrappedElement()).build().perform();
highlight(ng_datepicker);
// System.err.println("Embedded: " + ng_datepicker.getText());
} catch (Exception e) {
System.err.println("Exception: " + e.toString());
}
WebElement[] dates = ng_datepicker.findElements(NgBy.repeater("dateObject in week.dates")).toArray(new WebElement[0]);
assertTrue(dates.length >= 28);
Boolean foundDate = false;
int start = 0, end = dates.length;
for (int cnt = 0; cnt != dates.length; cnt++) {
if (start == 0 && Integer.parseInt(dates[cnt].getText()) == 1) {
start = cnt;
}
if (cnt > start && Integer.parseInt(dates[cnt].getText()) == 1) {
end = cnt;
}
}
for (int cnt = start; cnt != end; cnt++) {
WebElement date = dates[cnt];
highlight(date);
if (date.getAttribute("class").contains("current")) {
foundDate = true;
}
}
// Assert
assertTrue(foundDate);
}
Aggregations