【发布时间】:2021-12-20 18:30:11
【问题描述】:
我了解无法从资源中获取数据。 服务中提供了与服务中的桌面交互的权限。
简单测试通过:
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