问题
I have to test multiple machine and each machine have to test different website with same browser. In this case can I use Selenium Grid? If I can't, are there any way to do that?
回答1:
Yes you can do it using Grid. I am going to give you a simple example. Create two class of testng and and set the class in testng.xml
Now use code in both classes as below:-
public class Testing {
public static try1 {
try{
String baseUrl="https://www.google.com/"; // url on which we have to test
String nodeurl="http://192.168.10.30:5555/wd/hub"; // ip and port of node remote machine 2 we are using as node for testing.
System.setProperty("webdriver.chrome.driver","C:/robot/chromedriver.exe");
// the below line have chrome capability then explorer works dont change it to explorer it doesn't work
WebDriver driver = new RemoteWebDriver(new URL(nodeurl), DesiredCapabilities.chrome());
driver.get(baseUrl);
WebElement element = driver.findElement(By.name("q"));
element.sendKeys("BrowserStack");
element.submit();
System.out.println(driver.getTitle());
driver.quit();
}
Now configure different site in both classes, set there ips and provide there port as you had set in your other salve machines.
If you want to run them parallel then simply put parallel="tests"
in your testng.xml
<suite name="Test-class Suite" parallel="tests" thread-count="2">
I Hope it will help you :)
来源:https://stackoverflow.com/questions/32389706/can-i-use-selenium-grid-to-test-multiple-machines-and-website-but-same-browser