黄瓜并行测试在本地运行良好,但在詹金斯身上抛出了NPE

时间:2019-04-09 19:19:47

标签: java selenium jenkins cucumber

因此,我们使用Cucable插件并行运行测试。我们的框架(导致问题的部分)就是这样设计的-

DriverManager类通过initiateWebDriverInstance方法初始化驱动程序。我们从Hooks类中调用此方法。有一个静态instance变量,它将保存已初始化驱动程序对其对象的引用。

DriverManager.java

public class DriverManager
{
     public static DriverManagerinstance;  // instance variable for DriverManager
     public WebDriver driver;
     public static String browsername = "chrome";

     public static DriverManager getInstance() {
        if (instance == null) {
            instance = new DriverManager();
        }
        return instance;
     }

     public void initiateWebDriverInstance(String browserName) {
        //initializing chrome driver
        driver.manage().window().maximize(); //this is executing fine
     }

    //some code
}

Hooks.java

public class Hooks {

    @Before
    public void setup() {  

  DriverManager.getInstance().initiateWebDriverInstance(DriverManager.browsername);

}

 @After...
  }

Page1Steps.java

public class Page1Steps extends WebSessionManager {

    private WebDriver driver = WebSessionManager.getInstance().driver; //driver is null here only in Jenkins rest working fine
    private C2CWebLibrary webLibrary = new C2CWebLibrary(driver); //this is C2CLandingSteps.java:20
//some code
}

这些测试在我的本地计算机上运行良好,但它们在Jenkins机器上生成-

  

java.lang.NullPointerException   在com.cars24.library.C2CWebLibrary。(C2CWebLibrary.java:30)在   steps.C2C.C2CLandingSteps。(C2CLandingSteps.java:20)位于   sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法)     在   sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)     在   sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)     在java.lang.reflect.Constructor.newInstance(Constructor.java:423)     在   org.picocontainer.injectors.AbstractInjector.newInstance(AbstractInjector.java:145)     在   org.picocontainer.injectors.ConstructorInjector $ 1.run(ConstructorInjector.java:342)     在   org.picocontainer.injectors.AbstractInjector $ ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)     在   org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364)     在   org.picocontainer.injectors.AbstractInjectionFactory $ LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)     在   org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)     在   org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)     在   org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699)     在   org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)     在   org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:678)     在   cumul.runtime.java.picocontainer.PicoFactory.getInstance(PicoFactory.java:40)     在   cumul.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:38)     在   cumul.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:37)     在黄瓜。运行时。运行时间。运行步骤(运行时.java:300)在   黄瓜。运行时模型.StepContainer.runStep(StepContainer.java:44)     在   黄瓜。运行时模型.StepContainer.runSteps(StepContainer.java:39)     在   cuming.runtime.model.CucumberScenario.run(CucumberScenario.java:44)     在   cumul.runtime.junit.ExecutionUnitRunner.run(ExecutionUnitRunner.java:102)     在   cumul.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:63)     在   cumul.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:18)     在org.junit.runners.ParentRunner处$ 3.run(ParentRunner.java:290)在   org.junit.runners.ParentRunner $ 1.schedule(ParentRunner.java:71)在   org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)在   org.junit.runners.ParentRunner.access $ 000(ParentRunner.java:58)在   org.junit.runners.ParentRunner $ 2.evaluate(ParentRunner.java:268)在   org.junit.runners.ParentRunner.run(ParentRunner.java:363)在   banana.runtime.junit.FeatureRunner.run(FeatureRunner.java:70)在   cuming.api.junit.Cucumber.runChild(Cucumber.java:95)在   cuming.api.junit.Cucumber.runChild(Cucumber.java:38)在   org.junit.runners.ParentRunner $ 3.run(ParentRunner.java:290)在   org.junit.runners.ParentRunner $ 1.schedule(ParentRunner.java:71)在   org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)在   org.junit.runners.ParentRunner.access $ 000(ParentRunner.java:58)在   org.junit.runners.ParentRunner $ 2.evaluate(ParentRunner.java:268)在   org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)     在   org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)     在org.junit.runners.ParentRunner.run(ParentRunner.java:363)处   Cucumber.api.junit.Cucumber.run(Cucumber.java:100)在   org.junit.runner.JUnitCore.run(JUnitCore.java:137)在   org.junit.runner.JUnitCore.run(JUnitCore.java:115)在   org.testng.junit.JUnit4TestRunner.start(JUnit4TestRunner.java:82)在   org.testng.junit.JUnit4TestRunner.run(JUnit4TestRunner.java:70)在   org.testng.TestRunner $ 1.run(TestRunner.java:667)在   org.testng.TestRunner.runJUnitWorkers(TestRunner.java:950)在   org.testng.TestRunner.privateRunJUnit(TestRunner.java:698)在   org.testng.TestRunner.run(TestRunner.java:599)在   org.testng.SuiteRunner.runTest(SuiteRunner.java:380)在   org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375)在   org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)在   org.testng.SuiteRunner.run(SuiteRunner.java:289)在   org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)在   org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)在   org.testng.TestNG.runSuitesSequentially(TestNG.java:1301)在   org.testng.TestNG.runSuitesLocally(TestNG.java:1226)在   org.testng.TestNG.runSuites(TestNG.java:1144)在   org.testng.TestNG.run(TestNG.java:1115)在   org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:135)     在   org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeSingleClass(TestNGDirectoryTestSuite.java:112)     在   org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:99)     在   org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:146)     在   org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:384)     在   org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:345)     在   org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:126)     在   org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:418)

测试在我的本地计算机上运行良好。这可能是什么问题?

0 个答案:

没有答案