I have Java project with TestNG tests and Selenium WebDriver. At the moment, I can run them locally from my IDE only.
How can I implement a system that allows me to run a test with a post/get request on server?
For example, a page with button: on button click, a test should start executing on server, with all WebDriver manipulations, and when it's finished, I would receive an answer.
At first, I tried to call my testng.xml from command line. It worked, but it looks like command line is not, what I can use remotely with simple FirefoxDriver, so I started researching the "RemoteWebDriver" feature.
Then I downloaded " selenium-server-standalone-3.4.0 " and started the server and the node, but each time the script ends with an exception:
org.openqa.selenium.WebDriverException: The path to the driver executable must be set by the webdriver.gecko.driver system property
I added a required property, but it still doesn't work(the same problem). Here's a piece of code, which causes the exception:
@Test
public static void main() throws Exception {
URL server = new URL("http://127.0.0.1:4444/wd/hub");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
System.out.println("Connecting to " + server);
WebDriver driver = new RemoteWebDriver(server, capabilities);
System.setProperty("webdriver.gecko.driver", "geckodriver.exe");
driver.get("http://www.google.com");
driver.quit();
}
As you see, the system property is set (geckodriver.exe exists in directory and works fine with FirefoxDriver, but doesn't work with RemoteWebDriver).
I don't understand, what I'm doing wrong, and not even sure, that I'm working in right direction. Can you help me,please?
Tried adding parameter, proposed by @ekostadinov. Here's how I start hub and node:
java -Dwebdriver.gecko.driver="geckodriver.exe" -jar lib\selenium-server-standalone-3.4.0.jar -role hub
java -jar lib\selenium-server-standalone-3.4.0.jar -role node -hub http://localhost:4444/grid/register
Still doesn't work, but exception is different:
org.openqa.selenium.SessionNotCreatedException: Unable to find a matching set of capabilities
Update
Changed this
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
To this
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setBrowserName("firefox");
And it worked. Thanks everyone, who helped!
There is no need to
implement a system that allows me to run a test with a post/get request on server
except in the case, you really want to. Continuous_integration servers do all this and much more for you, out of the box. For example Jenkins (very suitable for JAVA based solutions) provides very convenient Selenium plugin , which helps you to manage the Grid.
One thing to note here - you should pass additional parameters when starting the Hub on your server, like so:
java -Dwebdriver.chrome.driver="/full/path/to/chromedriver" -Dwebdriver.gecko.driver="/full/path/to/geckodriver" -jar selenium-server-standalone-3.4.0.jar -role hub
Try moving this line of code above where you instantiate the driver:
System.setProperty("webdriver.gecko.driver", "geckodriver.exe");
Like this
@Test
public static void main() throws Exception {
URL server = new URL("http://127.0.0.1:4444/wd/hub");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
System.out.println("Connecting to " + server);
System.setProperty("webdriver.gecko.driver", "geckodriver.exe");
WebDriver driver = new RemoteWebDriver(server, capabilities);
driver.get("http://www.google.com");
driver.quit();
}
Also make sure the geckodriver is in the same directory where you are starting the hub/node.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.