[英]NullPointerException while trying to run my tests from testng.xml
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.所以,接下来的问题是——我正在尝试重构我的基础测试以进行多个浏览器并行测试,但是在从 testng.xml 文件运行我的代码之后,我得到了 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:我的 testng.xml 配置:
<?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.如果您能为我提供任何帮助,我将不胜感激。
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.现在您的浏览器变量将具有由 testng.xml 传递给您的代码的值,并且不应再提供 NullPointerException。
If you still facing any issue then I recommend you to please share the stack trace which can be helpful in further debugging.如果您仍然遇到任何问题,那么我建议您分享堆栈跟踪,这有助于进一步调试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.