testng-opening multiple browsers for scenario examples - automation

I have this feature file
Scenario Outline:
Given User is on my website
When User is Admin or Mastering Editor
3.And User is on /page/ page
4.And User click /header/ link
5.Then User should be taken to /target page/
Examples: Of page, header and target
| page | header | target page |
| Homepage | Master | Master page |
| Homepage | Translation | Translation page |
For "Given User is on my website"
I wrote the login details, and this is opening new browser for every example in scenario.
I want single browser to open and do all examples.
can anyone help please

Follow these steps:
Create one driver class with initialization, closing and some common driver related methods
Create your step definition file with extends this driver class.
Create before class method to initialize the driver
every step will be using the same opened browser
so every feature file one browser will be initialized.
public class PersonSteps extends DriverHelper

Related

Cucumber: loop over only part of the Scenario

is there any possibility to loop part of the scenario instead of all steps.
Below I have prepared an example, I want to login and click a list of links, but I want to execute the login-part only once. After logging the clicking part should be looped.
Scenario Outline
Given I am on Homepage
When I enter Email and Password and press send
And I am logged in
*And I click the link <link>
Examples:
| link1 |
| link2 |
| link3 |
| link4 |*
You should split your scenario in that case. Make the login as a scenario, do not close your driver in between scenarios. Now make the I click the link as a scenario outline in the same feature file.

How to use data table in background in cucumber

I want to execute common steps for few test cases.below are the common steps.But in background,since i cannot use Scenario Outline,what is the alternate?
Background:To test employee id search
Scenario Outline:
Given I am on login Screen
When I enter credentials "<User_ID>" and "<Password>"
When I clicks on search button
And search by "<Employee_id>"
Examples:
|User_ID|Password |Employee_id|
|Admin |Password | Q58ewQ |
A scenario outline is a way to run several scenarios whilst writing just a single scenario. Background is a set of steps to run before each scenario. You can't put an outline in a background, it makes no sense.
A Background is used for steps that will be run before each Scenario (or Example) in the feature file.
Each Scenario Outline will run as a separate Scenario / Example.
You cannot use Scenario Outline inside a Background, as that would make no sense.
Please check the links to the documentation for more information.
This is example is very imperative, BDD need to be declarative. Best Pratices BDD
Why do you create one method that do login.
Login(username, password){
set username = username;
set password = password;
clickButton;
}
And create one step.
Given the user logged on the system
login(username, password)
This is step do you use with background.
You can use Data Table in Cucumber Background :
Background:
Given User is on Home Page
When User Navigate to LogIn Page
And User enters Credentials to LogIn
| testuser_1 | Test#153 |
You can use a table in Cucumber Background:
Background:
Given I open Google's search page
When I use the following keywords to search in the Google's search page:
| CucumberBDD |
| CucumberHooks |

Can we use scenario outline for background steps

I am using POM with cucumber. I have 3 scenarios to execute where half of the steps are common for all the scenarios. So I am using background keyword for common steps. But I need to pass data through Example keyword to the steps defined in Background as well. How do I do it?
Below is my background
Given User is on login Screen
When user enters "<User_ID>" and "<Password>"
Then verify successfull login
When user clicks on search button
And search by "<reference_number>"
Examples:
| User_ID | Password |reference number |
| Abc | XYZ |ABC123 |
You are not able to pass example data from a scenario outline to the background. You will need to include those parameterized steps in the scenario outline rather than the background. If one step depends on another, they are probably stuck repeating steps in each scenario.

How to write scenario to verlify a list of values displayed?

How to write a gherkin scenario in which the user clicks on a menu button and he should see a list of sub-menus displayed.I tried:
Scenario Outline:Display of the login page
Given User is an admin
When user clicks on the menu
Then he should see the <list> displayed
Examples:
| list |
| loginform, UsernameField, PasswordField |
Your description of the scenario and the scenario itself contradict each other. You write about sub-menus, the scenario lists fields. As the very first step, discuss the scenarios with your colleagues. When you have a clear plan, you can take on the syntax.
Syntax: why would you use a Scenario Outline when you only have a single example?

How to use Selenium IDE to verify web service test form response

I have a webservice with a test form:
I want to test the webservice and verify the response but the response opens in a new window. Is there any way using Selenium IDE to check the output in the newly opened window?
Update: the webservice test form does a POST with target="_blank" which results in the response being loaded into a new tab in Firefox. The response from the webservice is an xml document so many of the standard Selenium IDE commands that rely on a HTML Document will not work. I've found the assertTextPresentXML extension but I can't select the newly opened tab because it doesn't have a name, id, or title that I can access.
You can use selectWindow command and specify title of newly opened window (if this title differs from initial window):
selectWindow | title=New window title
Title can be retrieved from html>head>title. If it doesn't work you can try something like that:
getEval | selenium.browserbot.findElement('locator_of_invoke_button').target='my_window'
getEval | window.open("", "my_window")
click | locator_of_invoke_button
selectWindow | my_window
waitForElementPresent | locator_of_element_at_new_window