gpt4 book ai didi

java - Cucumber 在 @before hook 期间失败 : NoClassDefFoundError

转载 作者:太空宇宙 更新时间:2023-11-04 09:56:35 27 4
gpt4 key购买 nike

Chrome 浏览器打开后,自动化框架将不会继续执行 .feature 文件中的步骤(然后关闭)

GenericStepImplementation.java 代码

@Before
public void setUp() throws ConfigurationException, org.apache.commons.configuration.ConfigurationException
{
System.setProperty("webdriver.chrome.ChromeDriver","C:\\Automation\\Webdrivers\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().window().maximize();
config = new XMLConfiguration("sample-object-config.xml");
}

RunAutoTest.java代码

package test_runner;

import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(
glue={"code_bindings"},
features="src/test/resources/features",
plugin = {"pretty", "html:target/cucumber-html-report"})

public class RunAutoTest {

}

示例.特征

Feature: Automation Test

@Login-Successful
Scenario: Login (Successful)
Given I go to "www.yahoo.com" URL
Then I enter "m@yahoo.com" into "login.username" field and click tab
Then I enter "1234567890" into "login.password" text field
Then I clicked on "login.loginlink" login button
Then I wait for "15" seconds
And I will capture the page named "Login-Successful"

作为 JUnit Test 运行后,Chrome 浏览器已打开,但不执行 Sample.feature 文件中的步骤。控制台还显示:

*Feature: Automation Test
Starting ChromeDriver 2.45.615291 (ec3682e3c9061c10f26ea9e5cdcf3c53f3f74387) on port 11795
Only local connections are allowed.
Jan 07, 2019 6:00:53 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
[31mFailure in before hook:[0m[31mGenericStepImplementation.setUp()[0m
[31mMessage: [0m[31mjava.lang.NoClassDefFoundError: org/apache/commons/collections/CollectionUtils
at org.apache.commons.configuration.XMLConfiguration.constructHierarchy(XMLConfiguration.java:640)
at org.apache.commons.configuration.XMLConfiguration.constructHierarchy(XMLConfiguration.java:635)
at org.apache.commons.configuration.XMLConfiguration.initProperties(XMLConfiguration.java:596)
at org.apache.commons.configuration.XMLConfiguration.load(XMLConfiguration.java:1009)
at org.apache.commons.configuration.XMLConfiguration.load(XMLConfiguration.java:972)

最佳答案

您需要将 System.setProperty 行中的关键字从 ChromeDriver 更改为 driver,即更改:

System.setProperty("webdriver.chrome.ChromeDriver","C:\\Automation\\Webdrivers\\chromedriver.exe");

致:

System.setProperty("webdriver.chrome.driver","C:\\Automation\\Webdrivers\\chromedriver.exe");
only ^^^driver^^^

关于java - Cucumber 在 @before hook 期间失败 : NoClassDefFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54072213/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com