如何使用Capabilities接口使用Arquillian配置WebDriver

时间:2012-08-20 00:01:20

标签: webdriver jboss-arquillian

我想使用Arquillian的Drone扩展来为一些功能测试配置WebDriver,使用Capabilities接口,如here所述。我在我的pom中添加了工件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 extract:

<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;   

} 

1 个答案:

答案 0 :(得分:2)

这是由Maven pom.xml中的依赖项声明引起的版本控制问题。需要在dependencyManagement下使用导入范围声明Arquillian BOM工件。 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依赖项。