Parameters in TestNg
Test methods don't have to be parameterless. You can use an arbitrary number of parameters on each of your test method, and you instruct TestNG to pass you the correct parameters with the @Parameters annotation.
Passing parameters in TestNg.xml file
In the above testng.xml file we are passing deviceName, udid, platformVersion and url.
Test methods don't have to be parameterless. You can use an arbitrary number of parameters on each of your test method, and you instruct TestNG to pass you the correct parameters with the @Parameters annotation.
Passing parameters in TestNg.xml file
<test name="Device-1">
<parameter name="deviceName" value="emulator-5554" />
<parameter name="udid" value="emulator-5554" />
<parameter name="platformVersion" value="9.0" />
<parameter name="url" value="http://0.0.0.0:4724/wd/hub" />
<classes>
<class name="testScripts.test1"/>
</classes>
</test>
In the above testng.xml file we are passing deviceName, udid, platformVersion and url.
public class BaseTest {
public static AppiumDriver<MobileElement> driver;
@BeforeTest
@Parameters({"deviceName","udid", "platformVersion","url"})
public void setup(String deviceName, String udid,String platformVersion,String url) throws MalformedURLException, InterruptedException
{
DesiredCapabilities cap=new DesiredCapabilities();
cap.setCapability("deviceName", deviceName);
cap.setCapability("udid", udid);
cap.setCapability("appActivity", "com.android.calculator2.Calculator");
cap.setCapability("appPackage", "com.android.calculator2");
// cap.setCapability("appActivity", "com.weather.Weather.daybreak.MainActivity");
// cap.setCapability("appPackage", "com.weather.Weather");
cap.setCapability("platformName", "Android");
cap.setCapability("platformVersion", platformVersion);
driver=new AppiumDriver<MobileElement>(new URL(url), cap);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
Thread.sleep(5000);
}
}
Fetching the above parameters in the tests
parameterization is more helpfull when you want to pass details like browser details, device details when you want to run on multiple devices / browsers.
No comments:
Post a Comment
If any suggestions or issue, please provide