小编Nic*_*ier的帖子

Cucumber + Selenium Java:在测试用例之间保持浏览器打开

我目前正在使用Java中的Cucumber和Selenium WebDriver来测试Web应用程序.我对浏览器关闭并在每个测试用例之间重新打开这一事实感到不满意.

首先,它很慢,而且对我来说没有意义.

我想要做的是在每次测试之间注销应用程序并保持浏览器打开.

我认为这条线可以完成工作,但它不能按预期工作:

driver.navigate().to("http://myurl.url");
Run Code Online (Sandbox Code Playgroud)

代替 :

driver.get("http://myurl.url");
Run Code Online (Sandbox Code Playgroud)

它会打开一个新的浏览器.我理解为什么会这样做,但我想附加到我之前的浏览器会话中.

java selenium

4
推荐指数
1
解决办法
5967
查看次数

项目无法识别黄瓜-picocontainer依赖性

我目前正在使用Cucumber,JUnit和Selenium开发Java测试框架。我已经从事过类似的项目,但是在这个项目上遇到了问题。

我正在尝试创建一个Singleton的Context类。我想使用Cucumber-picocontainer在每个步骤定义类中都可以访问此类。我在pom.xml中添加了依赖项,但是每次尝试执行测试时,都会有一个异常消息:“ NewLoginSteps没有空的构造函数。如果您需要DI,则在类路径上放置cumul-picocontainer” 。我尝试手动导入罐子,但没有帮助。

这是我的配置示例:

  • pom.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
    
        <properties>
            <cucumber.version>1.2.4</cucumber.version>
            <selenium-java.version>2.39.0</selenium-java.version>
        </properties>
        <dependencies>
            <dependency>
                <groupId>info.cukes</groupId>
                <artifactId>cucumber-java</artifactId>
                <version>${cucumber.version}</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>info.cukes</groupId>
                <artifactId>cucumber-picocontainer</artifactId>
                <version>${cucumber.version}</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>info.cukes</groupId>
                <artifactId>cucumber-junit</artifactId>
                <version>${cucumber.version}</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.11</version>
                <scope>test</scope>
            </dependency>
    </project>
    
    Run Code Online (Sandbox Code Playgroud)

TestContext.java:

public class TestContext {
    private static Map<String, String> siteLocations = new HashMap<String, String>();
    private static boolean initialized = false;
    private static boolean firstInitDone = false;
    private static WebDriver driver;
    private static boolean testsToRun = …
Run Code Online (Sandbox Code Playgroud)

java selenium cucumber picocontainer maven

4
推荐指数
1
解决办法
7195
查看次数

标签 统计

java ×2

selenium ×2

cucumber ×1

maven ×1

picocontainer ×1