views:

661

answers:

2

I am using Selenium Grid with TestNG to run my tests in parallel. I have certain tests that require a user to be logged in, so I have a user account configured for testing.

I have been careful to ensure that any tests involving logging in as my test user are run on separate virtual machines so that sessions are not interrupted, however after investigating some regularly failing tests it turns out that this is not enough. I therefore either need to:

  • Set up a new user for each test (I understand this may be the ideal solution, but it'll take some time to configure/run.

  • Have multiple test user accounts, and ensure that only one is used at a time.

If I could identify the host of the machine running the test I could set up test accounts accordingly. Is there any way to do this, or is there another solution that I haven't thought of?

A: 

I solved my problem by setting up several unique user accounts purely for testing, all ending with a number (for example: selenium.test1). This was simple to automate as a one off task using Selenium.

I store this number in code, and every time a test needs to login the number is incremented and the username is constructed.

I did consider 'releasing' and subsequently reusing these accounts when the tests finish, but decided it was easier just to make sure I had plenty of test accounts for my tests.

Dave Hunt
A: 

Hi, can u tell me how can we run a testng test parallely in remote machines with out giving parameters in xml because xml use is good for small number of testcases but i have a test case which i have to run on 20 machines.and i am using testng+selenium+eclipse environment and not able to run my test parallely.itz running sequentially and atacking only one host machine. i created 20 instances using @factory annotation to run on 20 machines but itz creating 20 instances in my machine thats bz itz not able to catch other host machine ip's.may be i am missing something.would really appreciate if u can provide sm solution to this.

here is my test: import com.thoughtworks.selenium.; import org.testng.annotations.;

public class Xampperf02 { private Selenium selenium;

@BeforeClass
@Parameters({"selenium.host","selenium.port","selenium.browser","selenium.url",})
public void startSelenium(String host, String port, String browser, String url) {

this.selenium = new DefaultSelenium(host, Integer.parseInt(port), browser, url);
this.selenium.start();
this.selenium.open(url);

}

@AfterClass(alwaysRun=true)
public void stopSelenium() {
this.selenium.stop();
}
@Test(invocationCount=2)
public void testXampperf02() throws Exception {
 selenium.open("http://202.53.87.166/xampperf/index.html");
 selenium.click("link=Login");
 selenium.waitForPageToLoad("30000");
 String loginID = selenium.getExpression("login");
 selenium.type("login", selenium.getEval("'" + loginID + "'+Math.round((3790-3741) * Math.random() + 3741)"));
 selenium.type("password", "password");
 selenium.click("Submit");
 selenium.waitForPageToLoad("30000");
 selenium.click("link=Total Members list");
 selenium.waitForPageToLoad("30000");
 selenium.click("link=Logout");
 selenium.waitForPageToLoad("30000");
 selenium.click("link=Login");
 selenium.waitForPageToLoad("30000");
}

}

My factory classs is as follows:(here i am creating 20 instances of my test class Xampperf02()

import org.testng.annotations.Factory; import org.testng.annotations.Test;

@Test public class Factory1 { @Factory public Object[] createInstances() { return new Object[] {new Xampperf02(), new Xampperf02(), new Xampperf02(), .
. . new Xampperf02(), };

} }

and here goes my xml file:

............(20 ips of differnt host)

.

In the xml file,i am passing 20 ip values but my test is detecting only one ip and creating all 20 instances in that single host machine leaving remaining 19 ip's in idle.

Ajay