[英]TestNG test skips while executing it inside servlet
I am trying to Execute TestNG test inside servlet with the help of " TestListenerAdapter " and " TestNG " my code snippet is like this: 我试图借助“ TestListenerAdapter ”和“ TestNG ”在Servlet内执行TestNG测试,我的代码片段是这样的:
TestListenerAdapter tla = new TestListenerAdapter();
TestNG testng = new TestNG();
testng.setTestClasses(new Class[] {src.scriptDemo.LoginTest.class});
testng.addListener(tla);
testng.run();
So, When i am executing this code snippet inside a Java Program the test name "LoginTest" is executing successfully (ie test starts, browsers opens and whole test executes). 因此,当我在Java程序中执行此代码段时,测试名称“ LoginTest”正在成功执行(即测试启动,浏览器打开并执行整个测试)。 But when the same code runs inside a Servlet it gives: 但是,当相同的代码在Servlet中运行时,它给出:
[TestNG] Running:
Command line suite
===============================================
Command line suite
Total tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 1
===============================================
It seems like test starts to execute but skipped. 似乎测试开始执行但被跳过了。 I don't know the reason behind this. 我不知道背后的原因。
PS: I debug my code and found that, It skips test due to FirefoxDriver() in the LoginTest selenium script file. PS:我调试了代码,发现由于LoginTest硒脚本文件中的FirefoxDriver(),它跳过了测试。 Code of LoginTest.java is: LoginTest.java的代码是:
package src.scriptDemo;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class LoginTest {
WebDriver driver;
String baseUrl;
@BeforeTest
public void setupSelenium() {
driver = new FirefoxDriver(true);
baseUrl = "https://example.com/login";
System.out.println("1:");
}
@Test
public void testCsrLogin() {
driver.get(baseUrl);
System.out.println("2:");
driver.findElement(By.id("username")).sendKeys("blah");
driver.findElement(By.id("password")).sendKeys("blah");
driver.findElement(By.className("btn-primary")).click();
}
@AfterTest
public void closeSelenium() {
System.out.println("3:");
driver.close();
driver.quit();
}
}
But while executing again by commenting FirefoxDriver(), the test runs without any problem and gives output 但是,在通过注释FirefoxDriver()再次执行时,测试运行没有问题,并提供了输出
Total tests run: 1, Failures: 1, Skips: 0
Can anyone suggest whats going on here and how to solve it, Please let me know if more description is required. 任何人都可以建议这里发生了什么事以及如何解决它,如果需要更多说明,请告诉我。
Thanks in Advance 提前致谢
If you run them inside a container, the should make use of selenium grid.(ie, you have to create a RemoteWebDriver instance rather your Browser Specific instance).To get started with selenium grid please visit this link . 如果您在容器中运行它们,则应该利用硒网格。(即,您必须创建一个RemoteWebDriver实例,而不是您的浏览器特定实例)。要开始使用硒网格,请访问此链接 。 Make sure the Selenium and grid dependency are added and packaged in your war. 确保在您的战争中添加并打包了硒和网格依赖项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.