dimanche 10 janvier 2021

Facing issue while using @Factory and @dataprovider in Testng

1. Could you please help me, looks like @factory, @dataProvider and @dependsOn not working properly, here i have two inputs Client A and Client B but i am only able to get only Client B not able to get the Client A, looks like few methods are unreachable while executing, really need help, How to handle this kind of issue

Below is my testNg.xml

    <!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Suite1" group-by-instances="true" verbose="1">
<parameter name="suit-param" value="This is at suite level"></parameter>
    <test name="Test1">
        <classes>
            <class name="com.brcc.tool.Rm_Saa.RmUi"/>
        </classes>
    </test>
</suite>

Below Is my testNg code

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.io.FileWriter;
import java.time.Duration;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.Wait;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Factory;
import org.testng.annotations.Test;
import com.brcc.tool.Configuration.DriverConfig;
import com.brcc.tool.Configuration.SftpConn;


public class RmUi extends DriverConfig {
    WebDriverWait wait;
    public static SftpConn sftpCon = new SftpConn();
    public Select select;
    public String matchingFields;
    public List<String> allSearchFieldsFromExcel;
    public List<String> allDisplayFieldsFromExcel;
    public String nonMatchingFields;
    public List<String> listOfNonMatchingFields;
    public List<String> listOfNonMatchFields = new ArrayList<String>();
    public List<String> nonMatchingList = new ArrayList<String>();
    public List<String> notificationUrProduct;
    public String notificationOrgName;
    public List<String> notificationEmail;
    private String data;
    //public int j = 1;
    
    
    @BeforeSuite
    public void beforeClass() throws Exception{
        
        System.out.println("Before Test case");
        wait = new WebDriverWait(driver,60);
        sftpCon.writeIntoExcel("Result", "login", "Failed - wrong credential");
        WebElement userName = wait
                .until(ExpectedConditions.visibilityOfElementLocated(By.name(prop.getProperty("userNameByname"))));
        userName.sendKeys(prop.getProperty("username"));
        // find password and set
        WebElement password = wait
                .until(ExpectedConditions.visibilityOfElementLocated(By.name(prop.getProperty("passwordByname"))));
        password.sendKeys(prop.getProperty("password"));

        WebElement login = driver.findElement(By.xpath(prop.getProperty("login")));
        login.click();
        System.out.println("login end");

        WebElement app = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(prop.getProperty("rmApp"))));
        app.click();
    }
     @DataProvider
        public static Iterator<Object[]> getTestData() throws Exception {
          ArrayList<Object[]> getclientProduct = new ArrayList<Object[]>();
          Object[] obj1 = {"Client A"};
          Object[] obj2 = {"Client B"};
          getclientProduct.add(obj1);
          getclientProduct.add(obj2);
        return getclientProduct.iterator();
            
            
        
        }
        
        @Factory(dataProvider = "getTestData")
        public  RmUi(String s) {
            
            this.data = s;
            
            
            
        }


    @Test(priority = 1)
    public void getTest() throws Exception {
       System.out.println("login");
       System.out.println("Client in Login = "+data);
        
        
        // Next Test case later create a new test case and put below code
    }
    @Test(priority = 2,dependsOnMethods="getTest")
    public void getRmApp() throws Exception {
        System.out.println("getRmApp = "+data);
        wait = new WebDriverWait(driver, 10);
        //System.out.println("getRmApp Start");
        sftpCon.writeIntoExcel("Result", "login", "Passed");
        ArrayList<Object[]> getClient = sftpCon.clientProduct("Client Type");
        //String getClient = sftpCon.clientProduct("Client Type");
        System.out.println("getClient "+getClient);
        sftpCon.writeIntoExcel("Result", "startRmApp", "Passed");
        System.out.println("getRmApp End");

    }
    
    @Test(priority = 3,dependsOnMethods="getRmApp")
    public void radioButton() throws Exception {
        
        System.out.println("radioButton ="+data);
        
    }
    @Test(priority = 4,retryAnalyzer = com.brcc.tool.RetryFailedTestCases.RetryTestCases.class,dependsOnMethods="radioButton")
    public void clickOutputbatch()
    {
        
        System.out.println("clieckOutputbatch ="+data);
    }

    
      @Test(priority = 5,dependsOnMethods="clickOutputbatch")
      public void getbatchReleaseStatus() throws Exception {
     System.out.println("getbatchReleaseStatus ="+data);
     System.out.println("_______________________________________________");
        wait = new WebDriverWait(driver,50);
        WebElement logoutdropdown = wait
                .until(ExpectedConditions.elementToBeClickable(By.xpath(prop.getProperty("logout"))));
        logoutdropdown.click();
        //driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);
        WebElement logout = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("/html/body/div/div/div[2]/ul/li[1]/div/ul/li[4]/a")));
        logout.click();
        
      
      }
     

    }

My Actual output

     Before Test case
login end
login
Client in Login = Client B
getRmApp = Client B
clientKey = [[Ljava.lang.Object;@36b6964d, [Ljava.lang.Object;@31198ceb]
getClient [[Ljava.lang.Object;@36b6964d, [Ljava.lang.Object;@31198ceb]
getRmApp End
radioButton =Client B
clieckOutputbatch =Client B
getbatchReleaseStatus =Client B
_______________________________________________
login
Client in Login = Client A
getRmApp = Client A

My Expected output

 Before Test case
login end
login
Client in Login = Client B
getRmApp = Client B
clientKey = [[Ljava.lang.Object;@36b6964d, [Ljava.lang.Object;@31198ceb]
getClient [[Ljava.lang.Object;@36b6964d, [Ljava.lang.Object;@31198ceb]
getRmApp End
radioButton =Client B
clieckOutputbatch =Client B
getbatchReleaseStatus =Client B
_______________________________________________
login
Client in Login = Client A
getRmApp = Client A
clientKey = [[Ljava.lang.Object;@36b6964d, [Ljava.lang.Object;@31198ceb]
getClient [[Ljava.lang.Object;@36b6964d, [Ljava.lang.Object;@31198ceb]
getRmApp End
radioButton =Client A
clieckOutputbatch =Client A
getbatchReleaseStatus =Client A

Aucun commentaire:

Enregistrer un commentaire