Second scenario doesn't run if first fails in selenium java - java

I have a selenium test case with multiple scenario's. I have a problem if the first one fails it doesn't run the second scenario properly. It does show the error for the first one failing. The one following it will just show all green check marks without starting up the UI tests. In the example below Bob has an error (throws an exception), but Sandra has never even started up the browser and it still shows like she has passed.
Abstract Scenario: I should be able to login
Given I log in with user with the login '<username>'
And I give the password '<password>'
Then I am logged in
Example:
| username | password |
| Bob | easyPassword|
| Sandra | hardPassword |
Does anyone know how to make the second scenario show the proper results instead of showing it like it passed? It is important because it's helpful to know one which exact scenario the test has failed.

Related

Using Cucumber examples data in "scenario outline" line, not in a step, data isn't read and column marked as unused

When I use table column in "scenario outline" line in cucumber feature file, not in any step, using java and intellij-idea such as the following:
Scenario Outline: my test <lastname>
Given Customer Ask Chatbot "My name is <fname>"
When Verify Chatbot responses contain
"""
Hello <fname>!
"""
Then Customer clicks on "Yes"
Examples:
| fname | lastname |
| ahmed | amir |
| saad | sameh |
| mohamed | morad |
"fname" is acting normal, but "lastname" column is marked as unused, as it is only used in the "scenario outline" line and not in any step.
My question is, does this happen with you? and if so, is this the intended behavior? or is it an issue that needs to be reported and fixed? and if so, is it a problem within intellij or cucumber or something else?
Thank you
There's an open ticket for this issue in IDEA: https://youtrack.jetbrains.com/issue/IDEA-261249, you can vote for it
Most likely, the feature file is not placed in "expected" (by Intellij) place.
Put it under resources folder.
To have a correct display in Intellij, sometimes it is needed to mark that directory as "test resources root"
there is also a small timeout to display the column as "used"

navigate between features scenarios in cucumber

I have two gherkin file the
first do the login with multiple user
and the second create multiple patient
here is my gherkin files:
Scenario Outline: User Login
Given user is on login page
When user enters username and password from line <RowNumber> and clicks login
Then check if login with data from line <RowNumber> was successful
Examples:
| RowNumber |
| 0 |
| 1 |
| 2 |
Scenario Outline: Patient Creation
Given user is on the creation page of the application
When user enters patient information from row <RowNumber>
Then user checks that displayed errors are the same as row <RowNumber>
Examples:
| RowNumber |
| 0 |
| 1 |
| 2 |
what I want is that when login with the first user I want to go to other scenario patine creation and create the 3 line and do the same with the 2 - 3 user
Test cases from scenarios should cover the appliaction and make it "safe". You can do the programing and just create sepparate method, or call the existing one that is transfered from gerkin into your step definitions.
Like inside of method "user enters username and password from line and clicks login", you can call method from other step definition file like "user enters patient information from row " (not same text of method in step definition as in feature file).
But that should not be the case, remember you will count your scenarios for report, there is no magic trick you can do about it, can go with multiple assertions, but that is not recommended.
The real question is do you need that structure of scenarios and .feature files or you could write them in a better way. If can not, leave them as they are, you will not lose much on execution time.

Context variable is null in tMysqlInput query

I have a problem with my job when I want to make a query with 2 context variables. I attached photos with my job and my components and when I run the job, it's giving me this error:
Exception in component tMysqlInput_1 (facebook_amazon_us)
java.lang.NullPointerException
at mava.facebook_amazon_us_0_1.facebook_amazon_us.tWaitForFile_1Process(facebook_amazon_us.java:2058)
at mava.facebook_amazon_us_0_1.facebook_amazon_us.tMysqlConnection_1Process(facebook_amazon_us.java:798)
at mava.facebook_amazon_us_0_1.facebook_amazon_us.runJobInTOS(facebook_amazon_us.java:5363)
at mava.facebook_amazon_us_0_1.facebook_amazon_us.main(facebook_amazon_us.java:5085)
What I want to do in this job: I have a csv file with multiple columns. The first one is called Reporting_Starts. I want to get the first registration from that column and put it in the query for a select like:
SELECT * FROM my_table WHERE MONTH(my_table.Reporting_Starts)='"+context.month+"'.
I cannot get why my tJava_4 sees the variables and tMysqlInput don't.
In my tJava_4 I have the following code:
System.out.println(context.month);[My job][1][after running the job][1][tJava_3][1][tJavaRow_1][1][tMysqlInput_1 query][1]
Please let me know if you need any additional information about the job.
Thanks!
With all the iterate links you have, I'm guessing the code isn't executing in the order you expect. Could you please make the following changes:
Remove all the iterate links from tFileList_1
Reorganize your jobs as :
tMysqlConnection_1
|
OnSubjobOk
|
tWaitForFile_1
|
Iterate
|
tFileList_1 -- Iterate -- tJava_3
|
OnSubjobOk
|
tFileInputDelimited_1 -- Main -- tJavaRow_1
|
OnSubjobOk
|
tMysqlInput -- tMap -- tMysqlOutput (delete mode, set a column as delete key)
|
tFileInputDelimited -- tMap -- tMysqlOutput (insert csv)
|
OnSubjobOk
|
tFileCopy
First test with just this part. Then if it works, you can add the rest of your job.

How to use nested Scenario Outline in Cucumber java

2suppose i have a Scenario Outline like
#Scenario1
Scenario Outline:Scenario one
Given fill up login fields "<email>" and "<password>"
And click the login button
Examples:
| email | password |
| someEmailAddress | SomePassword |
| someEmailAddress2| SomePassword2 |
and another Scenario like
#Scenario2
Scenario Outline:Scenario two
Given fill up fields "<value1>" and "<value2>"
Examples:
| value1 | value2 |
| value11 | value21 |
| value12 | value22 |
How could i run scenario like login with 'someEmailAddress' and fill up with all scenario2 value and then login with 'someEmailAddress2' and do the same.
Cucumber scenarios are tools we use to describe behaviour i.e. what is happening and why its important. They are not tools to program tests. The way to use Cucumber effectively is to keep your scenarios simple, and let code called by step definitions do your programming for you.
Step definitions and the methods they call are written in a programming language. This gives you all the power you need to deal with the details of how you interact with your system.
The art of writing Cucumber scenarios is for each one to talk about
The state we need setup so we can do something (Givens)
Our interaction (When)
What we expect to see after our interaction. (Then)
So for your scenario we have
Scenario: Login
Given I am registered
When I login
Then I should be logged in
When we make this scenario work our program has the behaviour that we can login. So then we can use that behaviour in other scenarios e.g.
Scenario: See my profile
Given I am logged in
When I view my profile
Then I should see my profile
Now to make this work we might need a bit more work because this scenario doesn't have a registered user yet. We can deal with this in a number of ways
1) Add another Given, perhaps in a background
Background:
Given I am registered
Scenario ...
Given I am logged in
2) We can register in the login step e.g.
Given "I am logged in" do
#i = register_user
login_as user: #i
end
Notice how in this step we are calling helper methods register_user and login_as to do the work for us.
This is the way to start using Cucumber. Notice how my scenarios have no mention of how we login, no email, no password, no filling in anything. To use Cucumber effectively you have to push these details down into the step definitions and the helper methods they call.
Summary
Keep you scenarios simple and use them to describe WHAT and explain WHY. Use the step definitions and helper methods to deal with HOW. There is no need to use Scenario Outlines when using Cucumber and you should never be nesting them.
There is no support for nested scenario outline in cucumber. but you can use following way to overcome it.
Scenario Outline:Scenario one and two
Given fill up login fields "<email>" and "<password>"
And click the login button
And fill up fields "<value1>" and "<value2>"
Examples:
| email | password | value1 | value2 |
| someEmailAddress | SomePassword | value11 | value21 |
| someEmailAddress | SomePassword | value12 | value22 |
| someEmailAddress2| SomePassword2 | value11 | value21 |
| someEmailAddress2| SomePassword2 | value12 | value22 |

How to verify all elements on the page?

I want to verify if all needed elemants exist on the page.
I can list them in the Examples section for Scenario Outline. For example:
Scenario Outline: I am able to see all elements on My Page
When I am on my page
Then I should see the following <element> My Menu
Examples:
| element |
| MENU button |
| MY logo |
| MY_1 link |
| MY_2 link |
| Button_1 button |
| Button_2 button |
| Loggin button |
Each row runs a separate method to verify an element's presence on the page. The problem is - the page is reloaded.
How can the problem be solved in more appropriate way?
You don't need a scenario outline. You just need a step that verifies all the elements in the table.
Scenario: I am able to see all elements on My Page
When I am on my page
Then I should see the following elements in My Menu
| MENU button |
| MY logo |
| MY_1 link |
| MY_2 link |
| Button_1 button |
| Button_2 button |
| Loggin button |
Where you can use the table as a array of arrays:
Then(/^I should see the following elements in My Menu$/) do |table|
table.raw.each do |menu_item|
#my_page_object.menu(menu_item).should == true
end
end
When(/^I am on my page$/) do
#my_page_object = MyPageObject.new(browser)
end
First of all using a scenario outline will result in 1 scenario for each element you want to test. This has huge run-time costs, and is not the way to go.
Secondly putting all this information in the scenario is also very expensive and unproductive. Gherkin scenarios are supposed to talk at the business level, not the developer level, so I would rewrite this as
Scenario: I am able to see all elements on Foo page
When I am on foo page
Then I should see all the foo elements
and implement it with something like
Then "I should see all the foo elements" do
expect(should_see_all_foo_elements).to be true
end
and now you can make a helper module to make this work
module FooPageStepHelper
def should_see_all_foo_elements
find('h1', text: /foo/) &&
...
end
end
World FooPageStepHelper
Now when the foo page gets a new element, you only have to change one line in one file. Notice how the business need (that all the elemnts should appear on the page) doesn't change when you add or remove elements
(n.b. you could improve the helper function in a number of ways to get better info when something goes wrong, and even output listing the elements that are present)

Categories