///
`公共类ApplicationHooks {
private DriverFactory driverFactory;
private WebDriver driver;
private ConfigReader configReader;
Properties prop;
@Before(order=0)
public void getProperty() {
configReader = new ConfigReader();
prop = configReader.init_prop();
}
@Before(order=1)
public void launchBrowser() throws Exception {
String browserName= prop.getProperty("browser");
driverFactory = new DriverFactory();
driver= driverFactory.init_driver(browserName);
}
}`
///
公共类 DriverFactory {
public WebDriver driver;
public static ThreadLocal<WebDriver> tlDriver= new ThreadLocal<WebDriver>();
public WebDriver init_driver(String browser) throws Exception {
System.out.println("brower value is "+ browser);
if(browser.equals("chrome")) {
Runtime.getRuntime().exec("taskkill /F /IM chrome.exe");
Runtime.getRuntime().exec("taskkill -f -im chromedriver.exe");
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + "/Driver/chromedriver_V124.exe");
ChromeOptions options= new ChromeOptions();
options.addArguments("--remote-debugging-port=9222");
options.addArguments("--no-sandbox");
options.addArguments("--start-maximized");
options.addArguments("--remote-allow-origins=*");
driver =new ChromeDriver(options);
tlDriver.set(driver);
}
else {
System.out.println("Please pass the correct browser value");
}
return getDriver();
}
public static synchronized WebDriver getDriver() {
return tlDriver.get();
}
}
///
公共课程 sessionDetailsStepDef {
private ViewSingleOrderMethods viewSingleOrderMethods = new ViewSingleOrderMethods(DriverFactory.getDriver());
@Given("Advisor will open abc applcation")
public void advisor_will_open_abc_applcation() {
System.out.println("In 1st step");
DriverFactory.getDriver().get("https:google.com");
}
/// [31mio.cucumber.core.exception.CucumberException:无法实例化类stepDefinitions.sessionDetailsStepDef 在 io.cucumber.core.backend.DefaultObjectFactory.cacheNewInstance(DefaultObjectFactory.java:67) 在 io.cucumber.core.backend.DefaultObjectFactory.getInstance(DefaultObjectFactory.java:45) 在io.cucumber.java.AbstractGlueDefinition.invokeMethod(AbstractGlueDefinition.java:47) 在 io.cucumber.java.JavaStepDefinition.execute(JavaStepDefinition.java:29) 在 io.cucumber.core.runner.CoreStepDefinition.execute(CoreStepDefinition.java:66) 在 io.cucumber.core.runner.PickleStepDefinitionMatch.runStep(PickleStepDefinitionMatch.java:63) 在 io.cucumber.core.runner.ExecutionMode$1.execute(ExecutionMode.java:10) 在 io.cucumber.core.runner.TestStep.executeStep(TestStep.java:81) 在 io.cucumber.core.runner.TestStep.run(TestStep.java:53) 在 io.cucumber.core.runner.PickleStepTestStep.run(PickleStepTestStep.java:51) 在io.cucumber.core.runner.TestCase.run(TestCase.java:84) 在 io.cucumber.core.runner.Runner.runPickle(Runner.java:75) 在 io.cucumber.junit.PickleRunners$NoStepDescriptions.lambda$run$0(PickleRunners.java:151) 在 io.cucumber.core.runtime.CucumberExecutionContext.lambda$runTestCase$5(CucumberExecutionContext.java:136) 在io.cucumber.core.runtime.RethrowingThrowableCollector.executeAndThrow(RethroingThrowableCollector.java:23) 在io.cucumber.core.runtime.CucumberExecutionContext.runTestCase(CucumberExecutionContext.java:136) 在 io.cucumber.junit.PickleRunners$NoStepDescriptions.run(PickleRunners.java:148) 在 io.cucumber.junit.FeatureRunner.runChild(FeatureRunner.java:144) 在 io.cucumber.junit.FeatureRunner.runChild(FeatureRunner.java:28) 在 org.junit.runners.ParentRunner$4.run(ParentRunner.java:331) 在 org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79) 在 org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329) 在 org.junit.runners.ParentRunner.access$100(ParentRunner.java:66) 在 org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293) 在 org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) 在 org.junit.runners.ParentRunner.run(ParentRunner.java:413) 在 io.cucumber.junit.FeatureRunner.run(FeatureRunner.java:137) 在 io.cucumber.junit.Cucumber.runChild(Cucumber.java:196) 在 io.cucumber.junit.Cucumber.runChild(Cucumber.java:89) 在 org.junit.runners.ParentRunner$4.run(ParentRunner.java:331) 在 org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79) 在 org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329) 在 org.junit.runners.ParentRunner.access$100(ParentRunner.java:66) 在 org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293) 在 io.cucumber.core.runtime.CucumberExecutionContext.lambda$runFeatures$6(CucumberExecutionContext.java:147) 在 io.cucumber.core.runtime.CucumberExecutionContext.execute(CucumberExecutionContext.java:162) 在 io.cucumber.core.runtime.CucumberExecutionContext.runFeatures(CucumberExecutionContext.java:145) 在 io.cucumber.junit.Cucumber$StartAndFinishTestRun.evaluate(Cucumber.java:226) 在 org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) 在 org.junit.runners.ParentRunner.run(ParentRunner.java:413) 在org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:93) 在 org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:40) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:529) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:756) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:452) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210) 引起原因:java.lang.reflect.InitationTargetException 在 java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法) 在 java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) 在 java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 在 java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490) 在 io.cucumber.core.backend.DefaultObjectFactory.cacheNewInstance(DefaultObjectFactory.java:53) ... 45 更多 引起原因:java.lang.IllegalArgumentException:当链接文本为空时找不到元素。 在 org.openqa.selenium.internal.Require$ArgumentChecker.nonNull(Require.java:207) 在 org.openqa.selenium.By$ByLinkText.(By.java:207) 在 org.openqa.selenium.By.linkText(By.java:57) 在 com.pages.ViewSingleOrderMethods.(ViewSingleOrderMethods.java:14) 在stepDefinitions.sessionDetailsStepDef.(sessionDetailsStepDef.java:13) ... 50多个
选择 50K+ 在线商店的最佳优惠、优惠券和促销代码,并通过 HotDeals.com 省钱。