【问题标题】:Cross browser and test suite with testng使用 testng 跨浏览器和测试套件
【发布时间】:2016-04-16 17:53:39
【问题描述】:

我想在一个浏览器中执行我所有的测试用例(我正在使用 testng 和 maven 来执行测试用例)我实现了@BeforeSuite@AfterSuite 一切都可以,但问题是当我想添加我的 testng.xml 的一个参数“浏览器”错误是:

@Configuration 在方法 testBeforeSuite 上需要参数“浏览器”,但尚未标记为 @Optional 或已定义 在 F:\workspace\my-app\browser.xml

我有下一个testng.xml

我只希望参数browser 仅适用于TestConfig,而不适用于其他测试用例 我试图修改我的 testng.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
  <test name="Test">
  <parameter name="browser" value="firefox"/>
    <classes>
      <class name="com.mycompany.app.TestConfig"/>
    </classes>
  </test> 

  <test name="Test2">
    <classes>
      <class name="com.mycompany.app.TestOrder"/>
      <class name="com.mycompany.app.TestDatabase"/>
    </classes>
  </test> 
</suite> 

但显示相同的错误。 我在 testng 中寻找排除参数,但我没有找到任何东西 有没有办法只为一个测试用例使用参数浏览器运行一套测试用例? (仅用于配置)

【问题讨论】:

  • 为你的 beforesuite 输入代码

标签: java maven selenium automation testng


【解决方案1】:

根据信息猜测,我会说您的testBeforeSuite 方法需要浏览器参数。 您是否尝试将参数应用于套件而不是测试?

【讨论】:

    【解决方案2】:

    Hi this is kumar.
    You have declared the parameters in the testng.xml 
    but u should read the parameter name and vaue in testng file.
     In testng file u have to use the @parameters annotatin .following code expalins
    
    
      public class Test
        {
          @parameters(browser)
          @Test
          public void runTest(string value)
            {
             WebDriver driver;
              if(value.equals("firefox"))
                {
                 driver= new FirefoxDriver();
                 }
           }
       }  

    【讨论】:

      猜你喜欢
      • 2020-02-26
      • 1970-01-01
      • 1970-01-01
      • 2017-12-14
      • 2019-02-18
      • 2015-11-03
      • 2012-05-17
      • 2020-01-14
      • 1970-01-01
      相关资源
      最近更新 更多