use of com.jprotractor.NgWebElement in project selenium_java by sergueik.
the class AppTest method testListTransactions.
// @Ignore
@Test
public void testListTransactions() throws Exception {
ngDriver.navigate().to(urlBanking);
// customer login
ngDriver.findElement(NgBy.buttonText("Customer Login")).click();
// select customer/account with transactions
assertThat(ngDriver.findElement(NgBy.input("custId")).getAttribute("id"), equalTo("userSelect"));
Enumeration<WebElement> customers = Collections.enumeration(ngDriver.findElement(NgBy.model("custId")).findElements(NgBy.repeater("cust in Customers")));
while (customers.hasMoreElements()) {
WebElement currentCustomer = customers.nextElement();
if (currentCustomer.getText().indexOf("Hermoine Granger") >= 0) {
System.err.println(currentCustomer.getText());
currentCustomer.click();
}
}
NgWebElement login = ngDriver.findElement(NgBy.buttonText("Login"));
assertTrue(login.isEnabled());
login.click();
Enumeration<WebElement> accounts = Collections.enumeration(ngDriver.findElements(NgBy.options("account for account in Accounts")));
while (accounts.hasMoreElements()) {
WebElement currentAccount = accounts.nextElement();
if (Integer.parseInt(currentAccount.getText()) == 1001) {
System.err.println(currentAccount.getText());
currentAccount.click();
}
}
// inspect transactions
NgWebElement transactions = ngDriver.findElement(NgBy.partialButtonText("Transactions"));
assertThat(transactions.getText(), equalTo("Transactions"));
highlight(transactions);
transactions.click();
// wait until transactions are loaded
Thread.sleep(500);
wait.until(ExpectedConditions.visibilityOf(ngDriver.findElement(NgBy.repeater("tx in transactions")).getWrappedElement()));
Iterator<WebElement> transactionTypeColumns = ngDriver.findElements(NgBy.repeaterColumn("tx in transactions", "tx.type")).iterator();
while (transactionTypeColumns.hasNext()) {
WebElement transactionTypeColumn = (WebElement) transactionTypeColumns.next();
if (transactionTypeColumn.getText().isEmpty()) {
break;
}
if (transactionTypeColumn.getText().equalsIgnoreCase("Credit")) {
highlight(transactionTypeColumn);
}
}
}
use of com.jprotractor.NgWebElement in project selenium_java by sergueik.
the class AppTest method testOpenAccount.
// @Ignore
@Test
public void testOpenAccount() throws Exception {
ngDriver.navigate().to(urlBanking);
// bank manager login
ngDriver.findElement(NgBy.buttonText("Bank Manager Login")).click();
ngDriver.findElement(NgBy.partialButtonText("Open Account")).click();
// wait for customers info get loaded
wait.until(ExpectedConditions.visibilityOf(ngDriver.findElement(NgBy.repeater("cust in Customers")).getWrappedElement()));
NgWebElement selectCustomer = ngDriver.findElement(NgBy.model("custId"));
assertThat(selectCustomer.getAttribute("id"), containsString("userSelect"));
List<WebElement> customers = new NgWebElement(ngDriver, selectCustomer).findElements(NgBy.repeater("cust in Customers"));
// pick random customer to log in
int random_customer_index = 1 + (int) (Math.random() * (customers.size() - 1));
WebElement customer = customers.get(random_customer_index);
String customerName = customer.getText();
System.err.println(customerName);
customer.click();
NgWebElement ng_selectCurrencies = ngDriver.findElement(NgBy.model("currency"));
actions.moveToElement(ng_selectCurrencies.getWrappedElement()).build().perform();
highlight(ng_selectCurrencies.getWrappedElement());
// use core Selenium
Select selectCurrencies = new Select(ng_selectCurrencies.getWrappedElement());
List<WebElement> accountCurrencies = selectCurrencies.getOptions();
// select "Dollars"
selectCurrencies.selectByVisibleText("Dollar");
// add the account
WebElement submitButton = ngDriver.getWrappedDriver().findElement(By.xpath("/html/body//form/button[@type='submit']"));
assertThat(submitButton.getText(), containsString("Process"));
actions.moveToElement(submitButton).build().perform();
highlight(submitButton);
submitButton.click();
String newAccount = null;
try {
alert = seleniumDriver.switchTo().alert();
String alert_text = alert.getText();
assertThat(alert_text, containsString("Account created successfully with account Number"));
Pattern pattern = Pattern.compile("(\\d+)");
Matcher matcher = pattern.matcher(alert_text);
if (matcher.find()) {
newAccount = matcher.group(1);
System.err.println("New account id " + newAccount);
}
// confirm the alert
alert.accept();
} catch (NoAlertPresentException ex) {
// Alert not present
System.err.println("NoAlertPresentException: " + ex.getStackTrace());
// observed in Chrome. Ignore
// return;
} catch (WebDriverException ex) {
// fullStackTrace =
// org.apache.commons.lang.exception.ExceptionUtils.getFullStackTrace(ex);
// System.err.println("Alert was not handled by PhantomJS: " +
// fullStackTrace);
System.err.println("Alert was not handled by PhantomJS: " + ex.getStackTrace().toString());
return;
}
// And I switch to "Home" screen
NgWebElement ng_home = ngDriver.findElement(NgBy.buttonText("Home"));
highlight(ng_home);
ng_home.click();
// And I proceed to "Bank Manager Login"
ngDriver.findElement(NgBy.buttonText("Bank Manager Login")).click();
ngDriver.findElement(NgBy.partialButtonText("Customers")).click();
// wait for customers info get loaded
ngDriver.waitForAngular();
// I can find the Customers Account I just Added
wait.until(ExpectedConditions.visibilityOf(ngDriver.findElement(NgBy.repeater("cust in Customers")).getWrappedElement()));
Enumeration<WebElement> customersEnum = Collections.enumeration(ngDriver.findElements(NgBy.repeater("cust in Customers")));
while (customersEnum.hasMoreElements()) {
// find the customer
WebElement currentCustomer = customersEnum.nextElement();
if (currentCustomer.getText().indexOf(customerName) >= 0) {
// System.err.println("Current customer: " + currentCustomer.getText());
highlight(currentCustomer);
NgWebElement ng_currentCustomer = new NgWebElement(ngDriver, currentCustomer);
Enumeration<WebElement> accountsEnum = Collections.enumeration(ng_currentCustomer.findElements(NgBy.repeater("account in cust.accountNo")));
while (accountsEnum.hasMoreElements()) {
// find the account
WebElement currentAccount = accountsEnum.nextElement();
if (currentAccount.getText().indexOf(newAccount) >= 0) {
highlight(currentAccount);
}
}
}
}
}
use of com.jprotractor.NgWebElement in project selenium_java by sergueik.
the class AppTest method testDatePickerDirectSelect.
@Test(enabled = true)
public void testDatePickerDirectSelect() throws Exception {
NgWebElement ng_result;
try {
ng_result = ngDriver.findElement(NgBy.model("data.dateDropDownInput"));
} catch (WebDriverException e) {
assertTrue(e.getMessage().contains("no injector found for element argument to getTestability"));
System.err.println(" Ignoring exception: " + e.getMessage());
} catch (Exception e) {
throw (e);
}
ng_result = ngDriver.findElement(NgBy.model("data.dateDropDownInput", "[data-ng-app]"));
actions.moveToElement(ng_result.getWrappedElement()).build().perform();
execute_script("scroll(0, 550)");
Thread.sleep(300);
execute_script("scroll(0, 550)");
assertThat(ng_result, notNullValue());
assertTrue(ng_result.getAttribute("type").matches("text"));
actions.moveToElement(ng_result.getWrappedElement()).build().perform();
highlight(ng_result);
NgWebElement ng_calendar = ngDriver.findElement(By.cssSelector(".input-group-addon"));
assertThat(ng_calendar, notNullValue());
highlight(ng_calendar);
actions.moveToElement(ng_calendar.getWrappedElement()).click().build().perform();
// seleniumDriver.manage().window()
// .setSize(new Dimension(datepicker_width, datepicker_heght));
NgWebElement ng_dropdown = ngDriver.findElement(By.cssSelector("div.dropdown.open ul.dropdown-menu"));
assertThat(ng_dropdown, notNullValue());
highlight(ng_dropdown);
actions.moveToElement(ng_dropdown.getWrappedElement()).build().perform();
String monthDate = "12";
WebElement dateElement = ng_dropdown.findElements(NgBy.cssContainingText("td.ng-binding", monthDate)).get(0);
assertThat(dateElement, notNullValue());
highlight(dateElement);
System.err.println("Mondh Date: " + dateElement.getText());
dateElement.click();
ngDriver.waitForAngular();
NgWebElement ng_element = ng_dropdown.findElement(NgBy.model("data.dateDropDownInput", "[data-ng-app]"));
assertThat(ng_element, notNullValue());
highlight(ng_element);
// System.err.println(ng_element.getAttribute("innerHTML"));
List<WebElement> ng_dataDates = ng_dropdown.findElements(NgBy.repeater("dateObject in data.dates"));
assertThat(ng_dataDates.size(), equalTo(24));
// Thread.sleep(10000);
String timeOfDay = "6:00 PM";
WebElement ng_hour = ng_element.findElements(NgBy.cssContainingText("span.hour", timeOfDay)).get(0);
assertThat(ng_hour, notNullValue());
highlight(ng_hour);
System.err.println("Hour of the day: " + ng_hour.getText());
ng_hour.click();
ngDriver.waitForAngular();
String specificMinute = "6:35 PM";
// reload,
try {
ng_element = ng_dropdown.findElement(NgBy.model("data.dateDropDownInput", "[data-ng-app]"));
assertThat(ng_element, notNullValue());
highlight(ng_element);
// System.err.println("Dropdown: " + ng_element.getText());
} catch (StaleElementReferenceException e) {
// org.openqa.selenium.StaleElementReferenceException in Phantom JS
// works fine with desktop browsers
System.err.println("Enexpected exception");
throw (e);
}
WebElement ng_minute;
try {
ng_minute = ng_element.findElements(NgBy.cssContainingText("span.minute", specificMinute)).get(0);
assertThat(ng_minute, notNullValue());
highlight(ng_minute);
System.err.println("Time of the day: " + ng_minute.getText());
ng_minute.click();
} catch (StaleElementReferenceException e) {
System.err.println("Ignoring StaleElementReferenceException");
}
try {
ng_result = ngDriver.findElement(NgBy.model("data.dateDropDownInput", "[data-ng-app]"));
highlight(ng_result);
System.err.println("Selected Date/time : " + ng_result.getAttribute("value"));
// "Thu May 12 2016 18:35:00 GMT-0400 (Eastern Standard Time)"
assertTrue(ng_result.getAttribute("value").matches("\\w{3} \\w{3} \\d{1,2} \\d{4} 18:35:00 GMT[+-]\\d{4} \\(.+\\)"));
} catch (StaleElementReferenceException e) {
throw (e);
}
}
Aggregations