working with java project with Maven and TestNG. Trying to put environment variables into maven profiles and call them on with mvn clean install -Pdevhost
The problen is that browser can't get a siteurl. Error:
java.lang.NullPointerException: null value in entry: url=null
Pom file profiles:
<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>
The file with properties called as "environment.properties" file and is located under src/test/resources:
site.url=${site.url}
Java class where driver gets the siteurl:
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);
Added property loader into java class.
PropertyLoader config = new PropertyLoader();
baseUrl = config.getProperty("site.url");
driver.get(baseUrl);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.