我是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方法的目標,還是隻是達到目的的一種手段? –