How can I check to see if the browser has been opened yet in Selenium WebDriver with Java? -


i want make each of tests in class independent of each other able run together. right have set this

public class master {

@aftersuite public static void close() throws interruptedexception{     thread.sleep(10000);     browser.driver.quit(); }  @test(enabled=true, priority=0) public void initiate(){     browser.openbrowser("http://dev01.juanregala.com.co/"); }  @test(enabled=true, priority=1) public void addproducttocart(){      browser.isurlcorrect("http://dev01.juanregala.com.co/medellin/");     commonrepeats.gotocart("chocolates",5);  }  @test(enabled=true, priority=2) public void emptycart(){      browser.isurlcorrect("http://dev01.juanregala.com.co/medellin/");     commonrepeats.gotocart("chocolates", 5);     cart.emptycart();  }  @test(enabled=true, priority=3) public void comprar(){     browser.isurlcorrect("http://dev01.juanregala.com.co/medellin/");     commonrepeats.gotoproduct("chocolates", 5);     product.comprar(); }  @test(enabled=true, priority=4) public void schedule(){     browser.isurlcorrect("http://dev01.juanregala.com.co/medellin/");     commonrepeats.gotoproduct("chocolates", 5);     product.checkschedule(); } 

}

public class browser {

public static webdriver driver;  public static void openbrowser(string url){     driver = new firefoxdriver();     driver.get(url);     driver.manage().timeouts().implicitlywait(10, timeunit.seconds); }  public static void gohome(){     driver.navigate().to("http://dev01.juanregala.com.co/medellin/"); }  public static void isurlcorrect(string url){      string currenturl = driver.getcurrenturl();      if (currenturl==url)         system.out.println("correct url");     else         driver.navigate().to(url);  } 

}

public class commonrepeats {

public static void gotocart(string category, int nthitem){     home.choosecategory(category);     category.chooseitem(nthitem);     product.addtocart(); }  public static void gotoproduct(string category, int nthitem){     home.choosecategory(category);     category.chooseitem(nthitem); } 

}

i have been trying find sort of way boolean value use in if statement test before each test if returned false (indicating browser has not been opened , trying individually run test out of of them) have open browser last test have left can continue should.

i tried using driver.tostring() see if returned null kept getting nullpointerexception


Comments