I am automating a web application with Selenium/Java/TestNG. The application has data in the main page and is being read from excel sheet by @dataProvider. Based on some criteria in the main page,I want to get data from other sheets in the same excel file and pass it into corresponding @test in the same class. Tried many options but not able to find a proper solution.
Thanks much in advance, Resh
Here's one way in which this can be done.
You basically inject the "sheet" name of your excel spreadsheet into the current
<test>
tag's context viz.,ITestContext
as an attribute and then from within the@DataProvider
annotated data provider, you basically read this attribute to decide which sheet has to be read.The below sample demonstrates two
@Test
methods doing this, wherein the first@Test
method injects this attribute as part of it doing a flow and the second@Test
method (it would have to depend on the first one) which is now powered by a dynamic data provider just consumes the data.Just an approach, you can try to copy or move particular sheet in to your excel sheet , more specifically in to your workbook.