A look at testng.xml

This is what the testng.xml file looks like:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test name="ChromeTest" enabled="true">
<classes>
<class name="org.packt.client.Driver_Script">
<parameter name="browserName" value="chrome"></parameter>
</class>
</classes>
</test>
<test name="IETest" enabled="true">
<classes>
<class name="org.packt.client.Driver_Script">
<parameter name="browserName" value="ie"></parameter>
</class>
</classes>
</test>
<test name="FirefoxTest" enabled="true">
<classes>
<class name="org.packt.client.Driver_Script">
<parameter name="browserName" value="firefox"></parameter>
</class>
</classes>
</test>

</suite> <!-- Suite -->

As you can see, the Driver_Script class in the org.packt.client package gets executed. Let's look at the contents of the Driver_Script class next.

The Driver_Script class has a switch case for all of the different keywords, such as openBrowser, and Navigate, as you can see in the following block of code:

  @Test
@Parameters({ "browserName" })
public void Run_Framework(String browserName) {
List<String> browsers = new ArrayList<String>();
browsers.add(browserName);
input_data = ExtractAllData.extractData(browserName);
System.out.println("kya ha ?" + input_data.size());
for (int i = 0; i < input_data.size(); i++) {
String timestamp = new SimpleDateFormat("yyyyMMMddHHmmss")
.format(new java.util.Date());

System.out.println("Starting " + browserName + timestamp);
actionKeyword = input_data.get(i).get("Keyword").toString();
inputData = input_data.get(i).get("Data").toString();
testcaseID = input_data.get(i).get("TestCaseID").toString();

switch (actionKeyword) {
case "openbrowser":
try {
actKeyword = new OpenBrowser();
} catch (IOException e) {
throw;
} catch (FilloException e) {
e.printStackTrace();
}
command = new NewBrowser(actKeyword);
invoker = new BrowserInvoker(command);
driver = invoker.open(browsers);
break;
case "navigate":
try {
actKeyword = new OpenURL();
} catch (IOException e) {
e.printStackTrace();
} catch (FilloException e) {
e.printStackTrace();
}
command = new OpenURLCommand(actKeyword);
NavigatorInvoker invoker1 = new NavigatorInvoker(command);
driver = invoker1.navigate(driver, inputData);
break;
}
}
}
}

If the Framework.xlsx file contains four test cases with two marked as Y in the Execute_Flag column, the Browser has the values Chrome and Internet Explorer, and if you execute testng.xml with this code, then one Chrome session will start, navigate to http://www.freecrm.com, and stay open. Similarly, an Internet Explorer session will open after that and navigate to the same URL and stay open. A new keyword called closeBrowser can be added if the browser windows need to be closed.

As you may have noticed from the timestamp, both of the timestamps will be different, indicating that each test case runs sequentially. But wait...if we have around 2,000 test cases in our test suite, won't the execution take a huge amount of time?

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.111.9