<-Here is the base BaseClass which is extends by VerifyLoginTest & this will open driver->
public class BaseClass {
private static Properties prop;
protected static WebDriver driver;
protected static WebDriverWait wait;
@BeforeSuite
public void propReading() {
try {
File file = new File(ConstantPaths.PROP_PATH);
FileInputStream fileInputStream = new FileInputStream(file);
prop = new Properties();
prop.load(fileInputStream);
} catch (
IOException e) {
System.out.println("Properties file not found");
}
}
public static void initializeBrowser() //Selenium 4.6.0 after that
{
switch (prop.getProperty("browserName").toUpperCase()) {
case "CHROME":
driver = new ChromeDriver();
ChromeOptions options = new ChromeOptions();
//options.addArguments("kiosk-printing");
break;
case "FIREFOX":
driver = new FirefoxDriver();
break;
case "EDGE":
driver = new EdgeDriver();
default:
System.out.println("Illegal Browser Name");
break;
}
driver.manage().window().maximize();
driver.get(prop.getProperty("urlName"));
wait = new WebDriverWait(driver, Duration.ofSeconds(10));
}
public static void closeBrowser() {
driver.close();
}
}
While running same @test in pageFactory model it is giving invalidSessionId exception
package testscripts;//import java.util.*;
import actions.Actions;
import base.BaseClass;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import pagesobjects.HomePage;
public class VerifyLoginTest extends BaseClass{
@BeforeMethod
public void startBrowser()
{
BaseClass.initializeBrowser();
}
@Test
public void verifyNoValue(){
HomePage homePage = HomePage.getHomePageObj();
homePage.enterInvestmentAmount(" ");
homePage.clickOnCalculate();
Assert.assertEquals(homePage.getErrorMsg(),"This field is required");
Actions.takeScreenshot("verifyNoValue");
}
@Test
public void verifyMinValue(){
HomePage homePage = HomePage.getHomePageObj();
homePage.enterInvestmentAmount("499");
homePage.clickOnCalculate();
Assert.assertEquals(homePage.getErrorMsg(),"Min Amount is 500");
Actions.takeScreenshot("verifyMinValue");
}
@Test
public void verifyMaxValue(){
HomePage homePage = HomePage.getHomePageObj();
homePage.enterInvestmentAmount("50000001");
homePage.clickOnCalculate();
Assert.assertEquals(homePage.getErrorMsg(),"Min Amount is 500");
Actions.takeScreenshot("verifyMinValue");
}
@AfterMethod
public void tearDown(){
BaseClass.closeBrowser();
}
}
This @Test are running in one browser instance only, I am expecting it to run on different browser as I have added 3 test annotation with before method