Data Driven testing - webdriver-io

I am currently working on deciding a tool for automation an app on react/redux platform.
Most of the scenarios that I have in the app is possible to automate using webdriver io.
There are certain test cases or scenarios which repeat itself for different data sets.
For eg.
Steps to be executed:
Login to the application
Enter search criteria Step
Enter Color 1, Color 2, Color 3
Save and Validate
Test Data:
|UserName|Password|Search Criteria|Color 1|Color 2|Color 3|
|abc | abc | search 1 |red | | |
|abc | abc | search 1 | |green | |
|abc | abc | search 2 |grey |white | |
|abc | abc | search 3 |white |black | yellow|
I have to execute the same set of code/steps multiple times depending the number of rows of test data we have.
I tried reading a lot of documentations but could not find any package which supports this type of automation in webdriver io.

I've succesfully used the code in this package https://github.com/gburghardt/jasmine-data_driven_tests
it allows to write data driven tests using 2 functions all & using
Here is an example that you can find in the github page:
all("blank values are invalid",
[
"",
null,
undefined
],
function(value) {
expect(isEmpty(value)).toBe(true);
}
);

Related

Passing Data from a Data Table in the feature file to my step definitions (js)

I'm trying to pass Data from a table into a feature file and then finally onto my java script step-definitions, shown below.
Scenario: XX | Basket Tests: Cover Type | Building + no bundle + HE
Given I open the page with the url "http://localhost:3000" and route "/basket"
When I click the button <coverTypeID>
And I click the button <bundleID>
Then I see the result <expectedResult>
| id | url | coverTypeID | bundleID | elementID | expectedResult |
| 1 | http://localhost:3000/basket | coverTypeId101 | NoBundle | null | |
| 2 | http://localhost:3000/basket | coverTypeId101 | NoBundle | checkbox1 | |
| 3 | http://localhost:3000/basket | coverTypeId101 | NoBundle | checkbox2 | |
| 4 | http://localhost:3000/basket | coverTypeId101 | NoBundle | checkbox3 | |
| 5 | http://localhost:3000/basket | coverTypeId101 | NoBundle | checkbox4 | |
Is my Feature file, i used to pass data using strings however now i am using the data table it doesn't identify the scenario when the tests run.
When("I click the button <coverTypeID>", (buttonID, next) => {
driver.findElement(By.id(buttonID)).then(pageElement => { /////////////////////////////////////////////
driver.wait(until.elementIsVisible(pageElement), 10000).then(async () => { //This is to click a button using elementID//
await driver.sleep(3000); /////////////////////////////////////////////
pageElement.click();
next();
})
.catch(ex => {
console.log(ex.message, ex.stack)
});
}).catch(ex => {console.log(ex.message, ex.stack)});
});
The error i'm getting is that the tests are undefined as the scenario doesn't match the step definition properly because of the usage of the table titles
I've looked at using Regular Expressions however i'm not sure what type of data the data table passes when executing, any guidance would be of use, i've went through a bunch of different questions and none quite seem to answer mine.
Any help would be greatly appreciated, i'd like to avoid regular expression if i could because the aim is to make the code as readable as possible.
Thank you in advance.
so i found the solution, rather than expecting the title of the data table i referred back to using {string}
When("I click the button {string}", (buttonID, next) => {
Then in the data table i realised the mistake i was making was simply not adding quotation marks to make the data into string format.
Examples:
| id | coverTypeID | bundleID | elementID |
| 1 | "coverTypeId101" | "moreDetails1" | "checkbox2" |
By doing this the feature now sucessfully pulls data from the feature file into the JS file.

Cucumber, examples: How can I verify that the value is exact the same as that of in the adjacent column

On the website there are 2 columns...
In my testcase in Selenium, in the examples the values are:
Examples:
| userrol | information 1 | information 2 |
| role 1 | test | rest |
| role 2 | test2 | rest2 |
Now I can test if those values are presented on the website.
but how can I verify that rest2 is the neighbour of test2 ?
and not like this on the website:
| USER | information1 | information2 |
| role 1 | test | rest2 |
| role 2 | test2 | rest |
(It should not only test if it is presented, it should also test that the text in the column next to it is corresponding)
You have to have a containing element in your html so that you can test that test is next to test2 e.g. with
div#row
span#info1 test
span#info2 rest
You could write something with capybara like
expect(page).to have_css('#row info1', text: 'test')
expect(page).to have_css('#row info2', text: 'rest')
If you haven't got another identifiers, css classes or html in your source to do this that simply, you can either modify your source, or use more complex css/xpath queries (google 'css siblings')

Flexibility of scenarios in Gherkin.

I looking for mechanism that will allow to build more flexible scenarios.
For example for these two very similar scenarios that test existence of records in database:
Scenario Outline: Testing query with 1 attribute with these 2 record in and another 2 out of result
Given I'm connected to <db> database
When I select <query> from database
Then Result should contain fields:
| <row> |
| <yes1> |
| <yes2> |
And Result should not contain fields:
| <row> |
| <no1> |
| <no2> |
Examples:
| db | row | yes1 | yes2 | no1 | no2 | query |
| 1 | model | 1013 | 1006 | 1012 | 1007 | "SELECT model FROM pc WHERE speed >= 3.0;" |
| 1 | maker | E | A | C | H | "SELECT maker FROM product NATURAL JOIN laptop WHERE hd >= 100;" |
Scenario Outline: Testing query with 2 attributes with these 2 record in and another 2 out of result
Given I'm connected to <db> database
When I select <query> from database
Then Result should contain fields:
| <rowA> | <rowB> |
| <yes1A> | <yes1B> |
| <yes2A> | <yes2B> |
And Result should not contain fields:
| <rowA> | <rowB> |
| <no1A> | <no1B> |
| <no2A> | <no2B> |
Examples:
| db | rowA | rowB | yes1A | yes1B | yes2A | yes2B | no1A | no1B | no2A | no2B | query |
| 1 | model | price | 1004 | 649 | 2007 | 1429 | 2004 | 1150 | 3007 | 200 | "SELECT model,price FROM product" |
| 2 | name | country | Yamato | Japan | North | USA | Repulse | Brit | Cal | USA | "SELECT name, country FROM clases" |
I would like to be able to write one scenario with general number of attributes. It would be great if number of tested rows will not be determined too.
My dream is to write only one general scenario:
Testing query with N attribute with these M record in and another L out of result
How to do this in Gherkin? Is it possible with any hacks?
The short answer is, No. Gherkin is not about flexibility, Gherkin is about concrete examples. Concrete example are everything except flexible.
A long answer is:
You are describing a usage of Gherkin as a test tool. The purpose with Gherkin is, however, not to test things. The purpose with Gherkin is to facilitate communication between development and the stakeholders that want a specific behaviour.
If you want to test something, there are other tooling that will support exactly what you want. Any test framework will be usable. My personal choice would be JUnit since I work mostly with Java.
The litmus test for deciding on the tooling is, who will have to be able to understand this?
If the answer is non techs, I would probably use Gherkin with very concrete examples. Concrete examples are most likely not comparing things in a database. Concrete examples tend to describe external, observable behaviour of the system.
If the answer is developers, then I would probably use a test framework where I have access to a programming language. This would allow for the flexibility you are asking for.
In your case, you are asking for a programming language. Gherkin and Cucumber are not the right tools in your case.
You can do it without any hacks, but I don't think you want to, at least not the entire scenario in a single line.
You will want to follow BDD structure, else why use BDD?
You should have and follow a structure like:
Given
When
Then
You need to split and have a delimitation between initial context, action(s) and result(s).It will be a bad practice to not have a limit between these.
Also note that a clear delimitation will increase reusability, readability and also help you a lot in debugging.
Please do a research of what BDD means and how it helps, it may help if you have a checklist with best practices of BDD that could also help in code review of the automated scenarios.

cucumber data table multiple seperate iteration

In the following feature file my requirement is to put one doc_id for every three field. To clarify, I want to check ProductName, manufacturerName and RevisionDate for every doc_id. I came up with following method but I think this is definitely not the preferred one. Can anyone suggest me a better way.
Background:
Given I am in landigpage page after login
Scenario Outline: valid
When I enter "<doc_id>"
And I click the search go button
Then I should get in vault search page
And Search result of "<field>" should match with database
Examples:
| doc_id | field |
| 15 | ProductName |
| 15 | ManufacturerName |
| 15 | RevisionDate |
Examples:
| doc_id | field |
| 16 | ProductName |
| 16 | ManufacturerName |
| 16 | RevisionDate |
You can use single examples table:
Background:
Given I am in landigpage page after login
Scenario Outline: valid
When I enter "<doc_id>"
And I click the search go button
Then I should get in vault search page
And Search result of "<field>" should match with database
Examples:
| doc_id | field |
| 15 | ProductName |
| 15 | ManufacturerName |
| 15 | RevisionDate |
| 16 | ProductName |
| 16 | ManufacturerName |
| 16 | RevisionDate |
I don't see any other way to pass arguments the way you need to. That's what I don't like about Cucumber. It is not that flexible.
Bacckground:
Given I am in landigpage page after login
Scenario Outline: valid
When I enter "<doc_id>"
And I click the search go button
Then I should get in vault search page
And the search results should match the database
Examples:
| doc_id |
| 15 |
| 16 |
and to make this work:
When /^I enter "<\w+>"$/ do | doc_id |
#doc_id = doc_id
...
end
Then "the search results should match the database" do
db_results = db.find(#doc_id) # or something similar
... # compare db_results to actual results
end
This still kind of sucks, because you have doc_id's in your Gherkin, you are relying on a prefilled database and you have a scenario outline; but hey lets save that for other questions :)
Hi i guess you guys are confusing Data Tables and scenario outline.
The solution for above is :
Background:
Given I am in landingpage page after login
Scenario Outline: valid
When I enter "<doc_id>"
And I select to navigate to search page
Then Search result of field should match with database
| ProductName |
| ManufacturerName |
| RevisionDate |
Examples:
| doc_id |
| 15 |
| 16 |
The table can easily be converted to a list or a map that you can use in your step.

FitNesse: Test that an element is not in a list?

I'm using FitSharp to test an application and have a question related to testing contents of lists. Testing that an element is present in a list is simple to do using, for example, a SubsetFixture and could be written as this:
| Check that element is in list |
| 5 |
But is there a way to write a fixture that tests if an element is not in a list?
| Check that element is not in list |
| 5 |
I want the last table to pass only if 5 is not in the processed list.
The closest you can come with any kind of list fixture would be to use a array or set fixture and to list ALL of the items you DO expect. There is no "not one of these" list fixtures.
I would recommend you just do a do fixture in one like like:
|check|that element | 5 | is in the list | False |
or you could use a column fixture to get the feel for a set fixture
| Check that element is not in list |
| element | exists? |
| 5 | false |