Hi Krishnan,
Thanks for the response.
I tried something with loggin into gmail on similar lines, following is the code:
package com.scripts;
import com.frame.*;
import com.lib.EnvSetup;
import com.lib.InitLog4j;
import com.lib.SuiteListener;
import com.lib.UtilityFun;
import org.apache.log4j.Logger;
import
org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.PageFactory;
import org.testng.Assert;
import org.testng.annotations.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Hashtable;
@Listeners({ SuiteListener.class})
public class Gmail_Login_TesCase2 extends Gmail_Login_Template{
// Instantiate Page class, utility and test environment objects
EnvSetup EnvObj = new EnvSetup();
UtilityFun utilObj = new UtilityFun();
protected Logger log = Logger.getLogger(this.getClass().getName());
private String username;
private String password;
private String applicationName;
public static RemoteWebDriver WEBDRIVER;
protected GmailLoginPage GmailLoginPage;
@Factory (dataProvider="dp")
public Gmail_Login_TesCase2(String username, String password,String applicationName){
this.username=username;
this.password = password;
this.applicationName = applicationName;
}
@Test (description="Gmail Login")
public void Gmail_Login() throws MalformedURLException {
// Read Test Data
log.info("Logging in Gmail");
DesiredCapabilities capability = DesiredCapabilities.chrome();
capability.setBrowserName("chrome");
capability.setCapability("applicationName",applicationName);
WEBDRIVER = new RemoteWebDriver(new URL("
http://localhost:4444/wd/hub"), capability);
GmailLoginPage = PageFactory.initElements(WEBDRIVER, GmailLoginPage.class);
log.info("Entering into GMAIL");
try{
WEBDRIVER.get("
http://www.gmail.com");
WEBDRIVER.findElementById("Email").sendKeys(username);
WEBDRIVER.findElementById("next").click();
System.out.println(password);
WEBDRIVER.findElementById("Passwd").sendKeys(password);
WEBDRIVER.findElementById("signIn").click();
}
catch (Exception e) {
log.info(e.getMessage());
}
}
{new String("XXXX"),new String("XXXX"),new String("agent1")},
{new String("XXXX"),new String("XXXX"),new String("agent2")}
};
}
@Override
public void performBeforeMethodOperation() {
// TODO Auto-generated method stub
}
@Override
public void performBeforeSuiteOperation() {
// TODO Auto-generated method stub
}
@Override
public void performAfterMethodOperation() {
// TODO Auto-generated method stub
}
@Override
public void performAfterSuiteOperation() {
// TODO Auto-generated method stub
}
}
And the testng xml looks like:
<suite name="Sample test suite" >
<test name="Gmail_Login" preserve-order="true">
<classes>
<class name="com.scripts.Gmail_Login_TesCase2">
</class>
</classes>
</test>
</suite>
After the run, the test results showed that:
===============================================
Sample test suite
Total tests run: 2, Failures: 1, Skips: 0
===============================================
Two queries:
1) Again the purpose of running under same test case is not solved, as the above run shows that two test cases are run, but I want the run this as a single test case
2) Secondly, if I want to do further operations in the individual remote WebDriver, how can I identify the remotewebdriver on each machine after it has been launched and work on it.
Thank you,
Viji Iyer