Selenium webdriver 使用选定的测试用例在TestNG中进行跨浏览器测试

Selenium webdriver 使用选定的测试用例在TestNG中进行跨浏览器测试,selenium-webdriver,testng,Selenium Webdriver,Testng,是否可以使用选定浏览器上的选定测试用例从TestNG运行跨浏览器测试?例如IE上的1-5个测试用例和chrome上的6-10个测试用例等 谢谢, 苏达卡是的,这是可能的 让我告诉你我是如何做到这一点的 在TestNG套件文件中,我将给出浏览器名称作为参数 现在在beforeTest方法中添加获取浏览器名称的代码 @BeforeTest(alwaysRun = true) public void fetchSuiteConfiguration(ITestContext testContext)

是否可以使用选定浏览器上的选定测试用例从TestNG运行跨浏览器测试?例如IE上的1-5个测试用例和chrome上的6-10个测试用例等

谢谢, 苏达卡是的,这是可能的 让我告诉你我是如何做到这一点的

  • 在TestNG套件文件中,我将给出浏览器名称作为参数

  • 现在在beforeTest方法中添加获取浏览器名称的代码

    @BeforeTest(alwaysRun = true)
    public void fetchSuiteConfiguration(ITestContext testContext) {
    targetBrowser=testContext.getCurrentXmlTest().getParameter("selenium.browser");}
    
  • 现在将浏览器初始化为before方法

    @BeforeMethod(alwaysRun = true)
    public void setUp(Method method, ITestContext testContext)  {
    
    if (targetBrowser == null || targetBrowser.contains("firefox")) {
        /*initialize firefox driver here*/
    } else if (targetBrowser.contains("ie")) {
     /*initialize ie driver here*/
    } else if (targetBrowser.contains("opera")) {
     /*initialize opera driver here*/
    } else if (targetBrowser.contains("chrome")) {
     /*initialize Chrome driver here*/
    
    
    } 
    
    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    driver.get(url);
    
    driver.manage().window().maximize();
    
    }
    

  • 你读过TestNG文档了吗?您尝试了哪些代码和配置?你有没有搞错?杰夫,这是我在采访中提出的问题。我说是的,但是当我仔细考虑后,我没有得到这样做的逻辑。Patel,根据您的代码,基于浏览器名称作为参数,代码将初始化浏览器并执行所有测试用例。我想做的是在一次执行中,TestNG应该在所有浏览器上运行,但使用不同的测试用例(选定的测试用例)。@Veskar,然后,您需要在测试标记内指定参数,如e。它将仅为特定测试获取参数值。因此,它将为您指定的测试打开不同的浏览器