use of org.openqa.selenium.NoAlertPresentException in project selenium_java by sergueik.
the class NgLocalFileIntegrationTest method testFindSelectedtOptionWithAlert.
@Ignore
@Test
public void testFindSelectedtOptionWithAlert() {
getPageContent("ng_selected_option.htm");
List<WebElement> elements = ngDriver.findElements(NgBy.selectedOption("countSelected"));
try {
assertThat(elements.size(), equalTo(1));
} catch (AssertionError e) {
if (isCIBuild) {
System.err.println("Skipped processing exception " + e.toString());
return;
} else {
throw e;
}
}
WebElement element = elements.get(0);
ngDriver.waitForAngular();
assertThat(element, notNullValue());
assertTrue(element.isDisplayed());
System.err.println("Selected option: " + element.getText() + "\n" + element.getAttribute("outerHTML"));
assertThat(element.getText(), containsString("One"));
for (WebElement option : ngDriver.findElements(NgBy.options("count.id as count.name for count in countList"))) {
System.err.println("Available option: " + option.getText());
if (option.getText().isEmpty()) {
break;
}
if (option.getText().equalsIgnoreCase("two")) {
System.err.println("Selecting option: " + option.getText());
option.click();
if (!isCIBuild) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
}
}
if (!isCIBuild) {
try {
alert = seleniumDriver.switchTo().alert();
String alert_text = alert.getText();
System.err.println("Accepted alert: " + alert_text);
alert.accept();
} catch (NoAlertPresentException ex) {
System.err.println(ex.getStackTrace());
return;
}
}
}
}
ngDriver.waitForAngular();
elements = ngDriver.findElements(NgBy.selectedOption("countSelected"));
try {
assertThat(elements.size(), equalTo(1));
} catch (AssertionError e) {
if (isCIBuild) {
System.err.println("Skipped processing exception " + e.toString());
return;
} else {
throw e;
}
}
element = elements.get(0);
assertThat(element, notNullValue());
System.err.println("Selected option: " + element.getText() + "\n" + element.getAttribute("outerHTML"));
assertThat(element.getText(), containsString("Two"));
WebElement countSelected = ngDriver.findElement(NgBy.binding("countSelected"));
assertThat(countSelected, notNullValue());
// System.err.println(countSelected.getText() );
int valueOfCountSelected = Integer.parseInt(new NgWebElement(ngDriver, countSelected).evaluate("countSelected").toString());
System.err.println("countSelected = " + valueOfCountSelected);
assertThat(valueOfCountSelected, equalTo(2));
if (!isCIBuild) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
}
}
}
use of org.openqa.selenium.NoAlertPresentException in project selenium_java by sergueik.
the class NgWay2AutomationIntegrationTest method testOpenAccount.
// @Ignore
@Test
public void testOpenAccount() throws InterruptedException {
if (isCIBuild) {
return;
}
// 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()));
// find the customer by name
for (WebElement currentCustomer : ngDriver.findElements(NgBy.repeater("cust in Customers"))) {
if (currentCustomer.getText().indexOf(customerName) >= 0) {
// System.err.println("Current customer: " + currentCustomer.getText());
highlight(currentCustomer);
NgWebElement ng_currentCustomer = new NgWebElement(ngDriver, currentCustomer);
// find the account we just added
for (WebElement currentAccount : ng_currentCustomer.findElements(NgBy.repeater("account in cust.accountNo"))) {
if (currentAccount.getText().indexOf(newAccount) >= 0) {
highlight(currentAccount);
}
}
}
}
}
use of org.openqa.selenium.NoAlertPresentException in project selenium_java by sergueik.
the class NgWay2AutomationIntegrationTest method testAddCustomer.
// @Ignore
@SuppressWarnings("unchecked")
@Test
public void testAddCustomer() {
if (isCIBuild) {
return;
}
ngDriver.findElement(NgBy.buttonText("Bank Manager Login")).click();
ngDriver.findElement(NgBy.partialButtonText("Add Customer")).click();
NgWebElement firstName = ngDriver.findElement(NgBy.model("fName"));
assertThat(firstName.getAttribute("placeholder"), equalTo("First Name"));
firstName.sendKeys("John");
NgWebElement lastName = ngDriver.findElement(NgBy.model("lName"));
assertThat(lastName.getAttribute("placeholder"), equalTo("Last Name"));
lastName.sendKeys("Doe");
NgWebElement postCode = ngDriver.findElement(NgBy.model("postCd"));
assertThat(postCode.getAttribute("placeholder"), equalTo("Post Code"));
postCode.sendKeys("11011");
// NOTE: there are two 'Add Customer' buttons on this form
Object[] addCustomerButtonElements = ngDriver.findElements(NgBy.partialButtonText("Add Customer")).toArray();
WebElement addCustomerButtonElement = (WebElement) addCustomerButtonElements[1];
addCustomerButtonElement.submit();
try {
alert = seleniumDriver.switchTo().alert();
} 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;
}
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));
}
// Actually add the customer
alert.accept();
// switch to "Customers" screen
ngDriver.findElement(NgBy.partialButtonText("Customers")).click();
// block and wait the customers list to get populated
wait.until(ExpectedConditions.visibilityOf(ngDriver.findElement(NgBy.repeater("cust in Customers"))));
for (WebElement firstNameElement : ngDriver.findElements(NgBy.repeaterColumn("cust in Customers", "cust.fName"))) {
actions.moveToElement(firstNameElement).build().perform();
highlight(firstNameElement);
System.err.println("Customer's First Name: " + firstNameElement.getText());
// no need for explicit findElements
Object objLastName = new NgWebElement(ngDriver, firstNameElement).evaluate("cust.lName");
assertThat(objLastName, notNullValue());
System.err.println("Customer's Last Name: " + objLastName.toString());
// fName, lName, accountNo, postCD, id, date
List<Long> accounts = (List<Long>) new NgWebElement(ngDriver, firstNameElement).evaluate("cust.accountNo");
System.err.println(accounts == null ? "No accounts" : "Account No: " + Arrays.toString(accounts.toArray()));
}
NgWebElement ng_deleteCustomer = null;
for (WebElement currentCustomer : ngDriver.findElements(NgBy.repeater("cust in Customers"))) {
if (currentCustomer.getText().indexOf("John Doe") >= 0) {
ng_deleteCustomer = new NgWebElement(ngDriver, currentCustomer);
break;
}
}
assertThat(ng_deleteCustomer.getWrappedElement(), notNullValue());
actions.moveToElement(ng_deleteCustomer.getWrappedElement()).build().perform();
// delete the customer we added
highlight(ng_deleteCustomer);
NgWebElement deleteCustomerButton = ng_deleteCustomer.findElement(NgBy.buttonText("Delete"));
assertThat(deleteCustomerButton, notNullValue());
assertThat(deleteCustomerButton.getText(), containsString("Delete"));
highlight(deleteCustomerButton);
// .. in slow motion
actions.moveToElement(deleteCustomerButton.getWrappedElement()).clickAndHold().build().perform();
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
actions.release().build().perform();
// let the customers reload
wait.until(ExpectedConditions.visibilityOf(ngDriver.findElement(NgBy.repeater("cust in Customers"))));
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
// TODO: assert the customers.count change
}
use of org.openqa.selenium.NoAlertPresentException in project selenium_java by sergueik.
the class AppTest method testInvitateNewCustomerToOpenAccount.
@Test
public void testInvitateNewCustomerToOpenAccount() throws Exception {
ngDriver.navigate().to(urlBanking);
// 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();
// And I login as "John Doe"
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("John Doe") >= 0) {
System.err.println(currentCustomer.getText());
currentCustomer.click();
}
}
actions.moveToElement(ngDriver.findElement(NgBy.model("custId")).getWrappedElement()).build().perform();
NgWebElement ng_login = ngDriver.findElement(NgBy.buttonText("Login"));
assertTrue(ng_login.isEnabled());
actions.moveToElement(ng_login.getWrappedElement()).build().perform();
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']"));
actions.moveToElement(message).build().perform();
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 org.openqa.selenium.NoAlertPresentException in project selenium_java by sergueik.
the class NgButtonIntegrationTest method testButtonStateText.
@Test
public void testButtonStateText() {
// 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_status = ngDriver.findElement(NgBy.binding("house.frontDoor.isOpen"));
CommonFunctions.highlight(ng_status);
assertTrue(ng_status.getText().matches("The door is closed"));
System.err.println("Initially: " + ng_status.getText());
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;
}
ng_status = ngDriver.findElement(NgBy.binding("house.frontDoor.isOpen"));
CommonFunctions.highlight(ng_status);
System.err.println("Finally: " + ng_status.getText());
assertThat(ng_status.getText(), matchesPattern(".+open"));
}
Aggregations