List of usage examples for org.openqa.selenium By id
public static By id(String id)
From source file:at.ac.tuwien.big.testsuite.impl.selenium.BaseSeleniumTest.java
License:Apache License
protected static String textById(WebDriver driver, String id) { try {// ww w. j ava 2 s . com return driver.findElement(By.id(id)).getText().trim(); } catch (NoSuchElementException ex) { return null; } }
From source file:at.ac.tuwien.big.testsuite.impl.selenium.BaseSeleniumTest.java
License:Apache License
protected static void clickAjax(WebDriver driver, String id) { clickAjax(driver, By.id(id)); }
From source file:at.ac.tuwien.big.testsuite.impl.selenium.LoginTest.java
License:Apache License
private void checkMessages(String message, Matcher<String> matcher) { WebElement loginMessagesElement = null; if (exists(By.id("login_messages"))) { loginMessagesElement = driver.findElement(By.id("login_messages")); } else if (exists(By.id("form:login_messages"))) { loginMessagesElement = driver.findElement(By.id("form:login_messages")); } else if (exists(By.id("login:form:login_messages"))) { loginMessagesElement = driver.findElement(By.id("login:form:login_messages")); }/*from ww w. ja v a 2 s.co m*/ String text = loginMessagesElement == null ? null : loginMessagesElement.getText(); checkThat(message, text, matcher); }
From source file:at.ac.tuwien.big.testsuite.impl.selenium.LoginTest.java
License:Apache License
public void doLogin(WebDriver driver, String username, String password) { checkThat("Login form element 'name' with id 'login:form:name' does not exist", true, is(exists(driver, By.id("login:form:name")))); checkThat("Login form element 'password' with id 'login:form:password' does not exist", true, is(exists(driver, By.id("login:form:password")))); checkThat("Login form element 'submit' with id 'login:form:submit' does not exist", true, is(exists(driver, By.id("login:form:submit")))); driver.findElement(By.id("login:form:name")).sendKeys(username); driver.findElement(By.id("login:form:password")).sendKeys(password); driver.findElement(By.id("login:form:submit")).click(); wait(200);//w w w . j a va2s. c om waitForJQuery(driver); }
From source file:at.ac.tuwien.big.testsuite.impl.selenium.LoginTest.java
License:Apache License
@Test public void testLogin_shouldBeSuccessful() throws Exception { exportCurrentHTML(driver, "login-new.html"); checkMessages("No login message expected but there is one given", isEmptyOrNullString()); doLogin(driver, username, password); // Logout//from www . j ava 2s.c o m if (exists(By.id("logout"))) { driver.findElement(By.id("logout")).click(); } else if (exists(By.id("navForm:logout"))) { driver.findElement(By.id("navForm:logout")).click(); } else { assertFalse( "The logout link could not be found, either a login error occurred or the logout link has a different id than expected", true); } wait(200); waitForJQuery(driver); checkMessages("No login message expected but there is one given", isEmptyOrNullString()); exportCurrentHTML(driver, "login-logged-out.html"); }
From source file:at.ac.tuwien.big.testsuite.impl.selenium.RegisterTest.java
License:Apache License
@Before @Override// www . ja va 2 s .com public void init() throws Exception { super.init(); if (exists(By.id("register"))) { clickNonAjax(By.id("register")); } else if (exists(By.id("navForm:register"))) { clickNonAjax(By.id("navForm:register")); } else { assertFalse(TestsuiteConstants.KNOWN_ERROR_PREFIX + " The register link does not exist", true); } waitForJQuery(); }
From source file:at.ac.tuwien.big.testsuite.impl.selenium.RegisterTest.java
License:Apache License
@Test public void testTermsAndConditions_shouldPass() { String termsId = getPrefixedId("terms"); checkThat("The terms and conditions are visible before the checkbox has been clicked.", driver.findElement(By.id(termsId)).getText(), allOf(not(containsString("Play at least once a day!")), not(containsString("Spiele zumindest einmal am Tag!")))); String showtermsId = getPrefixedId("showterms"); driver.findElement(By.id(showtermsId)).click(); wait(200);/* ww w .j a v a 2 s .c om*/ waitForJQuery(driver); checkThat("The terms and conditions are not visible after the checkbox has been clicked.", driver.findElement(By.id(termsId)).getText(), anyOf(containsString("Play at least once a day!"), containsString("Spiele zumindest einmal am Tag!"))); exportCurrentHTML(driver, "register-terms-and-conditions.html"); }
From source file:at.ac.tuwien.big.testsuite.impl.selenium.RegisterTest.java
License:Apache License
/** * Fills out the registration form, submit it and wait for the response * * @param firstname/*from w ww . jav a2s. com*/ * @param lastName * @param birthdate * @param sex * @param username * @param password */ private void doRegistration(String firstname, String lastName, String birthdate, int sex, String username, String password) { String firstnameId = getPrefixedId("firstname"); driver.findElement(By.id(firstnameId)).sendKeys(firstname); String lastnameId = getPrefixedId("lastname"); driver.findElement(By.id(lastnameId)).sendKeys(lastName); String birthdateId = ID_PREFIXES[0] + BIRTHDAY_IDS[0]; for (String bId : BIRTHDAY_IDS) { for (String tmpPrefix : ID_PREFIXES) { if (exists(By.id(tmpPrefix + bId))) { birthdateId = tmpPrefix + bId; break; } } } driver.findElement(By.id(birthdateId)).sendKeys(birthdate); String sexId = getPrefixedId("sex"); Select dropDown = new Select(driver.findElement(By.id(sexId))); dropDown.selectByIndex(sex); String usernameId = getPrefixedId("username"); driver.findElement(By.id(usernameId)).sendKeys(username); String passwordId = getPrefixedId("password"); driver.findElement(By.id(passwordId)).sendKeys(password); String submitId = getPrefixedId("submit"); driver.findElement(By.id(submitId)).click(); wait(200); waitForJQuery(driver); }
From source file:at.ac.tuwien.big.testsuite.impl.selenium.RegisterTest.java
License:Apache License
/** * Performs the given matcher check with the text of the WebElement with the * given id and stores the result in the error collector. If no element is * found with the given Id, the check is performed against null. * * @param message the message to be used if the check fails * @param elementIds the possible ids of the WebElement to check * @param matcher the matcher to be used in the check *///from w w w . ja v a 2 s . c o m private void checkMessages(String message, String[] elementIds, Matcher<String> matcher) { String elementId = elementIds[0]; for (String tmp : elementIds) { for (String tmpPrefix : ID_PREFIXES) { if (exists(By.id(tmpPrefix + tmp + "_messages"))) { elementId = tmpPrefix + tmp; break; } } } WebElement messagesElement = null; List<WebElement> elements = driver.findElements(By.id(elementId + "_messages")); if (!elements.isEmpty()) { messagesElement = elements.get(0); } String text = messagesElement == null ? null : messagesElement.getText(); checkThat(message, text, matcher); }
From source file:at.ac.tuwien.big.testsuite.impl.selenium.RegisterTest.java
License:Apache License
/** * returns the id with the used prefix/*from w w w .j a v a 2s . c om*/ * * @param id */ private String getPrefixedId(String id) { String elementId = ID_PREFIXES[0] + id; for (String tmpPrefix : ID_PREFIXES) { if (exists(By.id(tmpPrefix + id))) { elementId = tmpPrefix + id; return elementId; } } return elementId; }