Skip to content

Instantly share code, notes, and snippets.

Created September 1, 2015 04:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/f0f71e69c9a33dc96b5d to your computer and use it in GitHub Desktop.
Save anonymous/f0f71e69c9a33dc96b5d to your computer and use it in GitHub Desktop.
snippet of exampleTest
@Test(dataProvider = "HashMap", threadPoolSize = 2)
public void exampleTest(LinkedHashMap<String, String> cdpData,
... rest of params
int rowNum,
...
...
ITestContext itc) throws Throwable {
Long threadId = Thread.currentThread().getId();
System.out.println("Test method executing on thread with id: " + threadId);
System.out.println("testName " +testName + "row#" + cdpData.get("ID"));
System.out.println("itc.getName()" + itc.getName());
WebDriver driver = ExampleDriver.getDriver();
String url = TestConfig.getInstance().getLoginUrl();
driver.navigate().to(url);
// N.B testng dependency injection injects only a single instance of the ITestContext
// set imgCapMap key - key has to be the test name + row id from xlsx
String key = new String(testName + cdpData.get("ID"));
imgCapMap.put(key, new ArrayList<String>()); // key, imgCapList i.e. new key + new list of img cap per iteration. use the list size to count the number of screenshots
// set the test name key
String testNameKey = InetAddress.getLocalHost()+Long.toString(threadId);
LinkedHashMap<String, String> listOfTestNames = (LinkedHashMap<String, String>) itc.getAttribute("testNames");
listOfTestNames.put(testNameKey, key); // so when test runs adds e.g. lodgeTDP1, lodgeTDP1 ( value is same as key ).
// set the driver instance
driverMap.put(testNameKey, driver);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment