use of com.github.sergueik.jprotractor.NgWebElement in project selenium_java by sergueik.
the class NgWay2AutomationIntegrationTest method testEvaluateTransactionDetails.
// @Ignore
@Test
public void testEvaluateTransactionDetails() throws InterruptedException {
if (isCIBuild) {
return;
}
// When I proceed to "Customer Login"
ngDriver.findElement(NgBy.buttonText("Customer Login")).click();
// And I login as existing customer
assertThat(ngDriver.findElement(NgBy.input("custId")).getAttribute("id"), equalTo("userSelect"));
// Select customer/account with transactions
for (WebElement currentCustomer : ngDriver.findElement(NgBy.model("custId")).findElements(NgBy.repeater("cust in Customers"))) {
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();
// NOTE: need to select account with transactions
for (WebElement currentAccount : ngDriver.findElements(NgBy.options("account for account in Accounts"))) {
if (Integer.parseInt(currentAccount.getText()) == 1001) {
System.err.println(currentAccount.getText());
currentAccount.click();
}
}
// inspect transactions
NgWebElement transactions_button = ngDriver.findElement(NgBy.partialButtonText("Transactions"));
highlight(transactions_button);
transactions_button.click();
// wait until transactions are loaded
Thread.sleep(500);
wait.until(ExpectedConditions.visibilityOf(ngDriver.findElement(NgBy.repeater("tx in transactions")).getWrappedElement()));
// inspect max 5 transactions
int cnt = 0;
for (WebElement currentTransaction : ngDriver.findElements(NgBy.repeater("tx in transactions"))) {
if (cnt++ >= 5) {
break;
}
NgWebElement ngCurrentTransaction = new NgWebElement(ngDriver, currentTransaction);
assertTrue(ngCurrentTransaction.evaluate("tx.amount").toString().matches("^\\d+$"));
assertTrue(ngCurrentTransaction.evaluate("tx.type").toString().matches("(?i:credit|debit)"));
Object transaction_date = ngCurrentTransaction.evaluate("tx.date");
}
}
use of com.github.sergueik.jprotractor.NgWebElement in project selenium_java by sergueik.
the class NgWay2AutomationIntegrationTest method testListTransactions.
// @Ignore
@Test
public void testListTransactions() {
if (isCIBuild) {
return;
}
// customer login
ngDriver.findElement(NgBy.buttonText("Customer Login")).click();
// select customer/account with transactions
assertThat(ngDriver.findElement(NgBy.input("custId")).getAttribute("id"), equalTo("userSelect"));
for (WebElement currentCustomer : ngDriver.findElement(NgBy.model("custId")).findElements(NgBy.repeater("cust in Customers"))) {
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();
for (WebElement currentAccount : ngDriver.findElements(NgBy.options("account for account in Accounts"))) {
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
try {
Thread.sleep(500);
} catch (InterruptedException e) {
}
wait.until(ExpectedConditions.visibilityOf(ngDriver.findElement(NgBy.repeater("tx in transactions")).getWrappedElement()));
// perform some Credit transaction-specific checks
for (WebElement transactionTypeColumn : ngDriver.findElements(NgBy.repeaterColumn("tx in transactions", "tx.type"))) {
if (transactionTypeColumn.getText().isEmpty()) {
break;
}
if (transactionTypeColumn.getText().equalsIgnoreCase("Credit")) {
highlight(transactionTypeColumn);
}
}
}
use of com.github.sergueik.jprotractor.NgWebElement in project selenium_java by sergueik.
the class NgWay2AutomationIntegrationTest method testInvitateNewCustomerToOpenAccount.
// @Ignore
@Test
public void testInvitateNewCustomerToOpenAccount() {
if (isCIBuild) {
return;
}
// When I proceed to "Bank Manager Login"
ngDriver.findElement(NgBy.buttonText("Bank Manager Login")).click();
// And I proceed to "Add Customer"
ngDriver.findElement(NgBy.partialButtonText("Add Customer")).click();
NgWebElement ng_firstName = ngDriver.findElement(NgBy.model("fName"));
assertThat(ng_firstName.getAttribute("placeholder"), equalTo("First Name"));
ng_firstName.sendKeys("John");
NgWebElement ng_lastName = ngDriver.findElement(NgBy.model("lName"));
assertThat(ng_lastName.getAttribute("placeholder"), equalTo("Last Name"));
ng_lastName.sendKeys("Doe");
NgWebElement ng_postCode = ngDriver.findElement(NgBy.model("postCd"));
assertThat(ng_postCode.getAttribute("placeholder"), equalTo("Post Code"));
ng_postCode.sendKeys("11011");
// And I add no accounts
// NOTE: there are two 'Add Customer' buttons on this form
WebElement ng_addCustomerButtonElement = ngDriver.findElements(NgBy.partialButtonText("Add Customer")).get(1);
ng_addCustomerButtonElement.submit();
try {
alert = seleniumDriver.switchTo().alert();
Pattern pattern = Pattern.compile("Customer added successfully with customer id :(\\d+)");
Matcher matcher = pattern.matcher(alert.getText());
if (matcher.find()) {
System.err.println("New Customer id: " + matcher.group(1));
}
// confirm alert
alert.accept();
} catch (NoAlertPresentException ex) {
// Alert not present
System.err.println(ex.getStackTrace());
return;
} catch (WebDriverException ex) {
// Alert not handled by PhantomJS
System.err.println("Alert was not handled by PhantomJS: " + ex.getStackTrace());
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 "Customer Login"
ngDriver.findElement(NgBy.buttonText("Customer Login")).click();
for (WebElement currentCustomer : ngDriver.findElement(NgBy.model("custId")).findElements(NgBy.repeater("cust in Customers"))) {
if (currentCustomer.getText().indexOf("John Doe") >= 0) {
System.err.println(currentCustomer.getText());
currentCustomer.click();
}
}
NgWebElement ng_login = ngDriver.findElement(NgBy.buttonText("Login"));
assertTrue(ng_login.isEnabled());
highlight(ng_login);
ng_login.click();
ngDriver.waitForAngular();
// Then I am greeted as "John Doe"
NgWebElement ng_user = ngDriver.findElement(NgBy.binding("user"));
assertThat(ng_user.getText(), containsString("John"));
assertThat(ng_user.getText(), containsString("Doe"));
// And I am invited to open an account
Object noAccount = ng_user.evaluate("noAccount");
assertTrue(parseBoolean(noAccount.toString()));
boolean hasAccounts = !(parseBoolean(noAccount.toString()));
System.err.println("Has accounts: " + hasAccounts);
WebElement message = seleniumDriver.findElement(By.cssSelector("span[ng-show='noAccount']"));
assertTrue(message.isDisplayed());
highlight(message);
assertThat(message.getText(), containsString("Please open an account"));
System.err.println(message.getText());
// And I see no accounts
NgWebElement accountNo = ngDriver.findElement(NgBy.binding("accountNo"));
assertFalse(accountNo.isDisplayed());
// And I cannot choose an account to view
List<WebElement> accounts = ngDriver.findElements(NgBy.repeater("account for account in Accounts"));
assertThat(accounts.size(), equalTo(0));
}
use of com.github.sergueik.jprotractor.NgWebElement in project selenium_java by sergueik.
the class Program method testAddition.
@Test
public void testAddition() throws InterruptedException {
driver.get("http://juliemr.github.io/protractor-demo/");
NgWebElement element = ngDriver.findElement(NgBy.model("first"));
Assert.assertNotNull(element);
highlight(element, 100);
element.sendKeys("40");
element = ngDriver.findElement(NgBy.model("second"));
Assert.assertNotNull(element);
highlight(element, 100);
element.sendKeys("2");
element = ngDriver.findElement(NgBy.options("value for (key, value) in operators"));
element.click();
element = ngDriver.findElement(NgBy.buttonText("Go!"));
Assert.assertTrue(element.getText().indexOf("Go") == 0);
element.click();
element = ngDriver.findElement(NgBy.binding("latest"));
Assert.assertEquals("42", element.getText());
highlight(element, 100);
}
Aggregations