SoapUI override properites value of testCase when run as test step - properties

I have a test case that use custom properties. I want to override the properties value with another value when i run this testcase as a test step in another test case. how can i do it?

If you set the Return Properties to those custom properties (same name) in your Run TestCase Options then it should be overriding those values.

Related

How to add dynamic steps like dynamic data to automation testing

Having test with iterations which is steps like
Iteration 1 click on button in page Iteration 2 click on button in page 2 with same steps and same insertions.
I don’t want to repeat test case.
Test case steps can be dynamic like data by passing actions and func.
For example we need to automate reports page which have buttons for report1, report2, ..., report 10, when any button is clicked, confirming popup is displayed. This test case can be automated in one test case by passing dynamic steps to test case so no need to repeat test case.
For example nuit TestCaseSource returns IEnumerable.
GetTestCaseData IEnumerable<TestCaseData> (){
Yield return new Action( () => report1.Click())
.
.
}
By passing this method to test case like below. There is no need for repeating test cases by dividing iterations to different test cases. Iterations can be passed to test case.
[Test,TestCaseSource(nameof(GetTestCaseData))]
Public void TestCase (Action report){
//Act
NavigateToReport();
report.Invoke();
//Assert
}
Action can be used when no need to return. Func can be used if you need to assert on return.

Making dynamic code in Cucumber with the Page Object Model

Is there a way perform actions dynamically using Cucumber?
Example:
Feature File:
Scenario: Click all the boxes
Given On the checkbox page
When Click checkboxA
And Click checkboxB
Step Definition:
#When("Click checkboxA")
public void clickCheckBoxA()
{
pageObject.checkBoxA.click();
}
#And("Click checkboxB")
public void clickCheckBoxB()
{
pageObject.checkBoxB.click();
}
In this scenario, there are two very similar step definitions. The reason why there are two different definitions is because each WebElement is defined in the pageObject Class. Is there a way to dynamically pass which checkbox we want to click, rather than having two separate methods performing the same action?
The only way I can think to do this is by passing a selector as a parameter in the feature step and instantiating the webElement within the step definition method. But that seems like bad practice to me.
Click is your step. It should not be unique for each item you may want to click. You should match what you want to click with a regular expression. The following combines your two steps into one.
#When("^Click (.*)$")
public void clickElement(String elementToClick) {
switch (elementToClick) {
case "checkBoxA":
pageObject.checkBoxA.click();
case "checkBoxB":
pageObject.checkBoxB.click();
}
}
I'd suggest using a smarter regex match (this one is lazy and sloppy) and you could also create a new variable for the element to be clicked, assign its value to your existing element in each case and have a single call to click() after the switch statement.
Regarding your question of doing this "dynamically," you cannot do so in Java (I think you were thinking of having a single line in the example I gave above of pageObject.elementToClick.click();?) because it's a compiled programming language; your code can't be altered at runtime.
I would prefer to use #mike's solution, but in some cases I tend to create a locator as string in POM so that it reduces lines of code in the step definition.
Feature File:
Scenario: Click all the boxes
Given On the checkbox page
When Click checkbox A
And Click checkbox B
POM:
private String checkBox = "//input[text()='checkBox%s']";
Step Definition:
#When("Click checkbox (.*)")
public void handleCheckBox(String checkBoxName) {
driver.findElement(By.xpath(String.format(checkBox, checkBoxName))).click();
}

calling a test case within a test case in SOAP UI

I am trying to call a test case within a test case using SOAP UI Pro. I created a reusable test case to generate a random VIN and intend to call this test case within other test case where applicable. I used property transfer, but I am unable to set the property in the test case to the value being returned.
I created a test case, wrote a groovy script, added a property to the test case and added a property transfer.See picture
I have been unable to set the property vin (highlighted) as shown in the picture. Any help would be appreciated.
I think this works with "DataGen" option.Lets say you have 2 testcases TC1 and TC2 Right click on TC1-> choose DataGen and add a property, write the groovy script for generating the random VIN.
Go to the TC2 where you want to reuse the VIN, right click on the property name and click on "get data" ->TC1->property name.
https://www.soapui.org/data-driven-tests/reference/datagen-teststep.html

How to use variable, which value should be set in keyword or test, in XPATH?

I need to click on element based on what value it contains..but I want to set this value in test run or keyword definition (best option is in the test I guess)
How should I do it?
the variable containing xpath should look like that:
${DROPDOWN ITEMS} xpath=//*[contains(#class,'listitem-element')]/span[contains(text(),'${second_number}')]
This locator works when I replace the variable with actual number like '002', but I want to have it more general..
In keyword definition I use it like:
Choose Value From Dropdown
focus ${DROPDOWN ITEMS}
click element ${DROPDOWN ITEMS}
and in test I just call the keyword
my question is where and how to set the variable value of ${second_number} variable used in xpath?
PS:the xpath definition, keyword and test are each in separate files
thank you!
I use similar approach in my SUT, as it works with fairly complex objects, both precreated and dynamically generated during the tests executions - and their main user-identifiable attribute is the displayed name. Here's simplified version of my flow, and it's based around string substitution.
Starting off from the variables file - a simple collection of selenium locators, the value of the locator has a "special" string, which will later be substituted:
*** VARIABLES ***
${DROPDOWN ITEMS} xpath=//*[contains(#class,'listitem-element')]/span[contains(text(),'SELENIUM_PLACEHOLDER_CHANGE_ME')]
Then, in the keyword files there are private keywords for returning the proper locators, for example for this one:
*** KEYWORDS ***
_Return Selenium Locator For The Dropdown Item Named
[Documentation] Verifies the desired dropdown item is valid, ando returns its locator (not Webelements!!)
[Arguments] ${name}
# change the placeholder with the actual UI name
${loc}= Replace String ${DROPDOWN ITEMS} SELENIUM_PLACEHOLDER_CHANGE_ME ${name}
# why? Rationale explained below
Element Should Be Visible ${loc} message=The dropdown does not have an item called ${name}
[Return] ${loc}
Why the visibility check? Simple - to fail as early as possible if there's no such object currently in the SUT, and to have uniform error message, independent of how is the element further used (clicked on, checked for presence, attribute retrieval, etc.)
Then, a follow up user keyword for performing actions on the element uses the previous one:
# the user keywords
Choose Value From Dropdown
[Documentation] It does what it does :)
[Arguments] ${the value}
${loc}= _Return Selenium Locator For The Dropdown Item Named ${the value}
# as you can see, no checks is the element real - that'she offloaded to the helper keyword ^
Focus Element ${loc}
Click Element ${loc}
Finally, the test cases use the keyword to work with any data you deem neaded:
*** TESTCASE ***
The dropdown should do X
[Documentation] Steps: 1, 2, 3, etc
# do the normal steps you'do do
Choose Value From Dropdown my current value
This approach applies fairly well for negative tests also - for example, to check a value is not present, a test case would contain:
Run Keyword And Expect Error The dropdown does not have an item called no_such_element Choose Value From Dropdown no_such_element
Thus we're both using selenium checks for the absence of the element, and keeping the test case close to real-life expression - a description of what should happen, with no special syntax and SE keywords.
please excuse any typos and minor syntax omissions - it's not easy to type on a mobile that much, next time I'd think twice before taking it on :D
You can define variables when you fire off your test suite by using arguments.
Here is the documentation for it
Right now, you would leave your xpath as it is. Keeping the ${second_number} inside. Now you can either define it within the argument or within the argument file. They do the exact same thing, but one is neater. Just to get it working I would just worry about putting it directly in the console.
pybot -v second_number:002 nameOfTestFile.robot
This will tell pybot to create a variable called ${second_number} with the value of 002. It does not save this inside the test, so after the test is completed, it will forget the variable.
Once this works, you can then move this into a Argument file Or if you want you can even define it inside a Variable file where you can store all of your variables and then call them within the argument file / within the console.
Any questions do ask and ill try to help out
how about using the set suite variable keyword?
we can use Evaluate keyword for framing dynamically changing xpath
*** Variable ***
${common xpath} xpath=//label[contains(text(), '{0}')]
${text to be replaced} my name
*** Keyword ***
Frame xpath based on user input
${final xpath} Evaluate "${common xpath}".format("${text to be replaced}")
log ${final xpath}
RESULT
In ${final xpath}, you will have the "xpath=//label[contains(text(), 'my name')]"

phpunit assert that the element has a value

I'm using phpunit for the Yii framework. Tried creating a functional test. How to test that the existing element or label has a value.
I have read that
$this->assertQuery('input#valid_from[value=""]',1);
is used to check for empty values. But in my case I want to check that a label or readonly field has value.
I finally got the answer from http://phpunit.de/manual/3.1/en/selenium.html,
I have to use assertElementValueEquals(string $locator, string $text) or assertElementValueNotEquals(string $locator, string $text).