Forum Discussion
Kitt
3 years agoRegular Contributor
You can do this in several ways. If you use Name Mapping, you can pass a Project variable into your object identifiers as //a[text(), '%projectVar1%'] (NOTE: you can only use Project variables and NOT Project Suite variables in Name Mapping). The other methods of implementation might depend on your project setup and whether you are using scripting, keyword tests, or BDD for example - but in the same way allow you to use Project/ProjectSuite variables or pass in your own parameters or arguments into your test. Here are a few of those examples below:
SCRIPT
function findDynamicObject (var1) {
Sys.Browser("*").Page("*").FindElement("//a[text(), '" + var1 + "']").Click();
}
function testDynamicObject() {
findDynamicObject("City");
findDynamicObject("State");
findDynamicObject("Zip");
}
BDD
// bdd feature file (gherkin/cucumber)
Scenario Outline: Find a Dynamic Object
Given The user is logged into the application
When The user clicks on the dynamic object containing <text>
Then The user is redirected to somewhere
Exmaples:
| text |
| "City" |
| "State" |
| " Zip" |
// bdd script
Given("The user is logged into the application", function() {
// open application and log in
});
When("The user clicks on the dynamic object containing {arg}", function (param1){
Sys.Browser("*").Page("*").FindElement("//a[text(), '" + param1 + "']").Click();
});
Then("The user is redirected to somewhere", function() {
// verify redirect or somehting else
});
KEYWORD
see Smartbear [reference].