如何在2个不同的URL中运行相同的测试用例,这些URL在硒中具有相同的功能

时间:2018-12-15 07:12:13

标签: eclipse selenium testing selenium-webdriver testng

我是硒的新手,有人可以帮助我如何在具有相同功能的2个不同URL中运行相同的测试用例

1 个答案:

答案 0 :(得分:0)

两种方法。

1)从 testng文件中的 xml 传递值。

您可以参考的测试代码。

public class ParameterTest
{
    @Parameters({ "url" })
    @Test
    public void optionTest(String value) {
        System.out.println("This is: " + value);
    }
}

<suite name="Optional test Suite" verbose="1">

  <test name="Optional Test one">
<parameter name="url" value="https://xy.cm" />
    <classes>
      <class name="test.parameter.OptionalTest" />
    </classes>
  </test>

  <test name="Optional Test two">
    <parameter name="url" value="https://abc.om" />
    <classes>
      <class name="test.parameter.OptionalTest" />
    </classes>
  </test>

</suite>

2)您可以在 testng 中使用数据提供程序在测试用例中将url作为参数传递。

public class SameClassDataProvider
{
    @DataProvider(name = "url")
    public Object[][] dataProviderMethod() {
        return new Object[][] { { "https://yahoo.com" }, { "https://google.in" } };
    }

    @Test(dataProvider = "data-provider")
    public void testMethod(String url) {
       //write your test case
 }
}

希望这对您有所帮助!