Asserting a null value via a Scenario outline - cucumber

I am trying to assert a JSON response null value via the feature file below
Scenario Outline: GET incident notifications
Given I made a GET request for incident notifications for the "<incident>"
Then I should be able to see "<NotificationID>", "<DateTime>", "<ActionID>", "<Subject>", "<CreatedBy>","<Notes>"
Examples:
| incident |NotificationID|DateTime |ActionID|Subject |CreatedBy|Notes|
| 399 | 211 |2017-11-28T14:30:11.01|0 |Logged with Openreach| | |
| 400 | 2112 |2017-11-28T14:35:11.01|1 |Processed at Openreach|Agent | AgentNotes |
this is my step definition-
assertThat(webModel.getRestServices().response.getBody().path("CreatedBy[0]"),is(CreatedBy));
assertThat(webModel.getRestServices().response.getBody().path("Notes[0]"),is(Notes));
this is the error assertion error i get-
java.lang.AssertionError:
Expected: is ""
but: was null
I could get this thing working by asserting to nullValue() however, the 2nd run will fail as it has to take the parameter from the feature file.
any help would be greatly appreciated.

When we give any parameter as blank in the feature file, its taken as null. That's the reason you are getting this error as it is comparing null with a String.
We can solve this problem by doing a null or empty check before the assert. If the value is null, it would skip the assertion otherwise it will assert.

Related

Pushing Results to KiwiTCMS using RobotFramework Ride Issue

I am trying to get Robotframework(Ride) work with KiwiTCMS.
I am making the connection to the KIWI server (local) but I am getting these errors that I am not sure where(In RIDE? or the .conf file?) to fix:
[ ERROR ] Calling method 'start_suite' of listener 'zealand.listener.KiwiTCMS' failed: ENVIRONFILE Version value not defined, missing one of TCMS_PRODUCT_VERSION, TRAVIS_COMMIT, TRAVIS_PULL_REQUEST_SHA or GIT_COMMIT
[ ERROR ] Calling method 'end_test' of listener 'zealand.listener.KiwiTCMS' failed: TypeError: 'NoneType' object is not subscriptable
TestKiwiRide | PASS |
------------------------------------------------------------------------------
KiwiTest.TestKiwi | PASS |
1 test, 1 passed, 0 failed
==============================================================================
KiwiTest | PASS |
1 test, 1 passed, 0 failed
==============================================================================
Output: C:\Users\hendri\Documents\KiwiTest\output.xml
Log: C:\Users\hendri\Documents\KiwiTest\log.html
Report: C:\Users\hendri\Documents\KiwiTest\report.html
(kiwi-env) C:\Users\hendri\Documents\KiwiTest>
Please assit?
Details goes into the bat file you use to call the test cases
check here : https://kiwitcms.readthedocs.io/en/stable/plugins/automation-frameworks.html
In plugin configuration section, you have to passe configuration as environment variables. e.g.
export TCMS_PLAN_ID=*PLAN_ID*

Katalon Posibble to assert response = data?

I store json test data in excel file.
Make use of apache POI to read the json data and parse it as request body, call it from katalon.
Then I write many lines of assertion (groovy assert) to verify each line response = test data.
Example:
Assert test.responseText.fieldA == 'abc'
Assert test.responseText.fieldB == 'xyz'
And so on if I have total of 20 fields.
I'm thinking of there is better way to make use of the json data stored in data file.
To assert the response = test data. So I can save alot of time to key in each line and modify them is the test data changed.
Please advise if this can be achieved?
Here is an example: you have two excel sheets - current values and expected values (values you are testing against).
Current values:
No. | key | value
----+-----+------
1 a 100
2 b 6
3 c 13
Expected values:
No. | key | value
----+-----+------
1 a 100
2 b 6
3 c 14
You need to add those to Data Files:
The following code will compare the values in the for loop and the assertion will fail on the third run (13!=14):
def expectedData = findTestData("expected")
def currentData = findTestData("current")
for(i=1; i<=currentData.getRowNumbers(); i++){
assert currentData.getValue(2, i) == expectedData.getValue(2, i)
}
Failure message should look like this:
2020-07-02 15:16:40.471 ERROR c.k.katalon.core.main.TestCaseExecutor - ❌ Test Cases/table comparison FAILED.
Reason:
Assertion failed:
assert currentData.getValue(2, i) == expectedData.getValue(2, i)
| | | | | | |
| 14 3 | | 13 3
| | com.kms.katalon.core.testdata.reader.SheetPOI#5aabbb29
| false
com.kms.katalon.core.testdata.reader.SheetPOI#72c927f1

ArangoDB AQL: LOWER not working for value of slice?

I try following :
FOR d IN cresume FILTER d.isActive==true AND d.isPublic==true AND 'javascript' IN LOWER(d.resume.skills[*].name) SORT d.activatedTS DESC LIMIT 200 RETURN d
idea is to check if (lowercase) javascript is in skills[*] name. This don't find Result. If I do:
FOR d IN cresume FILTER d.isActive==true AND d.isPublic==true AND 'JavaScript' IN d.resume.skills[*].name SORT d.activatedTS DESC LIMIT 200 RETURN d
I get the result
Question... Is LOWER not working on a value from an [*] Array/Slice ?
Got info from Arango Support. As documented, LOWER works on strings. But instead of LOWER(d.resume.skills[*].name) you can use d.resume.skills[* RETURN LOWER(CURRENT.name)]

pywinatuo - Access Database Match Error for the same property - Code works on a small database not on a large one

I am trying to run some access queries using pywinauto. The error Constantly changes.
After checking the control properties i found that the query name does exist. However the the code throws an error stating match not found.
import os
import subprocess
access_file = r'C:\Ren'
filename='test.accdb'
accessPath = 'C:\Program Files (x86)\Microsoft Office\Office15\MSACCESS.exe'
subprocess.Popen([accessPath,access_open])
dlg=Desktop(backend='uia').window(title_re='Access*')
sleep(10)
dlg.Navigation_Pane.Queries.Query1.invoke()
dlg.Yes.invoke()
print(dlg.print_control_identifiers())
This code works on a smaller database. I Tried it 1st on a large database and got errors so i created a test database with few tables and queries. It works fine.
When i change dlg.Navigation_Pane.Queries.delete_reports.invoke()
and change the path to the actual database. I get a MatchError: Could not find 'Queries'.
This is the control properties.
GroupBox - 'Queries' (L4, T2979, R429, B5581)
| | | | ['Queries', 'QueriesGroupBox', 'GroupBox8', 'Queries0', 'Queries1']
| | | | child_window(title="Queries", control_type="Group")
Button - 'delete report' (L4, T3271, R429, B3301)
| | | | | ['Button147', 'delete reportButton', 'delete report']
| | | | | child_window(title="delete report", control_type="Button")
I am unable to understand why does it one work on one database and does not on the other.
Regards,
Ren.

Behave: Writing a Scenario Outline with dynamic examples

Gherkin / Behave Examples
Gherkin syntax features test automation using examples:
Feature: Scenario Outline (tutorial04)
Scenario Outline: Use Blender with <thing>
Given I put "<thing>" in a blender
When I switch the blender on
Then it should transform into "<other thing>"
Examples: Amphibians
| thing | other thing |
| Red Tree Frog | mush |
| apples | apple juice |
Examples: Consumer Electronics
| thing | other thing |
| iPhone | toxic waste |
| Galaxy Nexus | toxic waste |
The test suite would run four times, once for each example, giving a result similar to:
My problem
How can I test using confidential data in the Examples section? For example, I would like to test an internal API with user ids or SSN numbers, without keeping the data hard coded in the feature file.
Is there a way to load the Examples dynamically from an external source?
Update: Opened a github issue on the behave project.
I've come up with another solution (behave-1.2.6):
I managed to dynamically create examples for a Scenario Outline by using before_feature.
Given a feature file (x.feature):
Feature: Verify squared numbers
Scenario Outline: Verify square for <number>
Then the <number> squared is <result>
Examples: Static
| number | result |
| 1 | 1 |
| 2 | 4 |
| 3 | 9 |
| 4 | 16 |
# Use the tag to mark this outline
#dynamic
Scenario Outline: Verify square for <number>
Then the <number> squared is <result>
Examples: Dynamic
| number | result |
| . | . |
And the steps file (steps/x.step):
from behave import step
#step('the {number:d} squared is {result:d}')
def step_impl(context, number, result):
assert number*number == result
The trick is to use before_feature in environment.py as it has already parsed the examples tables to the scenario outlines, but hasn't generated the scenarios from the outline yet.
import behave
import copy
def before_feature(context, feature):
features = (s for s in feature.scenarios if type(s) == behave.model.ScenarioOutline and
'dynamic' in s.tags)
for s in features:
for e in s.examples:
orig = copy.deepcopy(e.table.rows[0])
e.table.rows = []
for num in range(1,5):
n = copy.deepcopy(orig)
# This relies on knowing that the table has two rows.
n.cells = ['{}'.format(num), '{}'.format(num*num)]
e.table.rows.append(n)
This will only operate on Scenario Outlines that are tagged with #dynamic.
The result is:
behave -k --no-capture
Feature: Verify squared numbers # features/x.feature:1
Scenario Outline: Verify square for 1 -- #1.1 Static # features/x.feature:8
Then the 1 squared is 1 # features/steps/x.py:3
Scenario Outline: Verify square for 2 -- #1.2 Static # features/x.feature:9
Then the 2 squared is 4 # features/steps/x.py:3
Scenario Outline: Verify square for 3 -- #1.3 Static # features/x.feature:10
Then the 3 squared is 9 # features/steps/x.py:3
Scenario Outline: Verify square for 4 -- #1.4 Static # features/x.feature:11
Then the 4 squared is 16 # features/steps/x.py:3
#dynamic
Scenario Outline: Verify square for 1 -- #1.1 Dynamic # features/x.feature:19
Then the 1 squared is 1 # features/steps/x.py:3
#dynamic
Scenario Outline: Verify square for 2 -- #1.2 Dynamic # features/x.feature:19
Then the 2 squared is 4 # features/steps/x.py:3
#dynamic
Scenario Outline: Verify square for 3 -- #1.3 Dynamic # features/x.feature:19
Then the 3 squared is 9 # features/steps/x.py:3
#dynamic
Scenario Outline: Verify square for 4 -- #1.4 Dynamic # features/x.feature:19
Then the 4 squared is 16 # features/steps/x.py:3
1 feature passed, 0 failed, 0 skipped
8 scenarios passed, 0 failed, 0 skipped
8 steps passed, 0 failed, 0 skipped, 0 undefined
Took 0m0.005s
This relies on having an Examples table with the correct shape as the final table, in my example, with two rows. I also don't fuss with creating new behave.model.Row objects, I just copy the one from the table and update it. For extra ugliness, if you're using a file, you can put the file name in the Examples table.
Got here looking for something else, but since I've been in similar situation with Cucumber before, maybe someone will also end up at this question, looking for a possible solution. My approach to this problem is to use BDD variables that I can later handle at runtime in my step_definitions. In my python code I can check what is the value of the Gherkin variable and map it to what's needed.
For this example:
Scenario Outline: Use Blender with <thing>
Given I put "<thing>" in a blender
When I switch the blender on
Then it should transform into "<other thing>"
Examples: Amphibians
| thing | other thing |
| Red Tree Frog | mush |
| iPhone | data.iPhone.secret_key | # can use .yaml syntax here as well
Would translate to such step_def code:
#given('I put "{thing}" in a blender')
def step_then_should_transform_into(context, other_thing):
if other_thing == BddVariablesEnum.SECRET_KEY:
basic_actions.load_secrets(context, key)
So all you have to do is to have well defined DSL layer.
Regarding the issue of using SSN numbers in testing, I'd just use fake SSNs and not worry that I'm leaking people's private information.
Ok, but what about the larger issue? You want to use a scenario outline with examples that you cannot put in your feature file. Whenever I've run into this problem what I did was to give a description of the data I need and let the step implementation either create the actual data set used for testing or fetch the data set from an existing test database.
Scenario Outline: Accessing the admin interface
Given a user who <status> an admin has logged in
Then the user <ability> see the admin interface
Examples: Users
| status | ability |
| is | can |
| is not | cannot |
There's no need to show any details about the user in the feature file. The step implementation is responsible for either creating or fetching the appropriate type of user depending on the value of status.

Resources