在运行Selenium网格设置时,我在启动Chrome浏览器时遇到问题,导致错误“无法创建新服务:ChromeDriverService”。
对此,我确定 a)兼容Chrome驱动程序版本和浏览器。 b)Chrome驱动程序的路径由“系统”属性设置。
但是所有这些更改之后,我无法解决此问题。
请帮助。
代码
package Grid;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
public class fillingForm {
//Used dataProvider parameter to get data from @DataProvider annotation method.
//Can accept object array data(browser name, First Name and Last Name) from getNames method.
@Test(dataProvider = "getNames")
public void gmailLogin(String browser, String fName, String lName) throws MalformedURLException, InterruptedException {
System.setProperty("webdriver.chrome.driver","C:\\Users\\Sumedha\\OneDrive\\Documents\\Selenium\\Other Jars\\chromedriver.exe");
System.setProperty("webdriver.geckodriver.driver","C:\\Users\\Sumedha\\OneDrive\\Documents\\Selenium\\Other Jars\\geckodriver.exe");
System.setProperty("webdriver.iedriverserver.driver","C:\\Users\\Sumedha\\OneDrive\\Documents\\Selenium\\Other Jars\\IEDriverServer.exe");
//Initialize DesiredCapabilities null.
DesiredCapabilities cap = null;
//Initialize browser driver as per data received from getNames().
if (browser.equals("firefox")) {
//Set firefox browser capabilities for windows platform.
cap = DesiredCapabilities.firefox();
cap.setBrowserName("firefox");
cap.setPlatform(Platform.WINDOWS);
} else if (browser.equals("chrome")) {
//Set chrome browser capabilities for windows platform.
cap = DesiredCapabilities.chrome();
cap.setBrowserName("chrome");
cap.setPlatform(Platform.WINDOWS);
} else if (browser.equals("iexplore")) {
//Set IE browser capabilities for windows platform.
cap = DesiredCapabilities.internetExplorer();
cap.setBrowserName("internet explorer");
cap.setPlatform(Platform.WINDOWS);
}
//Initialize RemoteWebDriver on grid 2 node with browser capability.
RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), cap);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//Open URL in requested browsers of node and execute test steps.
driver.get("http://only-testing-blog.blogspot.in/2014/05/form.html");
driver.findElement(By.name("FirstName")).sendKeys(fName);
driver.findElement(By.name("LastName")).sendKeys(lName);
driver.quit();
}
//Created @DataProvider annotation method to supply data(browser name, First Name and Last Name) for test
@DataProvider(parallel=true)
public Object[][] getNames(){
Object data[][] = new Object[3][3];
data[0][0] = "firefox";
data[0][1] = "FirstName1";
data[0][2] = "LastName1";
data[1][0] = "chrome";
data[1][1] = "FirstName2";
data[1][2] = "LastName2";
data[2][0] = "iexplore";
data[2][1] = "FirstName3";
data[2][2] = "LastName3";
return data;
}
}
testng.xml
<suite name="My Test Suite" verbose="2" parallel="tests" thread-count="5">
<test name="Selenium Grid Test">
<classes>
<class name="Grid.fillingForm" />
</classes>
</test>
</suite>