コード例 #1
0
ファイル: Tests.java プロジェクト: JairoAparicio/jairo
  @Test(timeOut = 20000)
  public void SearchingResultPosts() {
    // Validating Search No Results
    HomePage homePage = PageFactory.initElements(driver, HomePage.class);
    homePage.go(driver);
    homePage.search("not found");
    Assert.assertTrue(
        driver.findElement(By.xpath("//article[@id='post-0']/header/h1")).isDisplayed(),
        "Nothing Found");
    Assert.assertEquals("not found | Search Results | Automation Training", driver.getTitle());

    // Validating post results with the word "test"
    homePage.go(driver);
    homePage.waitForTitle();
    homePage.search("test");

    WebDriverWait waitForOne = new WebDriverWait(driver, 10);
    waitForOne.until(
        ExpectedConditions.presenceOfElementLocated(By.xpath("//h1[@id='site-title']/span/a")));
    waitForOne.until(
        ExpectedConditions.presenceOfElementLocated(
            By.xpath("//article[@id='post-39']/header/h1/a")));
    waitForOne.until(
        ExpectedConditions.presenceOfElementLocated(By.linkText("What software testing is")));

    driver.findElement(By.className("page-title")).isDisplayed();

    Assert.assertTrue(
        driver.findElement(By.xpath("//header/h1/span")).isDisplayed(), "SEARCH RESULTS FOR: TEST");

    waitForOne.until(ExpectedConditions.titleContains("test"));

    assert (driver.getTitle().contains(("test | Search Results | Automation Training")));
  }
コード例 #2
0
ファイル: Tests.java プロジェクト: JairoAparicio/jairo
  @Test(timeOut = 20000)
  public void GetPostAutor() {
    // homePage ge into the post();
    HomePage homePage = PageFactory.initElements(driver, HomePage.class);
    homePage.go(driver);
    homePage.search("test");

    // FindBy Posts

    driver.findElement(By.id("post-39"));
    WebElement myLink =
        driver.findElement(By.xpath("//a[contains(text(),'What software testing is')]"));
    driver.findElement(By.xpath("//article[@id='post-39']/header/h1/a")).getAttribute("href");
    String urlPost = myLink.getAttribute("href");
    System.out.println(urlPost);

    if (myLink.isDisplayed()) {
      myLink.click();
    }

    // Validate WebElement to the post autor;
    homePage.waitForTitle();
    WebElement autor = driver.findElement(By.xpath("//a[2]"));
    driver.findElement(By.xpath("//a[2]")).getAttribute("href");

    // Get Attribute from who posted
    String urlpostAutor = autor.getAttribute("href");
    System.out.println(urlpostAutor);
    // Validating Autor
    Assert.assertEquals("santiago.hernandez", driver.findElement(By.xpath("//a[2]")).getText());
    if (autor.isDisplayed()) {
      autor.click();
    }
    homePage.waitForTitle();
    String urlAutor = driver.getCurrentUrl();
    System.out.println(urlAutor);
    // Assertion to Url autor
    Assert.assertTrue(urlpostAutor.equals(urlAutor));
  }