use of com.github.sergueik.jprotractor.NgWebElement in project selenium_java by sergueik.
the class NgDemoTest method testCustomerLogin.
@Test
public void testCustomerLogin() {
// When I proceed to "Customer Login"
NgWebElement element = ngDriver.findElement(NgBy.buttonText("Customer Login"));
highlight(element);
element.click();
// And I find myself in the list of existing customers
NgWebElement custId = ngDriver.findElement(NgBy.input("custId"));
highlight(custId);
custId.click();
WebElement customer = custId.findElements(NgBy.repeater("cust in Customers")).stream().filter(c -> c.getText().indexOf("Hermoine Granger") >= 0).findFirst().get();
// NOTE: works differently in firefox and chrome
// customer.sendKeys(Keys.SPACE);
customer.click();
ngDriver.waitForAngular();
// And I log in
NgWebElement login = ngDriver.findElement(NgBy.buttonText("Login"));
assertTrue(login.isEnabled());
highlight(login);
login.click();
// Then I am greeted by my first and last name
assertThat("greeting", ngDriver.findElement(NgBy.binding("user")).getText(), containsString("Hermoine Granger"));
// And I see balance on one of my accounts
NgWebElement ng_accountNo = ngDriver.findElement(NgBy.binding("accountNo"));
assertThat("account number", ng_accountNo.getText(), anyOf(is("1001"), is("1002"), is("1003")));
highlight(ng_accountNo);
// And I open account
ngDriver.findElements(NgBy.options("account for account in Accounts")).stream().filter(account -> account.getText().matches("1001")).collect(Collectors.toList()).get(0).click();
// And I inspect transactions
NgWebElement transactions_button = ngDriver.findElement(NgBy.partialButtonText("Transactions"));
highlight(transactions_button);
transactions_button.click();
// wait until transactions are loaded
wait.until(ExpectedConditions.visibilityOf(ngDriver.findElement(NgBy.repeater("tx in transactions")).getWrappedElement()));
// Then I can observe few transactions
// to speed up test, limit to first 4
int cnt = 0;
for (WebElement tx : ngDriver.findElements(NgBy.repeater("tx in transactions"))) {
if (cnt++ > 4) {
break;
}
// view-source:http://www.way2automation.com/angularjs-protractor/banking/listTx.html
NgWebElement ngTx = new NgWebElement(ngDriver, tx);
// every transaction would be either Debit or Credit
String txType = ngTx.evaluate("tx.type").toString();
assertThat("transaction type", txType, anyOf(containsString("Debit"), containsString("Credit")));
// it will have non zero amount
int txAmount = Integer.parseInt(ngTx.evaluate("tx.amount").toString());
assertThat("it will have non zero amount", txAmount, greaterThan(0));
highlight(ngTx.findElement(NgBy.binding("tx.amount")));
// its transaction dates should be the past
try {
Date txDate = dateFormat.parse(ngTx.evaluate("tx.date").toString());
assertThat("transaction date", txDate, sameOrBefore(new Date()));
} catch (ParseException e) {
// ignore
}
}
// perform some Credit transaction-specific checks
// to speed up test, limit to first 3
ngDriver.findElements(NgBy.repeaterColumn("tx in transactions", "tx.type")).stream().filter(txType -> !txType.getText().isEmpty()).filter(txType -> txType.getText().equalsIgnoreCase("Credit")).limit(3).forEach(txType -> highlight(txType));
}
use of com.github.sergueik.jprotractor.NgWebElement in project selenium_java by sergueik.
the class NgDragDropIntegrationTest method testDragAndDrop.
// @Ignore
@Test
public void testDragAndDrop() {
NgWebElement ng_board = ngDriver.findElement(NgBy.model("kanbanBoard"));
assertThat(ng_board, notNullValue());
highlight(ng_board);
WebElement column3 = ng_board.findElement(By.id("column3"));
assertThat(column3, notNullValue());
highlight(column3);
NgWebElement ng_column3 = new NgWebElement(ngDriver, column3);
// alternative search
for (WebElement element : ngDriver.findElements(NgBy.repeater("column in kanbanBoard.columns"))) {
System.err.println("id: " + element.getAttribute("id"));
if (element.getAttribute("id").equalsIgnoreCase("column3")) {
System.err.println("id: " + element.getAttribute("id") + " found");
ng_column3 = new NgWebElement(ngDriver, element);
highlight(element);
}
}
WebElement source_card = null;
WebElement target_card = null;
for (WebElement card : ng_column3.findElement(NgBy.model("column.cards")).findElements(NgBy.repeater("card in column.cards"))) {
if (card.getText().isEmpty()) {
break;
}
if (card.getText().equalsIgnoreCase("Test user module")) {
System.err.println("source card: \"" + card.getText() + "\" found");
source_card = card;
}
if (card.getText().equalsIgnoreCase("CI for user module")) {
System.err.println("target card: \"" + card.getText() + "\" found");
target_card = card;
}
}
highlight(source_card);
Point source_card_location = source_card.getLocation();
highlight(target_card);
Point target_card_location = target_card.getLocation();
actions.moveToElement(source_card).build().perform();
// does not appear to work
actions.dragAndDropBy(source_card, 0, target_card_location.y - source_card_location.y).build().perform();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
// works
actions.clickAndHold(source_card).moveToElement(target_card).release().build().perform();
ngDriver.waitForAngular();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
use of com.github.sergueik.jprotractor.NgWebElement in project selenium_java by sergueik.
the class NgIgnoreSyncIntegrationTest method testNonAngular.
// @Ignore
@Test
public void testNonAngular() {
if (isCIBuild) {
return;
}
ngDriver.navigate().to("http://www.google.com");
try {
long startTime = System.currentTimeMillis();
ngDriver.waitForAngular();
// exception: window.angular is undefined
long estimatedTime = System.currentTimeMillis() - startTime;
System.err.println("waitForAngular: " + estimatedTime);
NgWebElement element = ngDriver.findElement(By.cssSelector("input#gs_htif0"));
element.getAttribute("id");
} catch (TimeoutException exception) {
System.err.println("TimeoutException thrown:");
fullStackTrace = org.apache.commons.lang.exception.ExceptionUtils.getFullStackTrace(exception);
System.err.println("Exception thrown: " + fullStackTrace);
return;
}
}
use of com.github.sergueik.jprotractor.NgWebElement in project selenium_java by sergueik.
the class NgLocalFileIntegrationTest method testOrderByColumnField.
// @Ignore
@Test
public void testOrderByColumnField() {
// Given there is a sorted data grid
getPageContent("ng_headers_sort_example1.htm");
String[] headers = new String[] { "First Name", "Last Name", "Age" };
Hashtable<String, String> header_columns = new Hashtable<String, String>();
// String[] sortOrders = new String[]{"descending", "ascending"};
for (String header : headers) {
for (int cnt = 0; cnt != 2; cnt++) {
// When grid is sorted by <header> in <sort order>
WebElement headerelement = ngDriver.findElement(By.xpath("//th/a[contains(text(),'" + header + "')]"));
headerelement.click();
// Then Angular uses the column <binding> to sort rows in <sort order>
// order
List<WebElement> rows = ngDriver.findElements(NgBy.repeater("emp in data.employees"));
WebElement row = rows.get(0);
String field = row.getAttribute("ng-order-by");
NgWebElement ng_row = new NgWebElement(ngDriver, row);
boolean reverseSort = parseBoolean(ng_row.evaluate("reverseSort").toString());
// Without Protractor:
// Then the data is sorted by <header> in <sort order>
// String binding = header_columns.get(header);
String binding = "emp." + ng_row.evaluate(field);
System.err.println("Sorted by: " + field + ": " + binding + ", Reverse: " + reverseSort);
// Iterate over all rows, selected column
for (WebElement emp : rows) {
NgWebElement ng_emp = new NgWebElement(ngDriver, emp);
try {
WebElement empFieldElement = ng_emp.findElement(NgBy.binding(binding));
assertThat(empFieldElement, notNullValue());
System.err.println(empFieldElement.getText());
} catch (Exception e) {
System.err.println(org.apache.commons.lang.exception.ExceptionUtils.getFullStackTrace(e));
}
}
// Compare selected column of first and last row
WebElement first_row_cell = ngDriver.findElement(NgBy.repeaterElement("emp in data.employees", 0, binding));
WebElement last_row_cell = ngDriver.findElement(NgBy.repeaterElement("emp in data.employees", rows.size() - 1, binding));
System.err.println("First row cell: " + first_row_cell.getText());
System.err.println("Last row cell: " + last_row_cell.getText());
if (reverseSort) {
System.err.println("Order: descending");
System.err.println("Verified " + (first_row_cell.getText().compareTo(last_row_cell.getText()) > 0));
} else {
System.err.println("Order: ascending");
System.err.println("Verified " + (first_row_cell.getText().compareTo(last_row_cell.getText()) < 0));
}
}
}
}
use of com.github.sergueik.jprotractor.NgWebElement in project selenium_java by sergueik.
the class NgLocalFileIntegrationTest method testHover.
// @Ignore
@Test
public void testHover() {
getPageContent("ng_hover1.htm");
// Hover over menu
WebElement element = seleniumDriver.findElement(By.id("hover"));
highlight(element);
actions.moveToElement(element).build().perform();
// Wait for the Angular 'hovering' property to get evaluated to true
WebDriverWait wait2 = new WebDriverWait(seleniumDriver, 120);
wait2.pollingEvery(50, TimeUnit.MILLISECONDS);
wait2.until(new ExpectedCondition<Boolean>() {
// NOTE: 'until' only prints "hovering: true" and never "hovering: false"
@Override
public Boolean apply(WebDriver d) {
NgWebDriver ngD = new NgWebDriver(d);
// org.openqa.selenium.WebDriverException: The WebDriver instance must
// implement JavaScriptExecutor interface.
NgWebElement ng_element = ngD.findElement(By.id("hover"));
Object value = ng_element.evaluate("hovering");
System.err.println("hovering: " + value.toString());
return parseBoolean(value.toString());
}
});
actions.moveByOffset(0, 300).build().perform();
// Wait for the tooltip div to get visible
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
actions.moveToElement(element).build().perform();
try {
wait.until(ExpectedConditions.visibilityOf(seleniumDriver.findElement(By.cssSelector("div[ng-show='hovering']"))));
} catch (NoSuchElementException e) {
}
}
Aggregations