为什么我的“ Suit结果”两次显示第一个测试数据?

问题描述 投票:0回答:1

[您好,我作为注册用户不熟悉StackOverflow,实际上我已经为学习目的而与数据提供者一起编写了一些代码。但是当通过testNg.xml执行它时,第一个测试将结果两次显示为

 package com.qa.zoho.rough;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class TestCase1 {

    WebDriver driver;

    @Test(dataProvider="getdata")
    public void doLogin(String username, String password,String browser) throws InterruptedException {

     if(browser.equals("chrome")) {

    System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir")+"\\src\\test\\resources\\executables\\chromedriver.exe");
     driver= new ChromeDriver();
     }
     else if (browser.equals("firefox")){

    System.setProperty("webdriver.gecko.driver", System.getProperty("user.dir")+"\\src\\test\\resources\\executables\\geckodriver.exe");
     driver= new FirefoxDriver(); 

     }

    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    driver.get("https://www.zoho.com");

    driver.findElement(By.xpath("//a[@class='zh-login']")).click();
    driver.findElement(By.id("lid")).sendKeys(username);
    driver.findElement(By.id("pwd")).sendKeys(password);
    driver.findElement(By.id("signin_submit")).click();
    Thread.sleep(3000);

    driver.quit();

    }

@DataProvider
 public Object[][] getdata(){

    Object[][] data= new Object[2][3];
    data[0][0]="[email protected]";
    data[0][1]="Confidential";
    data[0][2]="Confidential";

    data[1][0]="[email protected]";
    data[1][1]="Confidential";
    data[1][2]="firefox";

    return data;


    }
    }



  package com.qa.zoho.rough;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class TestCase2 {

    WebDriver driver;

    @Test(dataProvider="getdata")
    public void doLogin(String username, String password,String browser) throws InterruptedException {

     if(browser.equals("chrome")) {

    System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir")+"\\src\\test\\resources\\executables\\chromedriver.exe");
     driver= new ChromeDriver();
     }
     else if (browser.equals("firefox")){

    System.setProperty("webdriver.gecko.driver", System.getProperty("user.dir")+"\\src\\test\\resources\\executables\\geckodriver.exe");
     driver= new FirefoxDriver(); 

     }

    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    driver.get("https://www.zoho.com");

    driver.findElement(By.xpath("//a[@class='zh-login']")).click();
    driver.findElement(By.id("lid")).sendKeys(username);
    driver.findElement(By.id("pwd")).sendKeys(password);
    driver.findElement(By.id("signin_submit")).click();
    Thread.sleep(3000);

    driver.quit();

    }

@DataProvider
 public Object[][] getdata(){

    Object[][] data= new Object[1][3];
    data[0][0]="[email protected]";
    data[0][1]="Confidential";
    data[0][2]="chrome";



    return data;


    }


}


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
  <test name="TestChrome">
    <classes>

      <class name="com.qa.zoho.rough.TestCase1"/>
    </classes>
  </test>

  <test name="TestFirefox">
    <classes>
      <class name="com.qa.zoho.rough.TestCase2"/>

    </classes>
  </test> 

</suite> 

================套房结果========================>

Suite Result

我不知道发生了什么,我尝试过更新testng依赖关系,也更新了testNG库,但是仍然无法解决此问题,即使我在testNG.xml中交换了测试顺序,第二个测试结果也是显示两次。

[您好,我作为注册用户不熟悉StackOverflow,实际上我已经为学习目的而与数据提供者一起编写了一些代码。但是当通过testNg.xml执行它时,第一个测试显示...

java selenium testng
1个回答
0
投票

更改测试用例1中的getData行:

© www.soinside.com 2019 - 2024. All rights reserved.