How can I execute multiple test class 'test1'
and 'test2'
parallely? Which is using the same function in another class using TestNG.
When I define the parallel option as 'classes' and thread-count as '2' in TestNG XML, the login page is loading two times, but 'sendelement' method is executing in single browser two times simultaneously.
for eg; if my login is 'user1'
, sendelement
function execute two times as 'user1user1'
in the username field and shows invalid login.
<?xml version="1.0" encoding="UTF-8"?>
<!-- <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> -->
<suite name="Suite" parallel="classes" thread-count="2">
<test name="NavigationTest">
<classes>
<class name="Test1" />
<class name="Test2" />
</classes>
</test>
</suite>
public class Test1 {
loginToUserPage(strUserName, strPassword);
}
public class Test2{
loginToUserPage(strUserName, strPassword);
}
public class Test3
{
public void loginToUserPage(String strUserName,String strPassword)
{
webdriverCommon.windowMaximise();
webdriverCommon.sendElement(CommonRepo.userName_Edit, strUserName);
webdriverCommon.sendElement(CommonRepo.password_Edit, strPassword);
webdriverCommon.clickElement(CommonRepo.logginButton_buttton);
}
}
-
Where do your username and password come from? I don't see that data anywhere.FDM– FDM2017年05月26日 09:03:28 +00:00Commented May 26, 2017 at 9:03
-
strUserName,strPassword are username, password variables.. CommonRepo.userName_Edit and CommonRepo.userName_Edit are the By elements for input fields in UIsreelakshmi– sreelakshmi2017年05月26日 12:21:11 +00:00Commented May 26, 2017 at 12:21
-
Can you show the actual test class where you pass the data?FDM– FDM2017年05月26日 12:34:04 +00:00Commented May 26, 2017 at 12:34
1 Answer 1
It looks like you are using one webDriver, webdriverCommon
. You'll need to setup your framework such that each class or test uses its own driver. I have a TestBase class that each test class inherits from. The following example is using JUnit but the idea is the same.
public class TestBase {
protected WebDriver driver;
protected String baseUrl = "http://example.com/";
protected String hubUrl = "http://localhost:4444/wd/hub";
@Before
public void setUp() throws Exception{
try {
DesiredCapabilities capability = DesiredCapabilities.chrome();
driver = new RemoteWebDriver(new URL(hubUrl), capability);
}
catch (Exception e){
System.setProperty("webdriver.chrome.driver", "C:\\Selenium\\chromedriver.exe");
driver = new ChromeDriver();
}
driver.manage().deleteAllCookies();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@After
public void tearDown() throws Exception{
driver.quit();
}
}
Explore related questions
See similar questions with these tags.