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.
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 want to define a new template called "product".
This template calls an external service and retrieves the information about that specific product. That is easily done with a custom plugin that access the product information. Information on how to do that has been found here.
However, I would like that the URL of the page would be something like:
/product/<id>/<seo-friendly-description>
So I can retrieve in the Twig template both <id> and <seo-friendly-description> which will be used later to retrieve the specific product information.
I have tried to find something that could help in the documentation, without success. Could someone either point me to the right doc section or highlight the basic steps that shall be achieved so I can start solving this issue?
Just in case it helps, I am trying to find something similar to how bottle or other web frameworks work:
#route('/hello/<name>')
def greet(name):
return 'Hello ' + name
I've been building a family recipebook into my own website and I've been working through a similar problem. I haven't quite worked out all the kinks, but my solution is mostly working if you want to checkout my github repo.
In short, you need the plugin to watch what the active route is. If the route matches, you then create the page and populate it using your plugin data.
I haven't quite figured out how to get the active page to highlight in the navigation menu for generated pages, but you might still find this solution helpful.
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 :)
What's is the best way to prevent multiple submission when I'm using XPages?
For "classic web" solution is below.
How to Block Multiple Submissions of the Same Document from the Web
http://www-304.ibm.com/support/docview.wss?uid=swg21089865
Using jQuery, the solution is below.
http://www.norio.be/blog/2008/09/using-jquery-prevent-multiple-form-submissions
But I don't know the way in Xapges. How to prevent it in XPages or Dojo?
It is best not to apply such client-side techniques, because combined with an unreliable internet connection the user may find that the submission fails but be unable to retry.
A much more robust solution is to deduplicate on the server side, which can be done in a variety of ways; these are some that come to mind:
Define the semantics of your form contents so that it doesn't matter if you receive two requests (e.g. if it is updating a record, then a second update just changes nothing).
If you have seen the exact same submission before (compare all the relevant fields), ignore it.
Generate a serial number when you send the form to the client. Don't accept submissions that have a serial number you've seen before — or do something useful; for example, if it is a blog posting or comment form, then a second submission should be treated as an edit to the post created by the first submission.
You can prevent a submit by using XSP.addQuerySubmitListener and return false. This is not the easiest function to get working. So I suggest you take a look at the function in the book 'Xpages Portable Command Guide' or try my project multiple file uploader on OpenNTF. Download the project source code here.
I have some serious problems testing a sharepoint site with selenium/bromine. As I did't find an answer via various searches I hope someone here can point me in the right direction.
I am constantly getting timeouts opening the main page, but the server is definetly fast enough to answer the request and at 90% idle. Nevertheless I just get logs like these:
open http://username:passwd#10.13.110.54/default.aspx | Timed out after 90000ms
Test terminated The selenium server did not return OK
The auth popup is popping up at irregular intervals (every 5 to 10 clicks) although every open command uses the http://username:passwd#10.13.110.54/ as prefix
Clicking on elements is sometimes not registered, the logs show a successful
isElementPresent link=myLink
click link=myLink
but the browser doesn't react. These are mainly in-page links which open a new folder or an editing box.
I'm not sure whether I should have posted the in three separate questions, but I didn't want to spam.
Hope someone can help me, as I have these problems now for nearly 3 weeks.
Thanks in advance
Thomas
For your question number 2: Okay, this is a really late reply. I stumbled on this page looking for the answer myself. Given that I have solved it in the meantime, I figured I'd post my answer for other people stumbling onto this page.
General solution:
You need to create or use a profile that will let firefox automatically forward your credentials to the sharepoint website. You can create the profile manually and call it each time, see https://applicationtestingtips.wordpress.com/2009/12/21/seleniumrc-handle-windows-authentication-firefox/ for instructions.
Programmer solution: (works in python, should work similarly in Java)
Or you can create a new profile on the fly each time. I did that based on the information in the previously mentioned website. I use python for calling selenium, but this should be rather similar in whatever language you use to call selenium:
sharepointHosts = 'sharepoint1.mycompany.com,sharepoint2.mycompany.com' #have all your sharepoint hosts here in a comma-separated list
ffProfile.set_preference('network.automatic-ntlm-auth.trusted-uris', sharepointHosts)
ffProfile.set_preference('network.negotiate-auth.delegation-uris', sharepointHosts)
ffProfile.set_preference('network.negotiate-auth.trusted-uris', sharepointHosts)
driver = webdriver.Firefox(firefox_profile=ffProfile)