我是RobotFramework的新手(实际评估它是为了一个新的测试自动化项目)。在RobotFramework中扩展Selenium2库WebElement
在过去,我总是使用Java和页面对象创建自己的小框架,但是这次我想知道我是否可以使用现有的框架。我正在评估Spock和Robot Framework。
我的要求是测试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
//.........................
//.........................
机器人框架看起来不错,到目前为止,我喜欢蟒蛇太..但是我不知道我是否能够延长图书馆像selenium2library有自己的定制方法,就像我以前做的java在上面的例子中。
您的实际目标是什么?您的实际目标是重写webelement方法,还是您的目标是让您更容易地调用按您的方式行事的硒函数(例如:添加额外的日志记录,等待等)?换句话说,重写click方法的目标,还是只是达到目的的一种手段? –