I have a site that completely differs on the front-end between the mobile and desktop versions.
You cannot scope steps when defining them on Cucumber, so I am stuck with two solutions (as I see):
Write every step that conflicts with the other version, explicitly saying which version I am
Set up a "background" which tells me what is my context, and change all the step definitions to check for this context
None of this seem optimal to me.
Is there a better/cleaner way to do this?
You can use tags and hooks for this, tag each scenario/feature with the version of the site it tests:
#mobile
Scenario: Logging in on mobile
Given I visit the login page
#desktop
Scenario: Logging in on desktop
Given I visit the login page
Use some hooks to set a variable indicating the version of the site being tested:
Before '#mobile' do
#version = :mobile
end
Before '#desktop' do
#version = :desktop
end
Then in your steps:
Given /^I visit the login page$/ do
if #version == :desktop
# Desktop specific code
elsif
# Mobile specific code
else
raise "Don't know what to do!"
end
end
I ended up using a solution similar to Jon M.
For the concurring steps I made a "meta" step, that passes on to the correct context. Here is an example:
When /^I log in$/ do
step %Q{I log in on #{#context}}
end
Then in another file (separated by context) I have:
When /^I log in on mobile$/ do
# do stuff
end
To setup the context, I created a support module. Basically, it keeps the current context and also has a default one, that you can change with a step:
Given /^I am on the "(.*?)" version$/ do |version|
#context = version
end
It's not exactly how I setup the context part, but you get the picture.
The advantage in this, is that I can have infinite contexts and this "meta" steps will pick them up. I also don't have bloated steps. Each step stays simple and only deals with it's own context logic.
The downside is that for each non-default context I have, I need a Background stating that I am on a different context.
I won't accept a right answer here, since there is no such thing. You can deal with it with different approaches and until now, there isn't even a best practice about this :)
Related
I want to have an option on the cucumber report to mute/hide scenarios with a given tag from the results and numbers.
We have a bamboo build that runs our karate repository of features and scenarios. At the end it produces nice cucumber html reports. On the "overview-features.html" I would like to have an option added to the top right, which includes "Features", "Tags", "Steps" and "Failures", that says "Excluded Fails" or something like that. That when clicked provides the same exact information that the overview-features.html does, except that any scenario that's tagged with a special tag, for example #bug=abc-12345, is removed from the report and excluded from the numbers.
Why I need this. We have some existing scenarios that fail. They fail due to defects in our own software, that might not get fixed for 6 months to a year. We've tagged them with a specified tag, "#bug=abc-12345". I want them muted/excluded from the cucumber report that's produced at the end of the bamboo build for karate so I can quickly look at the number of passed features/scenarios and see if it's 100% or not. If it is, great that build is good. If not, I need to look into it further as we appear to have some regression. Without these scenarios that are expected to fail, and continue to fail until they're resolved, it is very tedious and time consuming to go through all the individual feature file reports and look at the failing scenarios and then look into why. I don't want them removed completely as when they start to pass I need to know so I can go back and remove the tag from the scenario.
Any ideas on how to accomplish this?
Karate 1.0 has overhauled the reporting system with the following key changes.
after the Runner completes you can massage the results and even re-try some tests
you can inject a custom HTML report renderer
This will require you to get into the details (some of this is not documented yet) and write some Java code. If that is not an option, you have to consider that what you are asking for is not supported by Karate.
If you are willing to go down that path, here are the links you need to get started.
a) Example of how to "post process" result-data before rendering a report: RetryTest.java and also see https://stackoverflow.com/a/67971681/143475
b) The code responsible for "pluggable" reports, where you can implement a new SuiteReports in theory. And in the Runner, there is a suiteReports() method you can call to provide your implementation.
Also note that there is an experimental "doc" keyword, by which you can inject custom HTML into a test-report: https://twitter.com/getkarate/status/1338892932691070976
Also see: https://twitter.com/KarateDSL/status/1427638609578967047
I started working with behavior driven tool cucumber. Its a fun tool to use. While i was working on a problem. I came across that most of time, I am not reusing my code.
That's why I want to call a scenario from another scenario. I have searched but found nothing helpful. Can I do that ?
Another same question posted here on github
This may be what you're looking for: https://github.com/cucumber/cucumber/wiki/Calling-Steps-from-Step-Definitions
So there are a couple of things you can do. If you have a step you want to reuse like the following:
Given /^I log in as (.*)$/ do |name|
# ...
end
You can call it within another step like so:
Given /^(.*) is logged in$/ do |name|
step "I log in as #{name}"
end
You can also do the following within a step definition:
steps %Q{
Given I log in as #{name}
}
I came to the same question - and found this post. Maybe it is on purpose that you cannot call Scenarios from other Scenarios. The framework is based on that you think about creating practical Stepdefinitions, so they can be used many times. The basis is to think before creating steps...
I created own Steps vor Login-Method, Pagetransitions to search-page or new File etc..
So in many Scenarios i reuse these Steps - and then add new ones (that can be reused, too).
Now you can think about how big one step should be. You can size it as one action in the testobject or use it as a routine to come to a certain startpoint of your Test over multiple actions. E.G. Given Go to Startpage of creating a security request
Java Code:
#Given ("^Go to Startpage of creating a security request$")
public void GoToStartpageOfCreatingASecurityRequest(){
//logic to get to the demanded point in testobject...
}
So as any other framework cucumber has its limits but they are intended and you have ways to work around it. ;)
Do not forget to use assertions in your test. Wether you use JUNIT or TestNG (I use TestNG). ;)
Xpage (listPostits.xsp) has a "View" container control, where one of the column is set "show values in this column as links".
Now, here comes "Strange behaviour".
When i work with this application on my own (developer) PC (Win XP, Chrome or IE), the Domino generate the link, which can't be really processed:
/servername/db/postit/postit.nsf/listPostits.xsp/onePostit.xsp?documentId=many_numbers&action=editDocument
Namely, the Bold-marked portion shouldn't be there ! This portion is the name of the XPage, where the View control is in.
When i work with the application from other PC (Mac, Firefox) then i get the correct link (the same as above but without the XPage name inbetween):
/servername/db/postit/postit.nsf/onePostit.xsp?documentId=many_numbers&action=editDocument
update: let us leave for the moment the differencies in generated links between two machines. The first question is - why the extra portion is inserted into automatically generated link?
After playing around i think i might have found the reason for this strange behaviour. Namely, the "Substitution" Rules on the server side. One of them is to substitute "*/postit/all" with "/db/postit/postit.nsf/listPostits.xsp"
If i switch it off, then the Links are generated properly. Still, it's pretty strange to me that these settings influence the way Domino generates the links. I thought it works on the fly with them and those settings have nothing to do with the way how Links are generated inside the application.
So, the help now is needed regarding Web Site Rule Topic, but for that, i guess, i have to create another topic. But in case somebody has some good Info on this, please share it with me. I'm a bit confused at the moment :)
Final Update: Spent some more hours of testing and the results confirmed the initial idea.
If i open the page with the standart URL, i.e.
http://servername/db/postit/postit.nsf/listPostits.xsp then everything is fine, links are generated properly. When i however open the same page with short URL http://servername/postit/all , then server adds the substitute URL (db/postit/postit.nsf/listPostits.xsp) to every single link he generates automatically to be used as the link to open/edit the underlying document.
Is it bug or feature ? Don't know.
As a workaround (because i want to keep simple URL's for the application) i have to manually generate links.
I am a complete newbie with ruby and am starting out using cucumber-nagios for some BDD testing.
I have installed cucumber-nagios on my Mac Pro using the instructions here:
http://auxesis.github.com/cucumber-nagios/
My Mac is running Snow Leapord 10.6.6 and has ruby 1.8.7 installed.
I have created some simple features to mechanize form submission. However try as I might whenever I submit a form the values of the form fields are not being passed with the request. No errors are returned (apart from the error reported for the final step dealing with the expected response page).
Thinking that perhaps the forms were too complicated I used a very simple form on the w3 site as the most simple test case possible.
http://www.w3schools.com/html/html_forms.asp
The form being submitted to is this:
Username:
and these are my feature steps:
When I go to "http://www.w3schools.com/html/html_forms.asp"
And I fill in "user" with "Chinese"
And I press "Submit"
Then I should see "user=Chinese"
The filling in of the form is done using the standard step code supplied with cucumber-nagios in http_steps.rb =>
When /^I fill in "(.*) with "(.*)"$/ do | field, value|
fill_in(field, :with => value)
end
When running
cucumber-nagios features/form.feature
all the steps pass except the final one, and the HTML response states I didn't submit any data with my form.
I turned on webrat logging but this does not give any helpful information.
As I said, I have tried similar code on other web sites and forms with exactly the same results.
The only thing I can think of is that I am missing some vital part of the whole cucumber-nagios set-up. Do I need to create and configure a database for example as you do with Rails applications? Excuse my ignorance.
I was having the same issue, and we tracked it down to webrat not POSTing the form properly.
Whilst it's not an elegant solution, we found that telling webrat it was in Rails mode fixed the problem.
Add the following code to your features/support/env.rb file, which is generated by cucumber-nagios when you create a new project.
Webrat.configure do |config|
config.mode = :rails
config.open_error_files = false
end
I wrote a blog article called Checking form Submissions with Cucumber-Nagios which explains the answer in greater detail.
Is there any sort of documentation on exactly what parameters you can put in the url of Google viewer?
Originally, I thought it was just url,embedded,chrome, but I've recently come accross other funny ones like a,pagenumber, and a few others for authentication etc.
Any clues?
One I know is "chrome"
If you've got https://docs.google.com/viewer?........;chrome=true
then you see a fairly heavy UI version of that doc, however with "chrome=false" you get a compact version.
But indeed, I'd like a complete list myself!
I know this question is very old and perhaps you already solved your issue, but for anyone on the internet who might be looking for an answer...
I have been looking for this recently, following a guide I found on GitHub Gist
https://gist.github.com/tzmartin/1cf85dc3d975f94cfddc04bc0dd399be
More specifically, the option to embed a certain page of pdf using
<iframe src="https://docs.google.com/viewer?srcid=[put your file id here]&pid=explorer&efh=false&a=v&chrome=false&embedded=true" width="580px" height="480px"></iframe>
The best I could fing was this article (I suppose from a long time now)
https://weekly-geekly.github.io/articles/111647/index.html
HOWEVER, I tried modifying the attributes and the result was simply a redirect to
https://drive.google.com/file/d/[ID]/edit
https://drive.google.com/file/d/[ID]/preview or
https://drive.google.com/file/d/[ID]/view
AS OF MAY 2020, THIS SOLUTION PROBABLY DOESN'T WORK
I'm also on a quest to discover some of the parameters of the viewer.
the "chrome" parameter doesn't seem to do anything, though. Is this
supposed to be the same as embedded=true?
Parameters I know of:
url= (obviously)
embedded= (obviously)
hl= set language of UI (tooltips)
#:0.page.1 = jump to page 2 (page 1 is numbered 0) - this is unreliable and often requires a refresh after the first load,
defeating the purpose.
That said, when I use the Google Docs viewer on my site, "fit page to
screen" is the default view without any parameters. So maybe I'm
misunderstanding your question.
Source: For convenience, this is a full quote of the sole answer (it is from user k3david) to the crosspost of this question #Doc has posted to the Google support forum in 2011.
You can pass q=whatever to pass a search query to the viewer.