简体   繁体   English

Maven不从test.xml读取参数

[英]Maven don't read parameters from test.xml

I have some strange situation (for me ofcourse). 我有一些奇怪的情况(当然对我来说)。 I try to run framework, based on Java+TestNG+WebDriver+Maven. 我尝试运行基于Java + TestNG + WebDriver + Maven的框架。 Here is piece of TestBase code: 这是一段TestBase代码:

@BeforeClass
@Parameters({ "browser", "version",
        "platform" })
public void setUp(@Optional String browser, @Optional String version, @Optional String platform)
        throws Exception {
    DesiredCapabilities capability = new DesiredCapabilities();
    capability.setCapability("platform", platform);
    capability.setCapability("browserName", browser);
    capability.setCapability("browserVersion", version);

    webDriver2 = new RemoteWebDriver(new URL(
                    "http://127.0.0.1:4444/wd/hub"),
            capability);

test.xml: test.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite thread-count="2" name="Suite" parallel="tests">
   <test name="FireFox_MAC">
      <parameter name="browser" value="firefox" />
      <parameter name="version" value="41.0.2" />
      <parameter name="platform" value="MAC" />
      <classes>
        <class name="com.testcases.AccountSuit" />
      </classes>
  </test> 
  <test name="Chrome_WIN7">
     <parameter name="browser" value="chrome" />
     <parameter name="version" value="42" />
     <parameter name="platform" value="WINDOWS" />
     <classes>
        <class name="com.testcases.AccountSuit" />
     </classes>
  </test>
</suite>

The problem is next: when i try to run tests via IDE Eclipse pom.xml->Run As...->Maven test. 接下来的问题是:当我尝试通过IDE Eclipse pom.xml-> Run As ...-> Maven测试运行测试时。 all works fine. 一切正常。 Maven runs two tests in parallel. Maven并行运行两个测试。 One on FF, second on chrome. 一在FF上,第二在镀铬上。 test.xml->Run As...->TestNG too. test.xml-> Run As ...-> TestNG也是如此。 But when i try to run tests via console, using command "mvn test -Dtest=com.testcases.AccountSuit" i've got in log "can't create a new driver instance for Capabilities [{browserVersion=null, browserName=null, platform=null}]" It necessary for me to start tests with command, because i need to start them via Jenkins automatically. 但是,当我尝试通过控制台使用命令“ mvn test -Dtest = com.testcases.AccountSuit”运行测试时,我在日志中“无法为Capabilities [{browserVersion = null,browserName = null ,platform = null}]“对于我来说,必须使用命令启动测试,因为我需要通过Jenkins自动启动它们。 I'm very confused( Help please. PS maven-surefire-plugin version 2.18 我很困惑(请帮助。PS maven-surefire-plugin版本2.18

When you are running with -Dtest only a single test is being run and the parameters that you defined in your xml are not being used. 使用-Dtest运行时,仅运行单个测试,并且不使用您在xml中定义的参数。 You need to either give -DsuiteXml to mvn test and specify your xml 您需要给-DsuiteXml进行mvn测试并指定xml

or 要么

define default data for browserversion, name and platform, since you have those as optional parameters. 定义浏览器版本,名称和平台的默认数据,因为您将这些数据作为可选参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法通过Java Selenium中的Maven和命令行运行test.xml文件 - Not able to run test.xml file through maven and command line in java selenium 如何使用此路径读取 xml 字符串值,如代码所示(getFilesDir().getAbsolutePath()+ File.separator + “test.xml”) - How to read xml string values using this path as shown in code(getFilesDir().getAbsolutePath()+ File.separator + “test.xml”) 休眠不从ehcache.xml读取,还是没有超时? - hibernate don't read from ehcache.xml OR not timeout? maven测试不运行测试 - maven test don't run tests Maven无法阅读我的黄瓜测试 - Maven can't read my Cucumber Test 不要通过xstream读取XML中元素的值 - don't read value of element in XML by xstream Maven验证程序集成测试未找到被测工件 - Maven verifier intergration tests don't find artifact under test 如何防止Maven检查我未在settings.xml文件中列出的存储库中的更新? - How can I prevent Maven from checking for updates from repositories that I don't list in my settings.xml file? 当更新项目时我的eclipse java构建路径源类别中不希望src / test / java存在时,如何配置maven pom.xml? - How to config maven pom.xml when my don't want src/test/java present in my eclipse java build path source category when update project? 不要在JLabel中使用XML文件读取&#39;&lt;&#39; - Don't read '&lt;' with XML-file in JLabel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM