webdriver - verify text presentation on a loaded page -


i trying verify line of text present on loaded page using webdriver. created function - istextpresent, invoked function within same method.

eclipse prompted me error: the method istrue(boolean) undefined type assert.

  1. please tell me why doesn't work , how should fix it.
  2. whatis best approach verify text presentation on web page?

    2a. possible verify text presentation within first @test code fragment?

    2b. type## heading ## of method shall use in case (public, private or protected)?

my code fragment:

import java.util.list; import java.util.concurrent.timeunit; import org.junit.*;  import org.junit.before; import org.junit.after; import org.openqa.selenium.*; import org.openqa.selenium.firefox.firefoxdriver; import org.openqa.selenium.support.ui.select;  public class selftechytestng  {     private webdriver driver;     private string baseurl;      @before     public void setup() throws exception     {         driver = new firefoxdriver();         baseurl = "http://selftechy.com/";         driver.manage().timeouts().implicitlywait(10, timeunit.seconds);     }         //first test method         @test     public void searchelements() throws exception{         driver.get(baseurl);         driver.findelement(by.xpath("//a[@title='selenium']")).click();      }        @test     public boolean istextpresent(string txtvalue){          try{              boolean b = driver.getpagesource().contains(txtvalue);              return b;          }          catch (exception e){              return false;          }          assert.istrue(istextpresent("testng (next generation testing framework) – understanding annotations"));        }    } 

modification have done make call function iselementpresent work adding asserttrue() method within searchelements() methods

 asserttrue(istextpresent(txtvalue)); 

method iselementpresent

public boolean istextpresent(string str1)     {          try          {              driver.get(baseurl);              driver.findelement(by.xpath("//a[@title='selenium']")).click();              b = driver.getpagesource().contains(str1);               if(b){                  system.out.println("text presented on page");              }              else{                  system.out.println("text did not present on page");              }              return b;          }          catch (exception e)          {              system.out.println(e.getmessage());              return b;          }           //return b;      } 

or can this. first, remove @test annotation in method , remove assert @ end:

public boolean istextpresent(string txtvalue){          boolean b = false;      try{          b = driver.getpagesource().contains(txtvalue);          return b;      }      catch (exception e){          system.out.println(e.getmessage());      }           finally{       return b;      } } 

then test this

 @test public void searchelements() throws exception{     driver.get(baseurl);     driver.findelement(by.xpath("//a[@title='selenium']")).click();     assert.istrue(istextpresent("testng (next generation testing framework) – understanding annotations")); } 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -