0

I have my TesTng class with 3 test (A,B, C) and this class extends base class which has @beforemethod and @ aftermethod

Now I want to pass browser to @ before method and email to method A

Below is my sample data.enter image description here

Email has to be unique every time.

Mahen
  • 9
  • 1
  • 4

2 Answers2

0

one of the ways is to use @Parameters annotation.

Code for @BeforeMethod is-

@BeforeMethod
@Parameters("browser")
public void testMethod1(String browser) {
     //do your task here
}

Code for method A-

@Test
@Parameters("email")
public void A(String email) {
     //implement your test logic here
}

Sample TestNG Sample-

<suite name="Suite1" verbose="1" >

<test name="Test1">
  <parameter name="browser" value="firefox"/> 
  <parameter name="email" value="an-email-id"/> 
  <classes>
    <class name="packagename.ClassName"/>
  </classes>
</test>

</suite>
optimistic_creeper
  • 2,739
  • 3
  • 23
  • 37
  • thnx @optimist_creeper , I am aware of I have to use @ Parameter or @ dataprovider but how do I pass them different value and for each value on @ beforemethod how do I pass corresponding value in @ test few method need to run 3 times few 2 times – Mahen Nov 17 '16 at 15:10
  • You may use DataProvider then. – optimistic_creeper Nov 17 '16 at 15:19
0

I found a solution for my problem please le me know if more efficient way is there.. I have userd @ parameter (thanx optimist_creeper) and In testng.xml I have created different test

<?xml version="1.0" encoding="UTF-8"?>

            <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
            <suite name="Suite">
            <test name="Chrome_test">
            <parameter name="Browser" value="chrome"></parameter>
            <parameter name="email" value="a"></parameter>
            <classes>
                <class name="selenium.mail.gmail.BabyTest">
                    <methods>
                        <include name="A" />
                        <include name="B" />
                        <exclude name="C" />
                    </methods>
        </class>
    </classes>
</test> <!-- Test -->

<test name="FF_test">
    <parameter name="Browser" value="Firefox"></parameter>
    <parameter name="email" value="b"></parameter>
    <classes>
        <class name="selenium.mail.gmail.BabyTest">
            <methods>
                <exclude name="C" />
            </methods>
        </class>
    </classes>
</test>


<test name="IE_test">
    <parameter name="Browser" value="IE"></parameter>
    <parameter name="email" value="c"></parameter>
    <classes>
        <class name="selenium.mail.gmail.BabyTest">
            <methods>
                <include name="A" />
            </methods>
        </class>
    </classes>
</test>

sorry for wrong indentation, code with correct indentation wasn't displayed properly.

Mahen
  • 9
  • 1
  • 4
  • This about driver and test data management. You can utilize [QAF](https://qmetry.github.io/qaf) for that. Where you can specify driver by using `driver.name` property and data you can provide in data file. I am sure this data you need to fill in form where you can use [formDatabean](https://qmetry.github.io/qaf/latest/databeans.html#form-data-bean) populated with random data or from data file. So when you have large number of test case you can manage test data properly. – user861594 Nov 20 '16 at 11:39