【问题标题】:Selenium tests running twice using Serenity使用 Serenity 运行两次 Selenium 测试
【发布时间】:2015-09-18 09:13:35
【问题描述】:

我正在使用 Maven clean/verify 运行一些测试。我的报告是在宁静中。但是,在构建成功之前,我的测试似乎运行了两次 Serenity 只显示一个测试(这很好)有人可以检查代码并查看导致它的原因,因为我已经尝试了一些事情,比如取出后集成测试等但它仍然运行两次相同的测试。

POM 文件

    `<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>
  <groupId>website.SurveyManager</groupId>
  <artifactId>GeneralTests</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>GeneralTests</name>
  <description>General Tests for Survey Manager</description>

  <properties>

    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <junit.version>4.12</junit.version>

  </properties>


    <dependencies>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.47.1</version>
        </dependency>


<dependency>
    <groupId>net.serenity-bdd</groupId>
    <artifactId>serenity-core</artifactId>
    <version>1.1.12</version>
</dependency>


        <dependency>
            <groupId>net.serenity-bdd</groupId>     
            <artifactId>serenity-junit</artifactId>
            <version>1.1.12</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.18.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                <includes>
                    <include>**/*Test.java</include>
                    <include>**/*When*.java</include>
                </includes>
                </configuration>
            </plugin>

            <plugin>
                <groupId>net.serenity-bdd.maven.plugins</groupId>       
                <artifactId>serenity-maven-plugin</artifactId>
                <version>1.1.12</version>

                <executions>
                    <execution>
                        <id>serenity-reports</id>
                        <phase>post-integration-test</phase>             
                        <goals>
                            <goal>aggregate</goal>                       
                        </goals>
                    </execution>

                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.18.1</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
          <configuration>
                <fork>true</fork>
                <executable>C:\Program Files\Java\jdk1.8.0_60\bin\javac.exe</executable>  

          </configuration>
        </plugin>
        </plugins>
    </build>

</project>

测试文件:

    package website.SurveyManager.test;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.WebDriver;

import website.SurveyManager.test.steps.SurveyManagerSteps;
import net.serenitybdd.junit.runners.SerenityRunner;
import net.thucydides.core.annotations.Managed;
import net.thucydides.core.annotations.Steps;

@RunWith (SerenityRunner.class)
public class SurveyManagerTest {

    @Managed
    WebDriver driver;

    @Steps
    SurveyManagerSteps steps;

    @Test
    public void testSurveyManagerVersion(){
        steps.gotoSurveyManager();
        steps.checkVersion();
        steps.VersionValidation("1.0.0.9");


    }

}

步骤文件:

package website.SurveyManager.test.steps;

import org.openqa.selenium.By;

import net.thucydides.core.annotations.Step;
import net.thucydides.core.steps.ScenarioSteps;
import static org.junit.Assert.*;

public class SurveyManagerSteps extends ScenarioSteps {

    @Step
    public void gotoSurveyManager(){
        getDriver().get("http://website.surveymanager.sys.networks.local/Survey/List");
    }

    @Step ()
    public void checkVersion(){
        getDriver().findElement(By.className("popupLink")).click();

    }

    @Step ()
    public void VersionValidation(String s){
        String actualValue = getDriver().findElement(By.xpath(".//*[@id='aboutSM']/div[1]/div[2]/table/tbody/tr[2]/td[2]")).getText();
        assertEquals(s, actualValue);

    }
}

【问题讨论】:

  • 您的运行配置如何?

标签: java maven selenium


【解决方案1】:

我的跑步者类看起来像: 在您的情况下,尝试使用 Webdriver 驱动程序删除 @manage 注释,因为在您的情况下没有必要

包 com.epam;

import cucumber.api.CucumberOptions;
import net.serenitybdd.cucumber.CucumberWithSerenity;
import net.thucydides.core.annotations.Feature;
import org.junit.runner.RunWith;

import static com.epam.utils.Property.*;

@RunWith(CucumberWithSerenity.class)
@CucumberOptions(
    features = {HMC,GALLERIES,ORDERS},
    tags = {"~@ignore"},
    strict = true
)
public class DefinitionTestSuite {

}

对于打开页面,您只需要使用名为 open() 的 PageObject.class 方法扩展您的页面对象,并在您的页面中设置 @DefaultUrl 注释,就像这里一样(在我的情况下,我使用了 CustomPageObject,因为我需要打开我的浏览器每次都处于最大化模式):

package com.epam.pages.frontendpages.cart;

import com.epam.utils.PageObjectCustom;
import com.epam.webElementFacadeCustomImpl.ICustomWebFacadeElement;
import net.serenitybdd.core.annotations.findby.FindBy;
import net.thucydides.core.annotations.DefaultUrl;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.interactions.Actions;

import static com.epam.utils.Property.SERV;

@DefaultUrl(SERV+"/cart")
public abstract class BaseCartPage extends PageObjectCustom {

    @FindBy(id = "voucherInput0")private ICustomWebFacadeElement voucherField;
    @FindBy(xpath = "//h2[@id='voucher_link']//span[@class='draw_header_text']")private ICustomWebFacadeElement voucherBlockLink;
    @FindBy(xpath = "//*[contains(@class,'applyVoucher_container')]/input")private ICustomWebFacadeElement applyVoucherBtn;
    @FindBy(xpath = "//div[@class='col']//a[contains(@class,'checkout-btn')]")protected ICustomWebFacadeElement proceedToTheNextPage;

    public void applyVoucherCode(String voucherCode){
        if(!voucherField.isCurrentlyVisible()){
            new Actions(getDriver()).moveToElement(voucherBlockLink).click().build().perform();
        }
        voucherField.sendKeys(voucherCode);
        applyVoucherBtn.click();
    }
}

所以现在你可以用 Steps 来写了

new BaseCartPage.open()

另外请注意,您必须创建类:

YourPage extends PageObject
YourPageSteps extends ScenarioSteps
YourPageStepsDefinition 

最后一个应该有@Given等等黄瓜注解

【讨论】:

    【解决方案2】:

    编辑:

    这是运行成功

    -------------------------------------------------------
     T E S T S
    -------------------------------------------------------
    SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
    SLF4J: Defaulting to no-operation (NOP) logger implementation
    SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
    Running website.SurveyManager.test.SurveyManagerTest
    Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 15.772 sec - in website.SurveyManager.test.SurveyManagerTest
    
    Results :
    
    Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
    
    [WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent! The file encoding for reports output files should be provided by the POM property ${project.reporting.outputEncoding}.
    [INFO] 
    [INFO] --- serenity-maven-plugin:1.1.12:aggregate (serenity-reports) @ GeneralTests ---
    Merging requirements = []
    Merging requirements = []
    Merged requirements set = []
    [INFO] REPORTS GENERATED IN C:\Users\pkirby\workspace\GeneralTests\target\site\serenity
    [INFO] REPORT HOME PAGE: C:\Users\pkirby\workspace\GeneralTests\target\site\serenity\index.html
    [INFO] Generating release reports for: []
    GENERATE CUSTOM REPORTS
    [INFO] 
    [INFO] --- maven-failsafe-plugin:2.18.1:verify (default) @ GeneralTests ---
    [INFO] Failsafe report directory: C:\Users\pkirby\workspace\GeneralTests\target\failsafe-reports
    [WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent! The file encoding for reports output files should be provided by the POM property ${project.reporting.outputEncoding}.
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 42.716 s
    [INFO] Finished at: 2015-09-18T13:22:25+01:00
    [INFO] Final Memory: 31M/282M
    [INFO] ------------------------------------------------------------------------
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-18
      • 2021-09-24
      • 1970-01-01
      • 2019-04-29
      • 2018-09-07
      • 2019-04-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多