简体   繁体   中英

Why My “Suit result” is showing the 1st test data twice?

Hello I am new to StackOverflow as a registered user, Actually I have written some code with data provider just for learning purposes. But when execute it through testNg.xml, the 1st test shows the result twice as

 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]="tester1sel@yahoo.com";
    data[0][1]="Confidential";
    data[0][2]="Confidential";

    data[1][0]="tester2sel@yahoo.com";
    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]="kasif135@yahoo.com";
    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=======================

Suite Result

I don't know what is going on, I have tried updating testng dependency and also updated the testNG library but still couldn't resolve this issue, even if I swap the test order in testNG.xml then the 2nd test result is shown twice.

Change getData lines in Test Case1:

Object[][] data= new Object[1][3];
data[0][0]="kasif135@yahoo.com";
data[0][1]="Confidential";
data[0][2]="chrome";
return data;

This way you will reture 1 object only, not 2.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM