java - Text check in every page (Selenium) -


using java, trying write general check particular text on every page in web application existing tests visit. instead of having write on each , every page individually, possible in 1 place @ high level (may in base class)?

public class baseclassforuitest {                 public baseclassforuitest() {                        ...                 }                  public void test() throws exception {                        boolean isnewpage = checkifnewpage();                        if (isnewpage)                              // perform text check on page                 } } 

every test extends baseclassforuitest , overrides test() method.

instead of having write on each , every page individually, possible in 1 place @ high level (may in base class)?

yes, possible implementing webdrivereventlistener baseclassforuitest , override event handler methods handling appropriate webdriver events according need in 1 place.

here every method corresponds event. according requirement need handle afternavigateto() method. 1 called every time navigate page completed.

you have perform text checker on page code in method code executed every time page navigates other page.

public class baseclassforuitest implements webdrivereventlistener {        ---------       ---------        public void afternavigateto(string arg0, webdriver arg1) {     // perform desire text checker stuff on page here   } } 

now create event throwing webdriver perform test :-

  • create regular webdriver.

    firefoxdriver driver = new firefoxdriver(); 
  • now create eventthrowingwebdriver using our regular webdriver created above.

    eventfiringwebdriver eventdriver = new eventfiringwebdriver(driver); 
  • create instance of eventhandler class , register events using register method of eventfiringwebdriver object created above :-

    baseclassforuitest handler = new baseclassforuitest();  eventdriver.register(handler); 

full code :-

import org.openqa.selenium.support.events.eventfiringwebdriver;  public class baseclassforuitest {   public void test() throws exception {                      firefoxdriver driver = new firefoxdriver();       eventfiringwebdriver eventdriver = new eventfiringwebdriver(driver);        baseclassforuitest handler = new baseclassforuitest();   eventdriver.register(handler);        eventdriver.get("your url");        //now further stuff } } 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -