Reputation: 23
So, the issue is next - I'm trying to refactor my base test to do multiple browser parallel testing, but after running my code from the testng.xml file I've got the NullPointerExeption. My BaseTest:
public class BaseTest {
String browser = System.getProperty("browser");
WebDriver driver = null;
@Parameters("browser")
@BeforeMethod(alwaysRun = true)
public void setUp() {
System.out.println("Current browser is " + browser);
if (browser.equalsIgnoreCase("chrome")) {
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
} else if (browser.equalsIgnoreCase("firefox")) {
WebDriverManager.firefoxdriver().setup();
driver = new FirefoxDriver();
} else if (browser.equalsIgnoreCase("edge")) {
WebDriverManager.edgedriver();
driver = new EdgeDriver();
}
driver.manage().window().maximize();
driver.get("https://demo.prestashop.com/");
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
BasePage.setDriverThreadLocal(driver);
}
@AfterMethod(alwaysRun = true)
public void tearDown() {
getDriver().quit();
}
}
My testng.xml configuration:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite thread-count="2" name="Suite" parallel="methods">
<test thread-count="2" name="Test" parallel="methods">
<parameter name="browser" value="chrome"/>
<classes>
<class name="SubscribeWithInvalidEmailTest"/>
<class name="CheckLanguagesTest"/>
</classes>
</test>
</suite>
I would appreciate it if you could provide me any help.
Upvotes: 2
Views: 705
Reputation: 56
There are two things-
@Parameters("browser")
@BeforeMethod(alwaysRun = true)
public void setUp(String browser) {
System.out.println("Current browser is " + browser);
and now your browser variable will have the value which is passed by the testng.xml to your code and should not give the NullPointerException anymore.
If you still facing any issue then I recommend you to please share the stack trace which can be helpful in further debugging.
Upvotes: 1