Reputation: 1399
I'm trying to set up robot on top of an Eclipse Maven-Selenium-TestNG java project I created, but it doesn't seem to be picking up default keywords (I haven't even tried adding my own yet).
I started by creating a maven project and adding to pom.xml the dependencies for selenium 3.4, testNG 6.8 and robot 3.0.2, then also added robot plugin 1.4.7. Finally, updated the project so maven downloads all the needed stuff.
To test selenium (without robot) I created a textNG class in src>test>java, added a system property pointing to the chromedriver.exe file in my system and added a simple test that just opens the browser and navigates to google. It worked, so now I want to use robot on top of that.
This is my pom.xml file:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.demo.automation</groupId>
<artifactId>automated_tests</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.robotframework</groupId>
<artifactId>robotframework</artifactId>
<version>3.0.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.robotframework</groupId>
<artifactId>robotframework-maven-plugin</artifactId>
<version>1.4.7</version>
<executions>
<execution>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
I created a file in src/test/robotframework/acceptance, with the following contents:
*** Settings ***
Test Set Up Start Selenium Server
Test Tear Down Stop Selenium Server
*** Test Cases ***
Visit google
Open Browser https://www.google.com chrome
Close Browser
However, when I run as maven install, I get:
Setup failed: No keyword with name 'Start Selenium Server' found.
Also teardown failed: No keyword with name 'Stop Selenium Server' found.
So why is it that robot is not finding the keywords implementation? And how do I add implementations of my own keywords?
Upvotes: 1
Views: 4479
Reputation: 1399
I actually found out I was missing a maven dependency:
<dependency>
<groupId>com.github.markusbernhardt</groupId>
<artifactId>robotframework-selenium2library-java</artifactId>
<version>1.4.0.8</version>
</dependency>
Also, I don't need to use Start Selenium Server and Stop Selenium Server because they're deprecated. After that, I was able to run my test by creating a custom keyword to set browser path (I'm using chromedriver):
I created a .java file within src/main/java/demo
and added a method that sets up the property:
package demo;
public class Setup {
public void driverPath() {
System.setProperty("webdriver.chrome.driver", "C:\\path\\to\\chromedriver.exe");
}
}
Then, I created src/test/robotframework/acceptance/Resource.robot file and imported my library:
*** Settings ***
Library Selenium2Library
Library demo.Setup
Also created a src/test/robotframework/acceptance/__init__.robot file and used the keyword I created (Browser Setup):
*** Settings ***
Test Setup Driver Path
Test Teardown Close All Browsers
Test Timeout 2 minute 30 seconds
In my test, I invoked Resource.robot:
*** Settings ***
Resource Resource.robot
*** Test Cases ***
Visit google
Open Browser https://www.google.com chrome
Upvotes: 0
Reputation: 386362
The reason robot isn't finding the keywords is that you aren't importing the library that contains the keywords. Start Selenium Server
is part of the deprecated SeleniumLibrary. In order to use the keywords you must import them with the Library
setting:
*** Settings ***
Library SeleniumLibrary
Test Set Up Start Selenium Server
Test Tear Down Stop Selenium Server
Assuming that the folder where SeleniumLibrary
is installed is in your PYTHONPATH, robot will import the library and make the keywords available to you.
Upvotes: 1