I have integrated my Selenium testNG suite with Jenkins build. Depending on the environment the build happens onto, automation script gets triggered. I am sending environment info from Jenkins to Automation code using "mvn clean test -Denv=" command. I am successfully using this value for environment in my script for distinguishing between data on different environments.
However some of my Xpaths have varying data depending on environment like text()='something environment specific'. I am unable to provide dynamic string at run time in @FindBy as it is not allowed for this annotation.
Please suggest any leads for this issue as I am willing to stick with the page factory approach.
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;
}