-
Notifications
You must be signed in to change notification settings - Fork 5.4k
[Bug]: #31229
Description
Version
1.43.0
Steps to reproduce
public class CucumberHook {
public static ThreadLocal playwright = new ThreadLocal<>();
public static ThreadLocal browser = new ThreadLocal<>();
public static ThreadLocal browserContext = new ThreadLocal<>();
public static ThreadLocal page = new ThreadLocal<>();
@BeforeAll
public static void beforeAll() {
playwright.set(Playwright.create());
browser.set(playwright.get().chromium().launch(new BrowserType.LaunchOptions()
.setHeadless(false).setChannel("chrome")));
}
@before
public static void beforeScenario(Scenario scenario){
browserContext.set(browser.get().newContext());
page.set(browserContext.get().newPage());
page.get().navigate("https://www.saucedemo.com/");
}
public class LoginPOM {
private LoginPOM(){
}
private static LoginPOM INSTANCE;
public static LoginPOM getInstance() {
if (INSTANCE == null) {
INSTANCE = new LoginPOM();
}
return INSTANCE;
}
Page page = CucumberHook.page.get();
{
elementsMap.put("userNameInputField", page.locator("#user-name"));
elementsMap.put("passwordInputField", page.locator("#password"));
elementsMap.put("loginBtn", page.locator("#login-button"));
}
private Locator appLogo = page.locator(".app_logo");
private Locator errorMsg = page.locator("//*[@Data-test='error']");
}
Expected behavior
I would like to run parallel tests using Playwright Java and Cucumber
Actual behavior
I'm getting below exception:
java.lang.NullPointerException: Cannot invoke "com.microsoft.playwright.Browser.newContext()" because the return value of "java.lang.ThreadLocal.get()" is null
Additional context
No response
Environment
System:
OS: Windows 11 10.0.22631
CPU: (16) x64 13th Gen Intel(R) Core(TM) i7-13620H
Memory: 4.43 GB / 15.73 GB
Binaries:
Node: 20.12.0 - C:\Program Files\nodejs\node.EXE
npm: 10.5.0 - C:\Program Files\nodejs\npm.CMD