List of usage examples for org.openqa.selenium By xpath
public static By xpath(String xpathExpression)
From source file:at.tugraz.ist.catroweb.catroid.SearchTests.java
License:Open Source License
@Test(groups = { "functionality", "upload" }, description = "search project, upload project with identical name, reload") public void identicalSearchQuery() throws Throwable { try {// w w w . j a va2s .c o m String projectTitle = "search_identical"; // + CommonData.getRandomShortString(10); String projectTitle1 = projectTitle + "_1"; String projectTitle2 = projectTitle + "_2"; String response = projectUploader.upload(CommonData.getUploadPayload(projectTitle1, "identical_search_project_2", "", "", "", "", "", "")); assertEquals("200", CommonFunctions.getValueFromJSONobject(response, "statusCode")); openLocation("/search/?q=" + projectTitle + "&p=1", false); ajaxWait(); assertTrue(isElementPresent(By.xpath("//a[@title=\"" + projectTitle1 + "\"]"))); assertFalse(isElementPresent(By.xpath("//a[@title=\"" + projectTitle2 + "\"]"))); projectUploader.upload(CommonData.getUploadPayload(projectTitle2, "identical_search_project_2", "", "", "", "", "", "")); driver().navigate().refresh(); ajaxWait(); driver().findElement(By.id("largeSearchButton")).click(); ajaxWait(); assertTrue(isElementPresent(By.xpath("//a[@title=\"" + projectTitle1 + "\"]"))); assertTrue(isElementPresent(By.xpath("//a[@title=\"" + projectTitle2 + "\"]"))); } catch (AssertionError e) { captureScreen("SearchTests.identicalSearchQuery"); throw e; } catch (Exception e) { captureScreen("SearchTests.identicalSearchQuery"); throw e; } }
From source file:at.tugraz.ist.catroweb.catroid.SearchTests.java
License:Open Source License
@Test(groups = { "functionality", "upload" }, description = "search and hide project") public void searchAndHideProject() throws Throwable { try {/*www . j av a 2 s. co m*/ String projectTitle = "search_test_" + CommonData.getRandomShortString(10); projectUploader.upload( CommonData.getUploadPayload(projectTitle, "some search project", "", "", "", "", "", "")); String projectID = projectUploader.getProjectId(projectTitle); openLocation(); ajaxWait(); // hide project openAdminLocation("/tools/editProjects"); clickOkOnNextConfirmationBox(); driver().findElement(By.id("toggle" + projectID)).click(); openLocation("search/?q=" + projectTitle + "&p=1"); ajaxWait(); assertFalse(isElementPresent(By.xpath("//a[@title=\"" + projectTitle + "\"]"))); // unhide project openAdminLocation("/tools/editProjects"); clickOkOnNextConfirmationBox(); driver().findElement(By.id("toggle" + projectID)).click(); openLocation("search/?q=" + projectTitle + "&p=1"); ajaxWait(); assertTrue(isTextPresent(CommonStrings.SEARCH_PROJECTS_PAGE_TITLE.toUpperCase())); assertTrue(isElementPresent(By.xpath("//a[@title=\"" + projectTitle + "\"]"))); } catch (AssertionError e) { captureScreen("SearchTests.searchAndHideProject"); throw e; } catch (Exception e) { captureScreen("SearchTests.searchAndHideProject"); throw e; } }
From source file:at.tugraz.ist.cucumber.SeleniumStepdefs.java
License:Open Source License
@Given("^the website's language is \"([^\"]*)\"$") public void the_websites_language_is(String language) throws Throwable { I_change_the_language_to(language);//from w w w .java2 s . c o m Assert.assertTrue(driver().findElement(By.xpath("//*[@id='switchLanguage']/option[@selected]")).getText() .contains(language)); }
From source file:at.tugraz.ist.cucumber.SeleniumStepdefs.java
License:Open Source License
@When("^I use the top search box to search for a project called \"([^\"]*)\"$") public void I_use_the_top_search_box_to_search_for_a_project_called(String projectName) throws Throwable { WebElement largeTopSearchBox = driver().findElement(By.xpath("//*[@id='largeMenu']/div[4]/input")); WebElement mobileSearchBox = driver().findElement(By.xpath("//*[@id='smallSearchBar']/input")); WebElement mobileSearchButton = driver().findElement(By.id("mobileSearchButton")); if (largeTopSearchBox.isDisplayed()) { largeTopSearchBox.clear();// w w w . jav a 2 s. c om largeTopSearchBox.sendKeys(projectName); largeTopSearchBox.sendKeys(Keys.RETURN); jqueryWait(); } else if (mobileSearchButton.isDisplayed()) { mobileSearchButton.click(); mobileSearchBox.clear(); mobileSearchBox.sendKeys(projectName); mobileSearchBox.sendKeys(Keys.RETURN); jqueryWait(); } }
From source file:at.tugraz.ist.cucumber.SeleniumStepdefs.java
License:Open Source License
@When("^I press the download button$") public void I_press_the_download_button() throws Throwable { WebElement downloadButton = driver() .findElement(By.xpath("//*[@class='projectDetailsDownloadButton']/a[1]")); downloadButton.click();/* w ww .j a va 2 s .c o m*/ }
From source file:at.tugraz.ist.cucumber.SeleniumStepdefs.java
License:Open Source License
@Then("^the title of the featured section should be \"([^\"]*)\"$") public void the_title_of_the_featured_section_should_be(String title) throws Throwable { Assert.assertEquals(title, driver().findElement(By.xpath("//*[@id='programmOfTheWeek']/header")).getText()); }
From source file:at.tugraz.ist.cucumber.SeleniumStepdefs.java
License:Open Source License
@Then("^the title of the newest section should be \"([^\"]*)\"$") public void the_title_of_the_newest_section_should_be(String title) throws Throwable { Assert.assertEquals(title, driver().findElement(By.xpath("/html/body/div/article/header[3]")).getText()); }
From source file:at.tugraz.ist.cucumber.SeleniumStepdefs.java
License:Open Source License
@Then("^the download count should be increased by one$") public void the_download_count_should_be_increased_by_one() throws Throwable { By downloadCount = By.xpath("//*[@class='projectDetailsInformation']/ul/li[4]/div[2]/span"); int downloads = Integer.parseInt(driver().findElement(downloadCount).getText().split(" ")[0]); driver().navigate().refresh();//from w ww .jav a 2 s .com Assert.assertEquals(downloads + 1, Integer.parseInt(driver().findElement(downloadCount).getText().split(" ")[0])); }
From source file:atd.selenium.RegisterUser.java
License:Open Source License
@Test public void testCsv() throws Exception { String csvFile = "test/atd/selenium/RegisterUser.csv"; BufferedReader br = null;// ww w .j a v a 2s.c o m String line = ""; String cvsSplitBy = ","; try { br = new BufferedReader(new FileReader(csvFile)); while ((line = br.readLine()) != null) { // use comma as separator String[] entry = line.split(cvsSplitBy); driver.get(baseUrl + "/ATD-WEBSITE/register/register.jsp"); driver.findElement(By.name("username")).clear(); driver.findElement(By.name("username")).sendKeys(entry[0]); driver.findElement(By.name("password")).clear(); driver.findElement(By.name("password")).sendKeys(entry[2]); driver.findElement(By.name("realname")).clear(); driver.findElement(By.name("realname")).sendKeys(entry[0] + " " + entry[1]); driver.findElement(By.name("postcode")).clear(); driver.findElement(By.name("postcode")).sendKeys(entry[3]); driver.findElement(By.name("email")).clear(); driver.findElement(By.name("email")).sendKeys(entry[4]); driver.findElement(By.name("kenteken")).clear(); driver.findElement(By.name("kenteken")).sendKeys(entry[5]); driver.findElement(By.name("merk")).clear(); driver.findElement(By.name("merk")).sendKeys(entry[6]); driver.findElement(By.name("type")).clear(); driver.findElement(By.name("type")).sendKeys(entry[7]); driver.findElement(By.xpath("//input[@value='Registreren']")).click(); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (br != null) { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } } }
From source file:au.edu.qtac.admission.webtest.LoginPage.java
public IndexPage loginWithSuccessfully(String username, String password) { this.withUsername(username).withPassword(password).login(); //it is important: it makes Browser to look for the element that //the locator shows, it make driver implicitily waits //the most important is to set implicitly waits timeout long enough!!!! driver.findElement(By.xpath("//html/body/button")); // explicit wait // WebElement e = (new WebDriverWait(driver, 10)).until(new ExpectedCondition<WebElement>(){ // @Override // public WebElement apply(WebDriver d) { // return d.findElement(By.xpath("//html/body/button")); // } // }); // Another explicit wait // WebDriverWait wait = new WebDriverWait(driver, 10); // wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//html/body/button"))); return new IndexPage(driver); }