2013-05-29 27 views
1

我有不同的類實現ExpectedCondition;其中一個AttributeContainsCondition如下所示。在我的測試中,我嘗試使用像condition dot這樣的東西,並查看ExpectedCondition中提供的所有方法以及我創建的實現ExpectedCondition的所有類。如何在WebDriver測試中將ExpectedConditions類與已實現的類相結合

所以在我的測試中,我試圖添加一些東西來從ExpectedCondition中獲取所有的方法以及我創建的實現ExpectedCondition的所有類。我正在導入創建類的位置。

public class AttributeContainsCondition implements ExpectedCondition<Boolean>{ 

    private final WebElement element; 
    private final String attributeName, expectedValue; 

    public AttributeContainsCondition(WebElement element, String attributeName, String expectedValue){ 
     this.element = element; 
     this.attributeName = attributeName; 
     this.expectedValue = expectedValue; 
    } 

    public Boolean apply(WebDriver input){ 
     return StringUtils.contains(element.getAttribute(attributeName), expectedValue); 
    } 
} 

測試文件:這是行不通的

import org.openqa.selenium.support.ui.ExpectedConditions; 
public class VerifyInfoTest extends mainTest { 
    ExpectedConditions condition = new ExpectedConditions<boolean>(); ???? 

,所以如果我使用condition.xxxx我應該能看到ExpectedConditions我創建實現它

感謝的方法和 所有類你:)

+0

你爲什麼初始化條件如此?這應該是'ExpectedCondition cond = new AttributeContainsCondition(...);' – fge

+0

謝謝......我看到這個錯誤:「令牌上的語法錯誤」布爾值「,在該令牌之後預期的維度」。而且,由於我有大約15個類,如AttributeContainsCondition,我試圖擺脫初始化它們中的每一個,如果可能的話。 – brzspirit

+0

'布爾',而不是'布爾'! 'Boolean'是對象,'boolean'是原始類型 – fge

回答

0

如果你想使用你的AttributeContainsCondition說在wait.until

,你可以用它的方式如下:

boolean result = wait.until(new AttributeContainsCondition(
     yourWebElement, 
     "yourAttributeName", 
     "yourExpectedValue")); 
相關問題