I'm using Selenium WebDriver, Eclipse, TestNG and Surefire plugin. I am not able to run testng.xml file from pom.xml. While I'm running pom.xml using mvn test it directly run the file which is in the src/test/java.
You should change suiteXmlFile from a class to a File instead for example testng.xml file which is located in src/test/resources. Furthermore update the surefire-plugin (current version 2.12). One other thing is that selenium tests are usually integration tests and not unit tests.
Update You have to add the testng dependency instead the junit dependency. So remove the junit dependency and add the testng dependency accordingly to the documentation of the maven-surefire-plugin.
回答3:
You can run maven test invoking testng.xml from command line directly via
mvn test -Dsurefire.suiteXmlFiles=src/test/resources/testng.xml
回答4:
I think there is basic Mistakes here.. pom.xml = package definition which is maintained by Maven
and testing.xml(any xml user may define) is used for TestNG test definition. Either you use the xml configuration of you can make own configuration from custom run settings for running Test NG And, your provided configuration in xml file (test name, listener class name, suite name or class name) should me match to your test class. Like you have decleared class name = TestScripts.SamplePage but your test class = sample , so this xml will never Run your test class. Small example : it is in my testing xml and my test class will be TestA.
回答5:
you can give direct testng.xml instead of src/test/resources/testng.xml
My POM.xml is working fine. Replace it with your POM.xml . Update your maven and run again. Best of luck :)