【问题标题】:Selenium Webdriver Java test does not start in Jenkins. It works well from the command line (cmd)Selenium Webdriver Java 测试未在 Jenkins 中启动。它从命令行(cmd)运行良好
【发布时间】:2021-12-20 18:30:11
【问题描述】:

我了解无法从资源中获取数据。 服务中提供了与服务中的桌面交互的权限。

简单测试通过:

enter image description here


enter image description here


enter image description here

enter image description here



enter image description here

enter image description here

enter image description here


在 Jenkins 中,我爬取了参数化的装配线:

-Dbrowser=${browser} -Dsurefire.suiteXmlFiles=${surefire.suiteXmlFiles} -Denvironment=${environment} clean test

错误代码


    java.lang.ExceptionInInitializerError
at service.InstanceCreator.getDataEstimateForm(InstanceCreator.java:24)
at test.GoogleCloudTest.checkEmailEstimateCost(GoogleCloudTest.java:17)
at java.util.ArrayList.forEach(ArrayList.java:1259)
Caused by: java.lang.NullPointerException
at java.util.ResourceBundle$CacheKey.calculateHashCode(ResourceBundle.java:654)
at java.util.ResourceBundle$CacheKey.<init>(ResourceBundle.java:584)
at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1333)
at java.util.ResourceBundle.getBundle(ResourceBundle.java:782)
at service.TestDataReader.<clinit>(TestDataReader.java:6)
... 35 more

...删除了 32 个堆栈帧


读键类

public class TestDataReader {
private static final ResourceBundle resourceBundle = ResourceBundle.getBundle(System.getProperty("environment"));

public static String getTestData(String key) {
    return resourceBundle.getString(key);
}

}


服务类

public class InstanceCreator {
private static final String NUMBER_OF_INSTANCES = "testdata.instanceCreator.number";
private static final String OPERATION_SYSTEM = "testdata.instanceCreator.os";
private static final String MACHINE_CLASS = "testdata.instanceCreator.machine-class";
private static final String SERIES_ID = "testdata.instanceCreator.series-id";
private static final String MACHINE_TYPE = "testdata.instanceCreator.machine-type";
private static final String NUMBER_OF_GPUS = "testdata.instanceCreator.number-of-gpus";
private static final String TYPE_GPU = "testdata.instanceCreator.type-gpu";
private static final String LOCAL_SSD = "testdata.instanceCreator.local-ssd";
private static final String DATA_CENTER_LOCATION = "testdata.instanceCreator.datacenter";
private static final String COMMITTED_USAGE = "testdata.instanceCreator.committed-sage";

public static InstanceForm getDataEstimateForm() {
  return new InstanceForm(       
          TestDataReader.getTestData(NUMBER_OF_INSTANCES),
          TestDataReader.getTestData(OPERATION_SYSTEM),
          TestDataReader.getTestData(MACHINE_CLASS),
          TestDataReader.getTestData(SERIES_ID),
          TestDataReader.getTestData(MACHINE_TYPE),
          TestDataReader.getTestData(NUMBER_OF_GPUS),
          TestDataReader.getTestData(TYPE_GPU),
          TestDataReader.getTestData(LOCAL_SSD),
          TestDataReader.getTestData(DATA_CENTER_LOCATION),
          TestDataReader.getTestData(COMMITTED_USAGE));
  }
}

测试

公共类 GoogleCloudTest 扩展 CommonConditions {

@Test(description = "get a letter with the results of processing the request")

public void checkEmailEstimateCost() {
    new InstanceCreator();
    InstanceForm instanceForm = InstanceCreator.getDataEstimateForm();
    String verificationCalculationResultsReceivedEmail = new GoogleCloudHomePage(driver)
            .openPage()
            .fillSearchInput()
            .openCalculator()
            .activationComputeEngine()
            .fillComputeEngineForm(instanceForm)
            .pressAddToEstimate()
            .saveResultEstimate()
            .pressButtonEmailEstimate()
            .openNewTab()
            .openPage()
            .copyEmailAddress()
            .comeBackToCalculator()
            .enterEmail()
            .pressButtonSendEmail()
            .returnToPageEmail()
            .pressCheckMailButton()
            .thisComparisonResultsReceivedEmailWithDataSite();
    Assert.assertEquals(verificationCalculationResultsReceivedEmail, ProcessData.getCurrentPriceInCalculator()
            , "the data received by mail does not coincide with the data received in the calculator");
}

pom.xml

<?xml version="1.0" encoding="UTF-8"?>

4.0.0

<groupId>org.example</groupId>
<artifactId>frameworklasttask</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
    <maven.compiler.source>8</maven.compiler.source>
    <maven.compiler.target>8</maven.compiler.target>
</properties>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.13.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>7.4.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>4.0.0</version>
    </dependency>
    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest</artifactId>
        <version>2.2</version>
        <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
    <dependency>
        <groupId>io.github.bonigarcia</groupId>
        <artifactId>webdrivermanager</artifactId>
        <version>5.0.3</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>2.14.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.14.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-report-plugin</artifactId>
        <version>3.0.0-M5</version>
        <type>maven-plugin</type>
    </dependency>
    <!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.11.0</version>
    </dependency>
</dependencies>

<build>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
        <plugins>
            <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M5</version>
                <configuration>
                    <testFailureIgnore>true</testFailureIgnore>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-clean-plugin</artifactId>
                <version>3.1.0</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.2.0</version>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

【问题讨论】:

  • 您参数化的行有:-Dbrowser=$(browser),该变量需要花括号作为行的其余部分。更正为:-Dbrowser=${browser}
  • 非常感谢,已更正,但并没有解决问题。
  • 因此,从外观上看,您的 service.class 没有取回一个或多个 test.data 字符串,因此是 NPE。您是否检查过 service.class 所需的所有值都可用于您的 Jenkins 代理?
  • 非常感谢好心人!是的,您正确理解了所有内容,我没有从我的 dev.properties 中收到用于处理密钥的数据,该数据位于“private static final ResourceBundle resourceBundle = ResourceBundle.getBundle (System.getProperty (" environment "));”行中我在我的问题中添加了 Jenkins 皮肤照片。请救救我,否则我快要发疯了:-)
  • P.S.将完整路径“src/test/resources/dev.properties”添加到“environment”参数没有产生任何结果

标签: java selenium jenkins testing webdriver


【解决方案1】:

从上面的屏幕截图中,您需要更正以下内容:

'在其他项目上触发/调用构建'部分

  • 子项目部分中的文件名mvn test -P -Dbrowser=${browser} -Dsurefire.suiteXmlFiles=${surefire.suiteXmlFiles} -Denvironment=${environment} clean test - 删除它,因为此部分是在主项目“frameworklasttask”的子项目中声明文件,而不是 maven 命令

现在在下一部分,您已经声明了 maven 版本“3.8.1”

  • clean test 更新为clean test -Dbrowser=${browser} -Dsurefire.suiteXmlFiles=${surefire.suiteXmlFiles} -Denvironment=${environment}.properties

目前,我已经放弃了 maven 命令的 -P 部分,因为您目前提供的配置中缺少一个标记。

【讨论】:

  • 感谢您的帮助!抱歉,它不起作用。
  • 我已经用 Jenkins 填充和构建结果完成了前 2 个图像。 (你能告诉我在这种情况下哪种绳子和哪种肥皂最适合我:-))
  • 上面更新了 mvn cmd 的答案以更改为 -Denvironment=${environment}.properties,让我们看看你的进展情况
  • 谢谢你没有离开我!!!添加 -Denvironment = $ {environment} .properties 并没有帮助获得相同的结果。现在我正在尝试像“youtube.com/…”那样做,但到目前为止还没有结果:-(
  • 非常感谢您愿意帮助我!!!我找到了解决方案,它花了我 4 天的时间! :-) 解决方案如下所示!!!如需帮助,请联系!无论如何,你的业力是巨大的!
【解决方案2】:

我只找到了这样的解决方案。此项目构建配置中的其他任何内容都不起作用!经过 4 天的搜索证明!


enter image description here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-11
    相关资源
    最近更新 更多