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 regularwebdriver
created above.eventfiringwebdriver eventdriver = new eventfiringwebdriver(driver);
create instance of
eventhandler
class , register events using register method ofeventfiringwebdriver
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
Post a Comment