简体   繁体   English

在Servlet中执行TestNG测试时会跳过

[英]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.

相关问题 TestNg:使用maven执行测试时获取ArrayIndexOutOfBoundsException:0 - TestNg: getting ArrayIndexOutOfBoundsException: 0 while executing test with maven 执行TestNG测试时出错 - Error executing TestNG test TestNG没有在selenium webdriver中执行Test annotation内部的方法 - TestNG is not executing methods inside Test annotation in selenium webdriver 所有测试跳过以编程方式运行 testNg - All test skips on running testNg programmatically 使用Maven执行TestNG测试时的Maven跳过测试(MVN测试) - Maven Skipping Test while executing TestNG test using maven (mvn test) 如果 @AfterMethod 失败,TestNG 会跳过 @Test(invocationCount = 3) 的后续运行 - TestNG skips subsequent runs of @Test(invocationCount = 3) if @AfterMethod fails 在@DataProvider方法中引发Exception后,TestNG会跳过测试 - TestNG skips test after raising Exception in @DataProvider method testng在执行子类时再次从基类执行@Test带注释的方法 - testng executes @Test annotated methods from base class again while executing sub class java.lang.NullPointerException 同时使用 Selenium TestNG 和 Java 执行第二个 @test 注释方法 - java.lang.NullPointerException while executing second @test annotated method using Selenium TestNG and Java 在仅访问TestNG中该类的特定组时执行该类的所有测试方法 - Executing all test methods of a class while accessing only particular group of that class in TestNG
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM