1

我想使用 Arquillian 的 Drone 扩展来为一些功能测试配置 WebDriver,使用这里描述的 Capabilities 接口。我在我的 pom.xml 文件中添加了 arquillian-bom(版本 1.0.2.Final)、arquillian-drone-bom(版本 1.1.0.CR2)、arquillian-drone-webdriver-depchain 和 arquillian-drone-webdriver 作为依赖项。 xml,如下所示,并声明了如图所示的功能,但是当我运行测试时,抛出以下异常:

java.lang.NullPointerException
at org.openqa.selenium.remote.DesiredCapabilities.<init>(DesiredCapabilities.java:51)
at org.jboss.arquillian.drone.webdriver.configuration.TypedWebDriverConfiguration$5.invoke(TypedWebDriverConfiguration.java:268)
at org.jboss.arquillian.drone.webdriver.configuration.TypedWebDriverConfiguration$5.invoke(TypedWebDriverConfiguration.java:259)
at org.jboss.arquillian.drone.webdriver.configuration.TypedWebDriverConfiguration$CallInterceptor.intercept(TypedWebDriverConfiguration.java:65)
at org.jboss.arquillian.drone.webdriver.configuration.TypedWebDriverConfiguration.getCapabilities(TypedWebDriverConfiguration.java:274)
at org.jboss.arquillian.drone.webdriver.factory.FirefoxDriverFactory.createInstance(FirefoxDriverFactory.java:79)
at org.jboss.arquillian.drone.webdriver.factory.FirefoxDriverFactory.createInstance(FirefoxDriverFactory.java:42)
at org.jboss.arquillian.drone.webdriver.factory.WebDriverFactory.createInstance(WebDriverFactory.java:129)
at org.jboss.arquillian.drone.webdriver.factory.WebDriverFactory.createInstance(WebDriverFactory.java:43)
at org.jboss.arquillian.drone.impl.DroneCreator.createWebTestBrowser(DroneCreator.java:71)
etc.

查看代码,我可以看到这个 NPE 是由未初始化的 TypedWebDriverConfiguration 中的类变量 CapabilityMap 引起的。

我需要在配置中修复什么才能使其正常工作?

pom.xml 提取:

<project>
    <dependencies>
        <dependency>
            <groupId>org.jboss.arquillian</groupId>
            <artifactId>arquillian-bom</artifactId>
            <version>${arquillian.version}</version>
            <type>pom</type>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.arquillian.extension</groupId>
            <artifactId>arquillian-drone-bom</artifactId>
            <version>${drone.version}</version>
            <type>pom</type>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.arquillian.extension</groupId>
            <artifactId>arquillian-drone-webdriver</artifactId>
            <version>${drone.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.arquillian.extension</groupId>
            <artifactId>arquillian-drone-webdriver-depchain</artifactId>
            <version>${drone.version}</version>
            <type>pom</type>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

arquillian.xml:

<arquillian xmlns="http://jboss.org/schema/arquillian"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://jboss.org/schema/arquillian
        http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
    <extension qualifier="webdriver">
        <property name="browserCapabilities">firefox</property>
        <property name="capabilityWebdriverFirefoxBin">/usr/bin/firefox</property>
    </extension>
</arquillian>

代码中的 WebDriver 声明:

@RunWith(Arquillian.class)
public class WebDriverTest {

    @Deployment
    public static WebArchive createDeployment() {
        ...
    }

    @Drone
    WebDriver driver;   

} 
4

1 回答 1

2

这是由 Maven pom.xml 中的依赖声明引起的版本控制问题。Arquillian BOM 工件需要在dependencyManagement 下声明,具有导入范围。pom.xml 依赖声明应如下所示:

<project>
    <dependencies>
        <dependency>
            <groupId>org.jboss.arquillian.extension</groupId>
            <artifactId>arquillian-drone-webdriver-depchain</artifactId>
            <version>${drone.version}</version>
            <type>pom</type>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.jboss.arquillian</groupId>
                <artifactId>arquillian-bom</artifactId>
                <version>${arquillian.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.jboss.arquillian.extension</groupId>
                <artifactId>arquillian-drone-bom</artifactId>
                <version>${drone.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>    
        </dependencies>
    </dependencyManagement>
</project>

请注意,不再需要 arquillian-drone-webdriver 依赖项。

于 2012-08-20T08:02:16.700 回答