use of com.github.sergueik.jprotractor.NgWebElement 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 com.github.sergueik.jprotractor.NgWebElement in project selenium_java by sergueik.
the class NgMultiSelectIntegrationTest method testSelectCarsOneByOne.
// @Ignore
@Test
public void testSelectCarsOneByOne() {
// Given we are using multi select directive to pick cars
NgWebElement ng_directive = ngDriver.findElement(NgBy.model("selectedCar"));
assertThat(ng_directive, notNullValue());
assertThat(ng_directive.getTagName(), equalTo("am-multiselect"));
WebElement toggleSelect = ng_directive.findElement(NgBy.buttonText("Select Some Cars"));
assertThat(toggleSelect, notNullValue());
assertTrue(toggleSelect.isDisplayed());
toggleSelect.click();
// After selecting every car one car at a time
List<WebElement> cars = ng_directive.findElements(NgBy.repeater("i in items"));
// NOTE: not "c.name for c in cars" that one finds in the am-multiselect tag
int selectedCarCount = 0;
for (int rowNum = 0; rowNum != cars.size(); rowNum++) {
NgWebElement ng_car = ngDriver.findElement(NgBy.repeaterElement("i in items", rowNum, "i.label"));
System.err.println("* " + ng_car.evaluate("i.label").toString());
CommonFunctions.highlight(ng_car);
ng_car.click();
selectedCarCount++;
}
// Until all cars are selected
assertThat(ng_directive.findElements(NgBy.repeater("i in items")).size(), equalTo(selectedCarCount));
// Then the button text shows the total number of cars selected
WebElement button = ngDriver.findElement(By.cssSelector("am-multiselect > div > button"));
String buttonTextPattern = "There are (\\d+) car\\(s\\) selected";
String buttonText = button.getText();
assertTrue(buttonText.matches(buttonTextPattern));
System.err.println(buttonText);
int carCount = 0;
Pattern pattern = Pattern.compile(buttonTextPattern);
Matcher matcher = pattern.matcher(buttonText);
if (matcher.find()) {
carCount = Integer.parseInt(matcher.group(1));
}
assertThat(carCount, equalTo(selectedCarCount));
}
use of com.github.sergueik.jprotractor.NgWebElement in project selenium_java by sergueik.
the class NgQualityShepherdIntegrationTest method testAddFriend.
@Test
public void testAddFriend() {
// When we add a friend
String friendName = "John Doe";
int friendCount = ngDriver.findElements(NgBy.repeater("row in rows")).size();
NgWebElement addnameBox = ngDriver.findElement(NgBy.model("addName"));
assertThat(addnameBox, notNullValue());
highlight(addnameBox);
addnameBox.sendKeys(friendName);
NgWebElement addButton = ngDriver.findElement(NgBy.buttonText("+ add"));
assertThat(addButton, notNullValue());
highlight(addButton);
addButton.click();
ngDriver.waitForAngular();
// Then there the total number of friends is increased by one
assertThat(ngDriver.findElements(NgBy.repeater("row in rows")).size() - friendCount, equalTo(1));
// And we can find the new friend using search
WebElement addedFriendElement = ngDriver.findElements(NgBy.cssContainingText("td.ng-binding", friendName)).get(0);
assertThat(addedFriendElement, notNullValue());
highlight(addedFriendElement);
System.err.println("Added friend name: " + addedFriendElement.getText());
}
use of com.github.sergueik.jprotractor.NgWebElement in project selenium_java by sergueik.
the class NgQualityShepherdIntegrationTest method testSearchAndDeleteFriend.
@Test
public void testSearchAndDeleteFriend() {
// Given we pick friend to delete
List<WebElement> friendNames = ngDriver.findElements(NgBy.repeaterColumn("row in rows", "row"));
WebElement friendName = friendNames.get(0);
highlight(friendName);
String deleteFriendName = friendName.getText();
assertFalse(deleteFriendName.isEmpty());
// When we delete every friend with the chosen name
for (WebElement currentfriendRow : ngDriver.findElements(NgBy.repeater("row in rows"))) {
WebElement currentfriendName = new NgWebElement(ngDriver, currentfriendRow).findElement(NgBy.binding("row"));
if (currentfriendName.getText().indexOf(deleteFriendName) >= 0) {
System.err.println("Delete: " + currentfriendName.getText());
WebElement deleteButton = currentfriendRow.findElement(By.cssSelector("i.icon-trash"));
highlight(deleteButton);
deleteButton.click();
ngDriver.waitForAngular();
}
}
// That the deleted friend's name cannot be found through search
System.err.println("Search name: " + deleteFriendName);
NgWebElement searchBox = ngDriver.findElement(NgBy.model("search"));
searchBox.sendKeys(deleteFriendName);
List<WebElement> rows = ngDriver.findElements(NgBy.repeater("row in rows"));
assertTrue(rows.size() == 0);
// clear search
WebElement clearSearchBox = searchBox.findElement(By.xpath("..")).findElement(By.cssSelector("i.icon-remove"));
assertThat(clearSearchBox, notNullValue());
System.err.println("Clear Search");
clearSearchBox.click();
ngDriver.waitForAngular();
// And the deleted friend cannot be found by looking at the remaining friend
// names
List<WebElement> elements = ngDriver.findElements(NgBy.cssContainingText("td.ng-binding", deleteFriendName));
assertTrue(elements.size() == 0);
// examine remaining friends
for (WebElement currentFriendRow : ngDriver.findElements(NgBy.repeater("row in rows"))) {
highlight(currentFriendRow);
String currentFriendName = new NgWebElement(ngDriver, currentFriendRow).evaluate("row").toString();
System.err.println("Found name: " + currentFriendName);
assertTrue(currentFriendName.indexOf(deleteFriendName) == -1);
}
}
use of com.github.sergueik.jprotractor.NgWebElement in project selenium_java by sergueik.
the class NgSvgIntegrationTest method testCircles.
@Test
public void testCircles() {
// if (isCIBuild) { // Alert not handled by PhantomJS
// return;
// }
getPageContent("ng_svg_ex1.htm");
for (WebElement circle : ngDriver.findElements(NgBy.repeater("circle in circles"))) {
// if (circle.getText().isEmpty()){
// break;
// }
Object x = new NgWebElement(ngDriver, circle).evaluate("circle.x");
Object y = new NgWebElement(ngDriver, circle).evaluate("circle.y");
Object r = new NgWebElement(ngDriver, circle).evaluate("circle.r");
highlight(circle);
formatter.format("x = %1$2d y = %2$2d r = %3$2d\n", x, y, r);
formatter.format("Location: x = %3d", circle.getLocation().x);
formatter.format(" y = %3d", circle.getLocation().y);
System.err.println(sb.toString());
sb.setLength(0);
try {
WebElement element = seleniumDriver.findElement(By.xpath(xpath_of(circle)));
System.err.println("Located by xpath " + xpath_of(circle));
formatter.format("Location: x = %3d", element.getLocation().x);
formatter.format(" y = %3d", element.getLocation().y);
System.err.println(sb.toString());
sb.setLength(0);
highlight(element);
} catch (NoSuchElementException ex) {
// at <anonymous class>.FirefoxDriver.prototype.findElementInternal_
System.err.println("Cannot locate by xpath: " + xpath_of(circle));
}
try {
WebElement element = seleniumDriver.findElement(By.cssSelector(css_selector_of(circle)));
System.err.println("Located by cssSelector " + css_selector_of(circle));
highlight(element);
System.err.println("innerHTML:" + element.getAttribute("innerHTML"));
// WebDriverException: cannot forward the request Software caused
// connection abort
System.err.println("Fill: " + CommonFunctions.executeScript("return arguments[0].getAttribute('fill')", element));
} catch (NoSuchElementException ex) {
System.err.println("Cannot locate by cssSelector: " + css_selector_of(circle));
}
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
Aggregations