我是 RobotFramework 的新手(实际上是为一个新的测试自动化项目评估它)。
过去,我总是使用 Java 和页面对象创建自己的小框架,但是这次我想知道是否可以使用现有的框架。我正在评估 Spock 和机器人框架。
我的要求是测试 web 应用程序、windows 对象和移动应用程序,所以 Robot 肯定比 Spock 更有优势。我也更喜欢 Python 而不是 Groovy。
我通常使用以下代码在我的框架中扩展 WebElement。我想知道是否可以在 Robot Framework 中做这样的事情。
//importing webdriver and other selenium libraries
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.internal.Coordinates;
import org.openqa.selenium.internal.Locatable;
import org.openqa.selenium.internal.WrapsElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.Wait;
//interface that will be implemented by my custom web element
interface MyElement extends WebElement, WrapsElement, Locatable {
}
//my custom web element class
public class MyWebElement implements MyElement {
private WebElement element;
//private constructor for my web element class
private MyWebElement(WebElement element) {
this.element = element;
}
//public factory method for my web element class
public static MyWebElement getInstance(By by) {
WebElement element = MyWebDriver.getInstance().findElement(by);
MyWebElement myWebElement = new MyWebElement(element);
return myWebElement;
}
//overriding WebElement method click
@Override
public void click() {
waitUntilClickable();
element.click();
}
//adding method waitUntilClickable to my web element
public MyWebElement waitUntilClickable() {
return waitUntilClickable(MyWebDriver.getTimeoutElementInMilliseconds(),
MyWebDriver.getPollingElementInMilliseconds());
}
//adding helper method to implement waitUntilClickable
public MyWebElement waitUntilClickable(long timeOutInMilliseconds,
long pollingIntervalInMilliseconds) {
Wait<WebDriver> wait = new FluentWait<WebDriver>(MyWebDriver.getInstance())
.withTimeout(timeOutInMilliseconds, TimeUnit.MILLISECONDS)
.pollingEvery(pollingIntervalInMilliseconds, TimeUnit.MILLISECONDS);
wait.until(ExpectedConditions.elementToBeClickable(element));
return this;
}
//other additional and overriding methods
//.........................
//.........................
到目前为止,Robot Framework 看起来不错,我也喜欢 python.. 但是我不知道我是否能够扩展 selenium2library 之类的库以拥有自己的自定义方法,就像我在上面的示例中在 java 中所做的那样。