【发布时间】:2019-06-01 23:44:54
【问题描述】:
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 {
}
Sample.feature
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)
【问题讨论】:
-
您似乎缺少 apache commons 集合库。您可以尝试将其添加到您的构建中。
-
您可以从mvnrepository.com/artifact/commons-collections/… 获取库,将其添加到您的构建中,具体取决于您使用的内容(maven、gradle 等)
-
@CalvinIyer 我已经下载了 commons-collections4-4.2 jar 并添加到 java 构建路径。它仍然无法正常工作。还有其他建议吗?
-
您需要
commons-collection而不是commons-collection4库,因为上面的错误。 -
@CalvinIyer 等等.. 我还会下载 commons-collection jar 文件来添加到 java 构建路径吗?
标签: java selenium automation cucumber chrome-web-driver