1

我已将我的 Selenium testNG 套件与 Jenkins 构建集成。根据构建发生的环境,触发自动化脚本。我使用“mvn clean test -Denv=" 命令将环境信息从 Jenkins 发送到自动化代码。我成功地在我的脚本中使用这个环境值来区分不同环境中的数据。

但是,我的一些 Xpath 具有不同的数据,具体取决于 text()='something environment specific' 等环境。我无法在运行时在 @FindBy 中提供动态字符串,因为此注释不允许这样做。

请就这个问题提出任何线索,因为我愿意坚持使用页面工厂方法。

Web Element Repository : 

    @FindBy(how = How.XPATH, using = "//tr/td[text()='Dipali33']")
public WebElement student_UserName_Value;


pom.xml contains:

    <configuration>
<systemPropertyVariables>
<environment>${env}</environment>
</systemPropertyVariables>
</configuration>

Automation code contains logic based on environment:

    this.env = System.getProperty("environment");
if(env='dev'){
    ..........
    .......
} 

Actual- The XPATHS are defined using static String.

Expected- XPATHS should be defined using dynamic String variable at run time something like as as below:

    if(env='dev'){
        @FindBy(how = How.XPATH, using = "//tr/td[text()='"+dev_studentName+"']")
        public WebElement student_UserName_Value;
    }
    else if(env='test'){
        @FindBy(how = How.XPATH, using = "//tr/td[text()='"+test_studentName+"']")
        public WebElement student_UserName_Value;
    }
4

1 回答 1

2

无法将 @FindBy 与动态 xpath 一起使用。您需要在方法中构建 By.xpath

于 2019-06-24T10:49:07.540 回答