Java Robot框架未拾取关键字实现
我试图在我创建的EclipseMaven Selenium TestNG java项目上设置robot,但它似乎没有选择默认关键字(我甚至还没有尝试添加自己的关键字) 我首先创建了一个maven项目,并将selenium 3.4、testNG 6.8和robot 3.0.2的依赖项添加到pom.xml中,然后还添加了robot插件1.4.7。最后,更新了项目,让maven下载所有需要的东西 为了测试selenium(没有robot),我在src>test>java中创建了一个textNG类,在我的系统中添加了一个指向chromedriver.exe文件的系统属性,并添加了一个简单的测试,只需打开浏览器并导航到google即可。它成功了,所以现在我想在上面使用机器人 这是我的pom.xml文件:Java Robot框架未拾取关键字实现,java,eclipse,maven,selenium,robotframework,Java,Eclipse,Maven,Selenium,Robotframework,我试图在我创建的EclipseMaven Selenium TestNG java项目上设置robot,但它似乎没有选择默认关键字(我甚至还没有尝试添加自己的关键字) 我首先创建了一个maven项目,并将selenium 3.4、testNG 6.8和robot 3.0.2的依赖项添加到pom.xml中,然后还添加了robot插件1.4.7。最后,更新了项目,让maven下载所有需要的东西 为了测试selenium(没有robot),我在src>test>java中创建了一个textNG类,在我
<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>
但是,当我以maven install运行时,我得到:
安装失败:找不到名为“Start Selenium Server”的关键字
拆卸也失败:没有名为“Stop Selenium Server”的关键字
找到了
那么,为什么robot找不到关键字实现呢?如何添加我自己的关键字的实现?robot找不到关键字的原因是您没有导入包含关键字的库<代码>启动Selenium服务器是不推荐使用的Selenium库的一部分。要使用关键字,您必须使用
库
设置导入它们:
*** Settings ***
Library SeleniumLibrary
Test Set Up Start Selenium Server
Test Tear Down Stop Selenium Server
假设安装了
SeleniumLibrary
的文件夹位于PYTHONPATH中,robot将导入库并使关键字对您可用 我实际上发现我缺少一个maven依赖项:
<dependency>
<groupId>com.github.markusbernhardt</groupId>
<artifactId>robotframework-selenium2library-java</artifactId>
<version>1.4.0.8</version>
</dependency>
然后,我创建了src/test/robotframework/acceptance/Resource.robot文件并导入了我的库:
*** Settings ***
Library Selenium2Library
Library demo.Setup
还创建了一个src/test/robotframework/acceptance/_init__.robot文件,并使用了我创建的关键字(浏览器设置):
在测试中,我调用了Resource.robot:
*** Settings ***
Resource Resource.robot
*** Test Cases ***
Visit google
Open Browser https://www.google.com chrome
*** Settings ***
Library Selenium2Library
Library demo.Setup
*** Settings ***
Test Setup Driver Path
Test Teardown Close All Browsers
Test Timeout 2 minute 30 seconds
*** Settings ***
Resource Resource.robot
*** Test Cases ***
Visit google
Open Browser https://www.google.com chrome