2

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 have python 3.4.3 installed on my Win 10 machine and am using the embedded maven that comes with Eclipse.

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 so I don't have to install anything externally.

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 opens the browser and navigates to google. It worked, so now I want to add robot framework.

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 (although I've read somewhere that after selenium 2 the "start/stop selenium server" keywords are not necessary, but nothing changes if I remove them):

*** 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

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?

2

A few corrections which will not directly solve the issues you're facing, but will put you in the right direction.

About your robotframework source:

  • The settings names are actually Test Setup and Test Teardown (single words)
  • To use a library, like the Selenium you'd like to, it has to be "imported" - e.g. again in the *** Settings *** section, add it as Library SeleniumLibrary. This btw is the reason for the error you are seeing.

In general:

  • This particular library is deprecated - it is based on Selenium RC (which no one uses anymore), and there is no development on it. (plus I've never used it myself, thus can't really help you any more with it...)
  • The current one is the so-called Selenium2Library - doc link; it's very much up to date with Selenium, has a lot of higher-level utility and helper methods
  • BUT (there's always a "but") it currently does not work with Python 3.X... So in order to utilize it, you should use the latest Python 2.7.x. The py3 support is underway, but frankly cannot say about its ETA.

As for the very last question you have - "And how do I add implementations of my own keywords?", that topic is thoroughly covered in the user guide - link again.
Basically, you can create them in the *** Keywords *** section of a suite and reference them, put in an external keywords file (and import them in the settings section through Resource your_file.robot), create them in python and load as a library, or even - run them as a service on a node and access with RPC calls. I.e. a vast topic :)

  • Thanks @Todor :) I now installed python 2.7 (and changed the environment Path variable), then added a Library Selenium2Library line in test settings. But I still get the same errors, only that now a new one is added: [ ERROR ] Error in file 'C:\mypath\src\test\robotframework\acceptance\tests.robot': Importing test library 'Selenium2Library' failed: ImportError: No module named Selenium2Library. I've read somewhere that libraries must be added in ${project.basedir}/src/test/resources/robotframework/libraries, however, since I use a maven repository, maybe it's not finding my selenium? – Floella Jul 4 '17 at 14:15
  • Have you followed the instructions here, and copied the extracted Selenium2Library's src dir to ${project.basedir}/src/test/resources/robotframework/librari‌​es? Disclaimer - I haven't ever set up the RF maven plugin, just reading what's in the docs; fingers crossed it will do the trick. – Todor Minakov Jul 4 '17 at 15:12
  • Actually, that's the part that puzzles me the most, since I'm using Maven to manage libraries for me. Why do I still need to manually place libraries in a specific folder? In any case, shouldn't I just tell robot to look for selenium in the maven repository instead of ${project.basedir}/src/test/resources/robotframework/librari‌​‌​es? That's what seems to indicate the answer here: stackoverflow.com/questions/40621698/… – Floella Jul 4 '17 at 16:14
  • Btw, even if I include selenium (version 3.4, which I downloaded from seleniumhq.org/download) in ${project.basedir}/src/test/resources/robotframework/librari‌​‌​‌​es and then run my project, I still get the same error. – Floella Jul 4 '17 at 16:33
  • The required is not the selenium library by itself; that is robotframework's selenium2library, usually installed by pip. It's pip name is robotframework-selenium2library. I would suggest for you to run a couple of cases standalone, and once you get the flow fully working, then to work on starting them from maven. – Todor Minakov Jul 4 '17 at 16:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.