我是Robot框架的新手,致力于使用带有Selenium和java关键字的Robot框架。我知道RF是基于python的,但是,该项目要求使用java关键字。
我的想法是创建java函数和文本文件,然后使用:java-jarrobotframework-2.8.x.jar
例如,java函数正在使用selenium webdrive打开浏览器,问题是我不知道如何将java函数组合到文本文件中。我试了试,但错误是“找不到关键字”。如果我的java函数称为openBrower
,我应该如何在文本文件中定义关键字?
谁能给我提供一个带有selenium和java关键字的RF的简单示例?谢谢!
# This file is located in "robot" folder
*** Settings ***
Documentation CommonResource file with KWs
Library OperatingSystem
*** Variables ***
${SRC_PATH} ../../src/
*** Keywords ***
Compile Class
[Arguments] ${class_name} ${path}=${SRC_PATH}
Run javac ${path}${class_name}.java
Run Java Class
[Arguments] ${class_name} ${path}=${SRC_PATH}
Compile Class ${path} ${class_name}
${output}= Run java -cp ${path} ${class_name}
Log ${output} WARN
/**
* This file is located in "src" folder
*/
public class Test {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
# This file is located in "robot/Tests" folder
*** Settings ***
Documentation Running Java class with RF
Resource ../CommonResource.robot
*** Testcases ***
TestOne
Run Java Class Test
package com.mypackage;
public class Foo {
public void methodNameIsKeyword() {
// ...
}
}
apply plugin: "java"
repositories {
mavenCentral()
}
dependencies {
runtime "org.robotframework:robotframework:2.8.5"
}
task writeScript() {
def classpath = sourceSets.main.runtimeClasspath + files("build/libs/mylibrary.jar")
println "java -cp ${classpath.asPath} org.robotframework.RobotFramework \$@"
}
task wrapper(type: Wrapper) {
gradleVersion = "1.10"
}
下一步是在脚本中使用新关键字
*** Settings ***
Library com.mypackage.Foo # constructor args go here.
*** Testcases ***
It should use the Java class
Method Name Is Keyword
当然,类可以接受构造函数参数,并从方法中获取参数/返回值。
甚至我也遇到过类似的情况,我必须将Java与Robotframework结合使用。使用Robot Selenium2library for Java可以链接关键字。
您还可以创建自定义关键字,然后将它们链接到Java类以实现各自的实现。
尝试查看下面的项目
https://github.com/mskumar1809/StraitTimesAppiumRobot
它为Robot关键字提供了java实现。