2017-01-30 55 views
1

在Selenium中使用PageObject模式,我想将所有定位器放在资源文件中。FindsBy属性与资源文件c#Selenium

尽可能使用与资源文件FindsBy属性

[FindsBy(How = How.Id, Using = "btnUserApply")] 
public Button ApplyButton { get; set; } 

变得低于疑惑给出了一个错误和不能做

[FindsBy(How = How.Id, Using = MyRexFile.btnUserApply)] 
public Button ApplyButton { get; set; } 

FindsBy也是密封的,不能继承。

有什么建议吗?

回答

0

这是不可能的。 FindsBy注释以Using参数的形式接收const(在编译中评估)字符串。来自资源文件的数据在运行时进行评估。

你可以创建另一个类来保存所有定位器

public static class Locators 
{ 
    public const string btnUserApply = "btnUserApply"; 
} 

public class PageObject 
{ 
    [FindsBy(How = How.Id, Using = Locators.btnUserApply)] 
    public Button ApplyButton { get; set; } 
} 
+0

你说只与常量的作品?关于如何创建自己的定制FindsBy来接受属性。关于这个 – developer9969

+0

@ developer9969没有太多东西可以,“FindsBy”只能用于常量。我从来没有尝试过创建自定义的'FindsBy',也没有遇到这种尝试。但也许这是可能的。 – Guy