TestNG - Test methods are not executing even with ThreadLocal Webdriver - selenium-webdriver

I have used implementation of ThreadLocal for Webdriver to run test methods in parallel from single Test class. I used BeforeMethod for LaunchingApplication and AfterMethod for teardown. Though my 6 different methods I have in Test class have different Thread IDs and 6 browser windows are opened, only one method is navigated to url and executing the method and close the browser window. Other 5 browser windows are just opened and no further actions are performed. I assume the only method that is exectued is having first thread ID.
My project in Github:
https://github.com/venkatakarteek/Practice
Please help to see my code in
BaseClass in src/test/java/com/Assignment/TestComponents
TestCases in src/test/java/com/Assignment/TestCases/TestCases
testng.xml - used to run the test methods in parallel
BaseClass
public class BaseClass {
public WebDriver driver;
protected static ThreadLocal<WebDriver> threadSafeDriver = new ThreadLocal<>();
public HomePage homePage;
public WebDriver browsersetup() throws IOException {
Properties prop = new Properties();
FileInputStream fis = new FileInputStream(
System.getProperty("user.dir") + "\\src\\main\\resource\\GlobalData.Properties");
prop.load(fis);
String browserName = System.getProperty("browser") != null ? System.getProperty("browser")
: prop.getProperty("browser");
if (browserName.contains("chrome")) {
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
}
else if (browserName.contains("edge")) {
WebDriverManager.edgedriver().setup();
driver = new EdgeDriver();
} else if (browserName.contains("firefox")) {
WebDriverManager.firefoxdriver().setup();
driver = new FirefoxDriver();
}
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
driver.manage().window().maximize();
return driver;
}
#BeforeMethod(alwaysRun = true)
public HomePage LaunchApplication() throws IOException {
driver = browsersetup();
threadSafeDriver.set(driver);
System.out.println("Before Method Thread ID: " + Thread.currentThread().getId());
driver = threadSafeDriver.get();
homePage = new HomePage(driver);
homePage.goTo();
return homePage;
}
#AfterMethod(alwaysRun = true)
public void tearDown() throws IOException {
driver.close();
System.out.println("After Method Thread ID: " + Thread.currentThread().getId());
threadSafeDriver.remove();
}
}
TestCases class
public class TestCases extends BaseClass {
#Test
public void Test1() {
System.out.println("Test1 Method Thread ID: " + Thread.currentThread().getId());
homePage.checkIfElementIsDisplayed(homePage.emailElement);
homePage.checkIfElementIsDisplayed(homePage.passwordElement);
homePage.checkIfElementIsDisplayed(homePage.signInElement);
homePage.emailElement.sendKeys("karteek#gmail.com");
homePage.passwordElement.sendKeys("******");
}
#Test
public void Test2() {
System.out.println("Test2 Method Thread ID: " + Thread.currentThread().getId());
homePage.checkValuesInListGroup();
homePage.checkSecondListItem();
homePage.checkSecondListItemBadgeValue();
}
#Test
public void Test3() throws InterruptedException {
System.out.println("Test3 Method Thread ID: " + Thread.currentThread().getId());
homePage.ScrolltotheElement(homePage.dropDownOption);
homePage.checkDefaultSelectedValue();
homePage.selectOption3();
}
#Test
public void Test4() {
System.out.println("Test4 Method Thread ID: " + Thread.currentThread().getId());
homePage.ScrolltotheElement(homePage.enabledButtonElement);
homePage.checkIfFirstButtonisEnabled();
homePage.checkIfButtonisDisabled(homePage.disabledButtonElement);
}
#Test
public void Test5() {
System.out.println("Test5 Method Thread ID: " + Thread.currentThread().getId());
homePage.ScrolltotheElement(homePage.test5Div);
homePage.ExplicitWait(homePage.test5Button);
homePage.clickOnButton();
homePage.checkIfButtonisDisabled(homePage.test5Button);
}
#Test
public void Test6() throws IOException {
System.out.println("Test6 Method Thread ID: " + Thread.currentThread().getId());
homePage.ScrolltotheElement(homePage.test6Div);
String cellValue = homePage.findValueOfCell(driver, 2, 2);
System.out.println(cellValue);
}
}
XML used to run test methods in parallel
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test thread-count="6" name="Test" parallel="methods">
<classes>
<class name="com.Assignment.TestCases.TestCases" />
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
I tried this ThreadLocal implementation by seeing the post from Linkedin
https://www.linkedin.com/pulse/selenium-parallel-testing-using-java-threadlocal-testng-shargo/
but getting parallel execution is not working for my code to run methods parallely

Related

Getting InstantiationException when creating factory for a page using appium

I am running a test case using pagefactory method and have created an appium driver. I'm trying to initialising a page using pagefactory class like this:
The test class:
public class VerifyValidLogin {
#Test
public void CheckValidUser() throws MalformedURLException {
AppiumDriver driver = DeviceFactory.CreateDriver();
login login_page = PageFactory.initElements(driver, login.class);
}
}
DeviceFactory class:
public class DeviceFactory {
public static AppiumDriver<MobileElement> driver;
public static AppiumDriver CreateDriver() throws MalformedURLException {
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability( capabilityName: 'deviceName', value: 'Something');
...
URL url = new URL("http://127.0.0.1:4723/wd/hub");
driver = new AppiumDriver<MobileElement>(url,cap);
System.out.print("Application started");
return driver;
}
}
Login class has element locators:
public class login {
AppiumDriver driver;
public login(AppiumDriver ldriver)
{
this.driver=ldriver;
}
#FindBy(how = How.XPATH,using ="xpath");
MobileElement SignInButton;
}
But i'm not sure where i am doing wrong.
The error is
java.lang.RuntimeException: java.lang.InstantiationException: com.Demo.pages.login
at org.openqa.selenium.support.PageFactory.instantiatePage(PageFactory.java:134)
at org.openqa.selenium.support.PageFactory.initElements(PageFactory.java:64)
at com.Demo.Testcases.VerifyValidLogin.CheckValidUser(VerifyValidLogin.java:18)
...
I am new to the automation testing so i'm not able to properly understand the error. Let me know if you need more details.
Initialise elements in constructor
public login(AppiumDriver ldriver)
{
this.driver=ldriver;
PageFactory.initElements(ldriver,this);
}

Cucumber #Before hook runs twice #After once

to all.
Curently writing a little BDD Test automation framework, using Java11+Junit5+Cucumber+Selenium, build tool: Graddle. Created a little test for validating Google title. When starting test, using Test task in Graddle or running CucumberRunner class, in both cases getting the same result: two times #Before method is executed, once #After method is executed and one browser windows is staying open. After added one more test, the same situation, only 4 browsers are opened, 2 of them are closing. Can anyone help with this situation?
Link to repository
After some watching of logs saw, that, seems, #Before is not executed twice, but Driver class is initialized twice, but why it happens no idea for now...
My code for now:
CucumberRunner.java:
#RunWith(Cucumber.class )
#CucumberOptions(
features = "src\\test\\java\\features",
glue = {"steps", "utils"},
tags = "#smoke")
public class CucumberRunner {
}
Driver.java:
public class Driver {
private WebDriver driver;
public Driver(){
driverInitialization();
}
private void driverInitialization(){
System.setProperty("webdriver.chrome.driver", "D:\\Soft\\selenium-drivers\\chromedriver.exe");
System.out.println("Starting driver.");
var browserName = "chrome";
switch (browserName.toLowerCase()){
case "chrome":
System.out.println("Starting chrome");
driver = new ChromeDriver();
System.out.println("Before break.");
break;
case "firefox":
driver = new FirefoxDriver();
break;
default:
throw new NotFoundException("Browser not found: " + browserName);
}
}
public WebDriver getDriver(){
return driver;
}
public WebDriverWait getWebDriverWait(){
return new WebDriverWait(driver, 120);
}
public void terminateDriver(){
System.out.println("Terminating driver.");
if (driver != null) {
driver.close();
driver.quit();
}
}
}
Hooks.java:
public class Hooks {
private Driver driver;
#Before
public void setup(){
System.out.println("In the Setup method.");
driver = new Driver();
}
#After
public void tearDown(){
System.out.println("In the TearDown method.");
driver.terminateDriver();
}
}
I think your Hook Class should be like this As You Are Using selenium-picocontainer DI.
public class Hooks {
private Driver driver;
public Hooks(Driver driver) {
this.driver = driver;
}
#Before
public void setup(){
System.out.println("In the Setup method.");
}
#After
public void tearDown(){
System.out.println("In the TearDown method.");
driver.terminateDriver();
}
}

Page Objects erro (java.lang.NullPointerException)

I did a basic project to training about Page Objects using selenium WebDriver with java and Junit. So, I make a page object class and Junit class too. I Make a call of method and pass the parameters to method but, the eclipse show a message that say: java.lang.NullPointerException
public class LogarBkoMaisPage {
static WebDriver driver;
By campoNome = By.id("matricula_I");
By campoSenha = By.id("senha_I");
By btnLogin = By.id("bt_entrar");
public LogarBkoMaisPage(WebDriver driver) {
this.driver = driver;
}
public void logar(String usuario, String senha) {
driver.findElement(campoNome).sendKeys(usuario);
driver.findElement(campoSenha).sendKeys(senha);
driver.findElement(btnLogin).click();
}
}
public class LogarBkoMaisTest {
static WebDriver driver;
#Before
public void setUp() throws Exception {
SelecionarNavegador nav = new SelecionarNavegador();
nav.iniciarNavegador("ie","http://10.5.9.45/BkoMais_Selenium/");
}
#Test
public void logarAplicacao() {
try {
LogarBkoMaisPage login = new LogarBkoMaisPage(driver);
login.logar("844502","Bcc201707");
}catch(Exception e) {
System.out.println("Mensagem de erro: " +e);
}
}
#After
public void tearDown() throws Exception {
}
}
public class SelecionarNavegador {
static WebDriver driver;
public static WebDriver iniciarNavegador(String nomeNavegador, String url) {
if(nomeNavegador.equalsIgnoreCase("firefox")) {
System.setProperty("webdriver.gecko.driver", "E:\\workspace_BCC_QA_BKOMAIS\\"
+ "FireFoxGeckodriver64\\geckodriver.exe");
driver = new FirefoxDriver();
}
else if(nomeNavegador.equalsIgnoreCase("chrome")){
System.setProperty("webdriver.chrome.driver", "E:\\workspace_BCC_QA_BKOMAIS"
+ "\\chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver();
}else if(nomeNavegador.equalsIgnoreCase("IE")) {
System.setProperty("webdriver.ie.driver", "E:\\workspace_BCC_QA_BKOMAIS"
+ "\\IE Plugin\\IEDriverServer.exe");
driver = new InternetExplorerDriver();
}
driver.manage().window().maximize();
driver.get(url);
return driver;
}
}
Exception:
You are getting a null pointer exception because iniciarNavegador method inside SelecionarNavegador class is the one which initializes the driver and it returns the driver which has to be assigned to a vairable. You need to do this in your setUp()method
#Before
public void setUp() throws Exception {
SelecionarNavegador nav = new SelecionarNavegador();
driver=nav.iniciarNavegador("ie","http://10.5.9.45/BkoMais_Selenium/");
}

I want to run different classes particular method from TestNG but everytime it opens a new window when i include beforeclass in each class

I want to run different classes particular method from TestNG but everytime it opens a new window when i include beforeclass in each class so i have now excluded beforeclass from add and logout classes so it can use same browser to run rest methods but its not working
The first class is of login class which is as below
public class LoginWeb {
public WebDriver driver;
WebDriverWait wait;
LoginScreen loginExcel;
#BeforeClass
public void beforeClass (){
System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
driver=new ChromeDriver();
driver.manage().window().maximize();
driver.get("http://10.7.1.180/views/index.html#/login");
System.out.println(driver.getTitle());
}
#Test (description = "Valid Credentials!")
public void LoginWithValidWebExcelEmailAndPass() throws IOException, BiffException {
loginExcel= new LoginScreen(driver);
FileInputStream fi = new FileInputStream("D:\\Programs\\New\\Sourcesmartdata.xls");
Workbook w = Workbook.getWorkbook(fi);
Sheet s = w.getSheet(0);
int z = s.getRows();
System.out.println("no of rows------------------------:"+z);
String email = s.getCell(0, 1).getContents();
System.out.println("Email -----------------"+email);
loginExcel.EnterEmail(email);
String password= s.getCell(1, 1).getContents();
System.out.println("Password------------------- "+password);
loginExcel.EnterPassword(password);
loginExcel.ClickToLogin();
wait= new WebDriverWait(driver, 10);
WebElement GetLogo = wait.until(ExpectedConditions.visibilityOf(loginExcel.TopRightMenu));
String str= GetLogo.getText();
System.out.println("Text------------"+str);
Assert.assertEquals(str, "Source Smart");
}
}
The second class is of adding commodities here i have excluded beforeclass as if i include before class it opens a new window and here login script is not written
public class AddCommoditiesWeb{
WebDriver driver;
WebDriverWait wait;
AddCommodities addcommodity;
#Test (description="Add Multiple Commodities!")
public void AddMultipleNewCommodities () throws Exception, Exception{
addcommodity = new AddCommodities(driver);
addcommodity.MenuCommodities(); //click left menu to open manage commodities page
FileInputStream fi = new FileInputStream("D:\\Programs\\New\\Sourcesmartdata.xls");
Workbook w = Workbook.getWorkbook(fi);
Sheet s = w.getSheet(1);
int z=s.getRows();
System.out.println("no of rows------------------------:"+z);
for(int row=1; row <2; row++){
Thread.sleep(5000);
addcommodity.ClickAddCommodities(); // click add commodity button
String commodityname = s.getCell(0, row).getContents();
System.out.println("commodityname -----------------"+commodityname);
//enterdefinecommodityTxtBox.sendKeys(commodityname);
addcommodity.Enterdefinecommodity(commodityname);
String grade= s.getCell(1, row).getContents();
System.out.println("grade------------------- "+grade);
//entergradeTxtBox.sendKeys(grade);
String unit= s.getCell(2, row).getContents();
System.out.println("unit------------------- "+unit);
//enterunitTxtBox.sendKeys(unit);
String minprice= s.getCell(3, row).getContents();
System.out.println("min price------------------- "+minprice);
//enterminpriceTxtBox.sendKeys(minprice);
String maxprice= s.getCell(4, row).getContents();
System.out.println("max price------------------- "+maxprice);
//entermaxpriceTxtBox.sendKeys(maxprice);
addcommodity.EnterAddCommoditiesData(grade,unit,minprice,maxprice);
}
wait=new WebDriverWait(driver,10);
WebElement commodityname= wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("/html/body/div/div[4]/div/section[2]/div[4]/d-expand-collapse[1]/div/div/div[1]/h4/a")));
String commoditynamejustadded= commodityname.getText();
System.out.println("name--------------"+commoditynamejustadded);
assertEquals(commoditynamejustadded, "Rice");
}
}
TestNG code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test name="Login check">
<classes>
<class name="SourceSmartWeb.LoginWeb"/>
<class name = "SourceSmartWeb.AddCommoditiesWeb">
<methods>
<include name="AddMultipleNewCommodities"/>
</methods>
</class>
<class name ="SourceSmartWeb.LogoutWeb"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
Logout class:
public class LogoutWeb{
WebDriver driver;
// #BeforeClass
// public void beforeClass (){
// System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
// driver=new ChromeDriver();
// driver.manage().window().maximize();
// driver.get("http://10.7.1.180/views/index.html#/login");
// System.out.println(driver.getTitle());
// super.beforeClass();
//
// }
#Test
public void Logout() throws InterruptedException {
LogoutScreen logout=new LogoutScreen(driver);
logout.ClickToLogout();
}
#AfterClass
public void exit(){
driver.quit();
}
}
What its doing is it opens the browser logins and then do nothing. How can i make it do rest of activities on same browser as if i add before class in second class it opens a new browser and then there i dont have login code. please guide
From what you are stating, it looks like you need to basically have a browser spawned per <test> tag and then share that browser amongst all your test classes. But you cannot make use of the #BeforeTest and #AfterTest annotations because you would need to bring in inheritance into the picture and since these methods are executed only once per <test> you will start seeing NullPointerException.
So the idea is to basically leverage TestNG listeners for this webdriver instantiation and cleanup and have your test classes/methods just query them from within a helper method.
Here's some sample code, that shows all of this in action.
Here's how the listener would look like
package com.rationaleemotions.stackoverflow.qn46239358;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.ITestContext;
import org.testng.ITestResult;
import org.testng.Reporter;
import org.testng.TestListenerAdapter;
public class WebdriverSpawner extends TestListenerAdapter {
private static final String WEBDRIVER = "webdriver";
#Override
public void onStart(ITestContext testContext) {
testContext.setAttribute(WEBDRIVER, createDriver());
}
#Override
public void onFinish(ITestContext testContext) {
getWebDriverFromContext(testContext).quit();
}
public static RemoteWebDriver getCurrentWebDriver() {
ITestResult result = Reporter.getCurrentTestResult();
if (result == null) {
throw new IllegalStateException("Please invoke this from within a #Test annotated method");
}
ITestContext context = result.getTestContext();
return getWebDriverFromContext(context);
}
private static RemoteWebDriver getWebDriverFromContext(ITestContext context) {
Object object = context.getAttribute(WEBDRIVER);
if (!(object instanceof RemoteWebDriver)) {
throw new IllegalStateException("Encountered problems in retrieving the webdriver instance");
}
return (RemoteWebDriver) object;
}
private static RemoteWebDriver createDriver() {
return new ChromeDriver();
}
}
Here's how your test classes which now use this above listener can look like (I have intentionally kept it simple and have it open up just a URL, but if you run them you would notice a single browser opening up multiple URLs. So only one browser instance)
package com.rationaleemotions.stackoverflow.qn46239358;
import org.testng.annotations.Test;
public class LoginWeb {
#Test(description = "Valid Credentials!")
public void LoginWithValidWebExcelEmailAndPass() {
System.err.println("Page title : " + PageLoader.loadAndGetTitle("http://www.google.com"));
}
}
package com.rationaleemotions.stackoverflow.qn46239358;
import org.testng.annotations.Test;
public class LogoutWeb {
#Test
public void Logout() throws InterruptedException {
System.err.println("Page title : " + PageLoader.loadAndGetTitle("http://www.facebook.com"));
}
}
package com.rationaleemotions.stackoverflow.qn46239358;
import org.testng.annotations.Test;
public class AddCommoditiesWeb {
#Test(description = "Add Multiple Commodities!")
public void AddMultipleNewCommodities() {
System.err.println("Page title : " + PageLoader.loadAndGetTitle("http://www.yahoo.com"));
}
#Test
public void anotherTestMethod() {
System.err.println("Page title : " + PageLoader.loadAndGetTitle("http://www.ndtv.com"));
}
}
The PageLoader utility class looks like this
package com.rationaleemotions.stackoverflow.qn46239358;
import org.openqa.selenium.remote.RemoteWebDriver;
public final class PageLoader {
private PageLoader() {
//Utility class defeat instantiation
}
public static String loadAndGetTitle(String url) {
RemoteWebDriver driver = WebdriverSpawner.getCurrentWebDriver();
driver.get(url);
return driver.getTitle();
}
}
Here's how the suite xml looks like :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="46216357_Suite" verbose="2">
<listeners>
<listener class-name="com.rationaleemotions.stackoverflow.qn46239358.WebdriverSpawner"/>
</listeners>
<test name="Login_check">
<classes>
<class name="com.rationaleemotions.stackoverflow.qn46239358.LoginWeb"/>
<class name="com.rationaleemotions.stackoverflow.qn46239358.AddCommoditiesWeb">
<methods>
<include name="AddMultipleNewCommodities"/>
</methods>
</class>
<class name="com.rationaleemotions.stackoverflow.qn46239358.LogoutWeb"/>
</classes>
</test>
</suite>
So here none of your #Test classes invoke driver.quit() explicitly. The webdriver cleanup is managed by the listener.
This model is going to work only when you want to run multiple tests on the same browser.
The flip side of this would be that, you can NEVER run your #Test methods in parallel, because now all your tests are sharing the same browser.

Selenium Grid running tests in parallel

Currently, I have a Selenium grid setup, with 1 local hub and 2 local nodes. The hub is capable of distributing the tests to run in parallel and distribute it over to the nodes. I am running the tests in parallel.
The following is the base test
public abstract class BaseTest
{
String testFolder;
String testName;
protected String envName;
protected Configuration config;
protected String host;
protected RemoteWebDriver driver;
protected String proxy;
protected SomeData someData;
protected SomeController someController;
public BaseTest() {
}
public BaseTest( String testFolder, String testName)
{
this.testFolder = testFolder;
this.testName = testName;
this.envName = System.getProperty("config");
this.proxy = System.getProperty("proxy");
config = this.envName;
}
#BeforeMethod
public void startTest(Method testMethod) {
LOG.info("Starting test: " + testMethod.getName());
try {
this.someData = new SomeData();
this.driver = WebDriverSetup.getDriver();
this.someController = new someController(this.driver, this.someData);
driver.navigate().to("https://" + this.host);
} catch (MalformedURLException e) {
System.out.println("MalformedURLException");
}
}
#AfterMethod
public void closeWindow() {
driver.close();
driver.quit();
}
}
The following is the class to get the RemoteWebDriver:
public class WebDriverSetup {
public static RemoteWebDriver getDriver() throws MalformedURLException{
String SELENIUM_HUB_URL = "http://localhost:4444/wd/hub";
ThreadLocal<RemoteWebDriver> remoteWebDriver = null;
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
String proxy = System.getProperty("proxy");
if (proxy != null && !proxy.isEmpty()) {
System.out.println("Using proxy: " + proxy);
capabilities.setCapability(CapabilityType.PROXY, proxy);
}
try {
remoteWebDriver = new ThreadLocal<RemoteWebDriver>();
remoteWebDriver.set(new RemoteWebDriver(new URL(SELENIUM_HUB_URL),
capabilities));
} catch (MalformedURLException e) {
System.out.println("Tackle Issue with RemoteDriverSetup");
}
remoteWebDriver.get().manage().window()
.setSize(new Dimension(2880, 1524));
remoteWebDriver.get().manage().timeouts()
.pageLoadTimeout(10, TimeUnit.SECONDS);
remoteWebDriver.get().manage().timeouts()
.implicitlyWait(10, TimeUnit.SECONDS);
return remoteWebDriver.get();
}
}
My test suite is like :
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Multiple Tests Suite" verbose="1" parallel="methods">
<test name="Test1">
<classes>
<class name="com.itesteverything.qa.Tests"></class>
</classes>
</test>
</suite>
Tests are like :
public class Tests extends BaseTest {
#Parameters({"testName", "env" })
public Tests( #Optional String testName, #Optional String env ) {
super( null, testName, null, env );
}
#BeforeMethod
public void setup() throws Exception {
//setSomeData
}
public void test1() throws Exception {
use driver from super
use someData from super
use someController is using the driver from super
}
public void test2() throws Exception {
use driver from super
use someData from super
use someController is using the driver from super
}
While running these tests, I get the following errors
Build info: version: '2.44.0', revision: '76d78cf323ce037c5f92db6c1bba601c2ac43ad8', time: '2014-10-23 13:11:40'
Driver info: driver.version: RemoteWebDriver
org.openqa.selenium.remote.SessionNotFoundException: Session ID is null. Using WebDriver after calling quit()?
Build info: version: '2.44.0', revision: '76d78cf323ce037c5f92db6c1bba601c2ac43ad8', time: '2014-10-23 13:11:40'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:572)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:352)
at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:393)
at org.openqa.selenium.By$ById.findElement(By.java:214)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:344)
at org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:59)
at com.sun.proxy.$Proxy25.sendKeys(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:673)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:842)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1166)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
TEST FAILED: test2
FAILED REASON: Session ID is null. Using WebDriver after calling quit()?
Is it something anyone aware of?
Thanks in advance!
Do not set driver in the base class, do not have driver property at all. The same instance is being overridden by different threadlocal drivers.
Any time you want to run your test, refer to WebDriverSetup.getDriver() in your test method itself and in your after/before methods.
#AfterMethod
Is running after each method.
And U run's only one setup. So after first method U close and it is closed as shows stack trace.

Resources