[英]maven profile can't get the site.url
使用 Maven 和 TestNG 處理 java 項目。 嘗試將環境變量放入 maven 配置文件並使用 mvn clean install -Pdevhost 調用它們
問題是瀏覽器無法獲取siteurl。 錯誤:
java.lang.NullPointerException: null value in entry: url=null
Pom文件配置文件:
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
<configuration>
<suiteXmlFiles>
<file>${project.basedir}/suites/smoke.xml</file>
</suiteXmlFiles>
<systemPropertyVariables>
<environment.properties>/environment.properties</environment.properties>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
<testResources>
<testResource>
<directory>src\test\resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
<resources>
<resource>
<directory>src\test\resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<!-- Profiles configuration -->
<profiles>
<!--Environments "mvn test -P dev3"-->
<profile>
<id>devhost</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<site.url>https://siteurl.com</site.url>
</properties>
</profile>
</profiles>
帶有屬性的文件稱為“environment.properties”文件,位於 src/test/resources 下:
site.url=${site.url}
驅動程序獲取站點 URL 的 Java 類:
public void SetUp() {
driver = new ChromeDriver();
System.setProperty("webdriver.chrome.driver",
ConfigFileReader.getDriverPath());
driver.manage().window().maximize();
driver.get(System.getProperty("site.url"));
driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
將屬性加載器添加到 java 類中。
PropertyLoader config = new PropertyLoader();
baseUrl = config.getProperty("site.url");
driver.get(baseUrl);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.