java - How to read values from multiple excel sheets using DataProvider and pass it to multiple @test? -


i automating web application selenium/java/testng. application has data in main page , being read excel sheet @dataprovider. based on criteria in main page,i want data other sheets in same excel file , pass corresponding @test in same class. tried many options not able find proper solution.

thanks in advance, resh

here's 1 way in can done.

you inject "sheet" name of excel spreadsheet current <test> tag's context viz., itestcontext attribute , within @dataprovider annotated data provider, read attribute decide sheet has read.

the below sample demonstrates 2 @test methods doing this, wherein first @test method injects attribute part of doing flow , second @test method (it have depend on first one) powered dynamic data provider consumes data.

import org.testng.itestcontext; import org.testng.reporter; import org.testng.annotations.dataprovider; import org.testng.annotations.test;  public class sampletestclass {     /**      * method simulating master test method interact      * web app , bring application state wherein next test method      * should take on , interact.      */     @test     public void testlogin() {         //simulating toggling between multiple flows.         int whichflow = integer.parseint(system.getproperty("flow", "1"));         reporter.getcurrenttestresult().gettestcontext().setattribute("flow", whichflow);     }      /**      * method intentionally dependent on "testlogin" because "testlogin"      * first interact web application , bring application place      * further interaction required, vary based on "x" criteria      * "x" criteria available attribute in current &lt;test&gt; tag's      * context.      */     @test(dependsonmethods = "testlogin", dataprovider = "getdata")     public void testsomethingelse(int a, string b) {         //real test method logic goes here.         system.out.println(a + ":" + b);      }      @dataprovider     public object[][] getdata(itestcontext context) {         int whichflow = integer.parseint(context.getattribute("flow").tostring());         switch (whichflow) {             case 1:                 return new object[][]{                         {1, "login"},                         {2, "signup"}                 };             case 2:                 return new object[][]{                         {100, "fees"},                         {200, "charges"}                 };              case 3:             default:                 return new object[][]{                         {900, "logout"},                         {1000, "random"}                 };          }     } } 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -