英文:
How to declare user defined properties in pom.xml file
问题
我正在使用Maven项目进行UI自动化测试,并需要在多个环境和多个浏览器中运行一些测试。
我已经创建了pom.xml文件并在其中声明了属性。但是当我通过终端执行时,出现了错误。
我使用的命令是-
mvn clean
mvn test -Denvironment=test -Dbrowser=chrome
我的XML文件-
<?xml version="1.0" encoding="UTF-8"?>
<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>org.example</groupId>
<artifactId>ui-automation-projects</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<property>
<environment>${environment}</environment>
</property>
<property>
<browser>${browser}</browser>
</property>
</properties>
<dependencies> </dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</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>3.0.0-M4</version>
</plugin>
</plugins>
</build>
错误信息-
[INFO] 正在扫描项目...
[ERROR] [ERROR] 处理POM文件时出现一些问题:
[FATAL] 无法解析的POM D:\work\Cucumber_Projects\ui-automation-projects\pom.xml:TEXT必须紧接着END_TAG而不是START_TAG(位置:START_TAG seen ...
13, column 26
英文:
I am using maven project for UI automation and I need to run some tests in multiple environment and multiple browsers.
I have created added the pom.xml file and declared the properties in it. But when i execute it through the terminal i get errors.
command i used-
mvn clean
mvn test -Denvironment=test -Dbrowser=chrome
My Xml file-
<?xml version="1.0" encoding="UTF-8"?>
<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>org.example</groupId>
<artifactId>ui-automation-projects</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<property>
<environment>${environment}</environment>
</property>
<property>
<browser>${browser}</browser>>
</property>
</properties>
<dependencies> </dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</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>3.0.0-M4</version>
</plugin>
</plugins>
</build>
Error-
[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-parseable POM D:\work\Cucumber_Projects\ui-automation-projects\pom.xml: TEXT must be immediately followed by END_TAG and not START_TAG (position: START_TAG seen ...<property>\n <environment>... @13:26) @ line
13, column 26
答案1
得分: 1
在pom.xml中声明项目属性如下:
<properties>
<environment>默认环境值</environment>
<browser>默认浏览器值</browser>
</properties>
您可以在POM参考文档中了解更多信息。
英文:
Project properties in pom.xml are declared like this:
<properties>
<environment>default-environemnt-value</environment>
<browser>default-browser-value</browser>>
</properties>
You can read more in POM reference
答案2
得分: 1
你必须删除<property>
并在<properties>
下添加你的属性。
<environment>${environment}</environment>
<browser>${browser}</browser>
</properties>
另外,在</browser>
后面多了一个'>'
英文:
You must delete <property>
and add your property under <properties>
.
<properties>
<environment>${environment}</environment>
<browser>${browser}</browser>
</properties>
Also, you have an extra '>' after </browser>
答案3
得分: -1
你在解析 pom.xml 文件时出现了错误,我在我的 Idea 中检查并进行了修正。你缺少了 </project>
标签,而 <dependencies> </dependencies>
是多余的。此外,应该有以下答案:
<properties>
<environment>${envValue}</environment>
<browser>${browserValue}</browser>
</properties>
在添加这些内容后,文件将能够正确构建。
<?xml version="1.0" encoding="UTF-8"?>
<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>org.example</groupId>
<artifactId>ui-automation-projects</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<environment>${envValue}</environment>
<browser>${browserValue}</browser>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</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>3.0.0-M4</version>
</plugin>
</plugins>
</build>
</project>
这样文件就能正确构建了。
英文:
You have error during the parson pom.xml file I checked it into my Idea and corrected. You didn't have </project>
tag and <dependencies> </dependencies>
were redundant. Also there should be answer
<properties>
<environment>${envValue}</environment>
<browser>${browserValue}</browser>
</properties>
After this the file builds correctly.
<?xml version="1.0" encoding="UTF-8"?>
<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>org.example</groupId>
<artifactId>ui-automation-projects</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<environment>${envValue}</environment>
<browser>${browserValue}</browser>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</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>3.0.0-M4</version>
</plugin>
</plugins>
</build>
</project>
答案4
得分: -3
我看到了你的POM几次,也看到了我的本地POM,我是如何定义我的依赖关系和POM的。
我发现了两件事情:
- 你已经在属性中定义了可以直接添加值的属性(在你的情况下是environment和Browser),否则可以单独定义如下:
${environment} - 我没有在POM中看到项目的结束标记。尝试添加它,应该可以正常工作。
英文:
I have seen u r POM couple of ties and have seen my local pom how I have defined my dependencies and POM
I found 2 things
- You have defined the properties already in which u can directly add the value
(Here in your case it is environment and Browser)
else define alone as follows in properties
${environment} - I haven't seen end for the Project in the POM.
Try adding that and that should work.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论