How to handle or integrate multiple step def files using Cucumber Selenium page factory? - cucumberjs

I have create a page factory framework using Cucumber, Selenium with js.
I have multiple step definition file one is for login and one is for logout.
IF I run single step def file it successfully get automated but when I want to automate first login then after successful login application should logout.
In my first step def file I have provided driver, browser information and in second step def file I have provided only webdriver and browser information.
I am not getting how to link second step def file with first to test end to end functionality.

Related

Cypress - how to best test a multi step flow process

Using an example scenario where a user needs to shop for flights, via these Steps:
Select Outbound Flight, go to next page
Select Return Flight, go to next page
Enter Billing Info, go to next page
On The confirmation page - submit info
Now I know that Cypress is all about building up state programmatically rather than going through the steps via the UI. So for the smoke test would I want to only start the test from Step 4, feed it a previously set state and make sure there is no error upon submit?
Also what about the other pages - would it be ok to have one end to end test that goes through Steps 1-4 purely via the UI?
There are 2 ways of potentially achieving this.
1. Using Rest API in cy.route, More info here: https://docs.cypress.io/api/commands/route.html#Usage
2. If the site appends query parameters to the url e.g. www.flightsight.com/?from=london&to=chicago, you can give this URL in step 4.
If the site uses POST request, then these parameters unfortunately won't be available.

JMeter Web Driver Test randomly fails for some threads

I have a JMeter Web Driver Test plan. Where I have:
a Thread group with 3 users
a Web Driver Sampler,
Firefox Driver Config
and View Results in Tree listener.
Also I have a CSV Data Set Config wherein I have mapped it to a CSV file to receive Username and Passwords.
In the Web Driver Sampler we have just written a Simple code which invokes Firefox browser, passes the url to it, passes Username and Passwords to it.
Then makes a search for a term and logs out.
Once I run this test with 3 users, the test runs fine for first and second user and fails for the third one.
And when I run the test again, First and Third user passes but fails for the second.
When I go and check on the Response message, it says it was unable to locate element.
Whereas it would have ran fine for the next user.
I'm not sure why the test is behaving like this, Can someone Help me on this issue.
Elements may not appear in DOM immediately after WebDriver get() request, I would suggest to add an extra step which will ensure that specified element is present in DOM and may be interacted with prior to clicking/typing by something like:
var pkg = JavaImporter(org.openqa.selenium)
var support_ui = JavaImporter(org.openqa.selenium.support.ui.WebDriverWait)
wait.until(support_ui.ExpectedConditions.presenceOfElementLocated(pkg.By.id('element_id')))
var element=WDS.browser.findElement(pkg.By.id('element_id'))
element.click()
See Using Selenium with JMeter's WebDriver Sampler guide for more details on Selenium scripting in JMeter

Ruby/Cucumber/Capybara Testing Multipart File Uploads

I'm using Cucumber/Capybara to test a web application. I'm pretty much a complete beginner in Ruby and its a real testimony to the developers of Cucumber/Capybara just how far I have been able to test my application with only the miniscule amount of Ruby knowledge that I have.
However, as you've probably guessed, I've reach the point were I need some expert help. I need to test a multipart file upload. The problem is that the web application that I'm testing has a URL command interface, but no associated pages. So I can't just load the page, fill in a parameter and push a button. I have to format the POST command programatically.
Up until now, I have been interacting this the application exclusively using 'visit'. i.e. i have steps definitions such as:
Given /^I delete an alert with alertID "([^"]*)" from the site$/ do |alertID|
visit WEB_SITE_ROOT + "/RemoteService?command=deleteAlert&siteName=#{$Site}&alertID=#{alertID}"
end
But now I need to do some posts. I found some code that seems to do what I need:
Given /^I upload the "([^"]*)" file "([^"]*)" for the alert$/ do |fileType, fileName|
file = File.new(fileName, "rb")
reply = RestClient.post(
"#{WEB_SITE_ROOT}" + "/FileUploader?command=upload&siteName=#{$Site}&alertID=#{$OriginalAlertID}",
:pict => file,
:function => "#{fileType}",
:content_type => 'multipart/jpg',
)
end
But this is not running in the same cucumber/capybara session, and so is not authorised (one of the previous steps was a login). Also, the reply from the web application is not picked up by cucumber/capybara and so my test for success/failure do not work.
Can someone please point me in the right direction?
By default capybara uses the Rack::Test adapter which will bypass the HTTP server and interact with your Rack/your app directly. The POST request you're doing in your step won't go through capybara, hence why it's failing.
To upload files when using Rack::Test you'll need to use the Rails #fixture_file_upload method, which by default should be available in your cucumber steps.

Capybara not finding javascript

I am new to Capybara testing and am having a few issues.
I have a scenario I am trying to run, and this is the step implementation:
When /^I select the signin link$/ do
click_link 'Sign in'
end
I have tried to access this link with xpath, css, and tried the within implementation as well. Capybara cannot seem to find it, and returns a Capybara::ElementNotFound exception in all cases.
When I load the webpage without JavaScript, the link is not visible, and I'm wondering if this is why Capybara cannot find it. I found a trigger method, but am unsure how it works. Does anyone have a working example of trigger, or any other ideas for what I should do?
Are you using the selenium webdriver to run this test? It sounds like you are trying to run a scenario that requires javascript to see certain elements, without using a driver that supports javascript.
In your .feature file all you have to do is add this line before the scenario:
#javascript
Scenario: My Scenario
When blah blah blah
...
The #javascript tag tells capybara to use selenium-webdriver to run the test. It'll fire up firefox and go through the test - allowing all javascript functionality to work. This slows tests down considerably so only use it when absolutely necessary to test ajax-y and javascript-y behavior.
If that still doesn't work you can use this step:
Then show me the page
When I select the signin link
Which will open the page up for you in a new browser in that page's current state for your inspecting pleasure.

watir web testing is not working for sites taking some time to load

With cucumber 0.9.4, Iam testing some websites using Watir ruby gem.
All the testing is working fine but the issue is if the site is taking
some time to load then that site testing is skipped, how to overcome
this issue.
My feature file content is:
Feature: Search
In order to learn more
As an information seeker
I want to find more information
Scenario: Find what I'm looking for
Given I am on the Google search page
When I click on link Services
Then I should see
"""
spriteCloud
"""
My step def. file content is:
Given 'I am on the Google search page' do
#browser.goto 'http://www.spritecloud.com/'
end
When /^I click on link (.*)$/ do |link|
#browser.link(:text, link).click
end
Then /I should see/ do |text|
#browser.text.should =~ /#{text}/m
end
The above code works perfect for site google.com and click on news section
By default, Watir waits for the page to load. Are there asynchronous requests on the page?
For asynchronous requests, Watir will not wait until attempting an action and that could be the reason your tests are failing. In that case, you'll need to wait for the element to load first:
Waiter.wait_until(20) do
browser.text_field(:id, 'customer_id').exists?
end
And then perform the action.

Resources