I am new to automation testing and have no experience in Ruby, nor any other programming language. However my current employer wants from me to start automating small tasks. The problem I stumbled upon is when trying to pass hash values into fields of a registration form.
This is my Gherkin Scenario:
On the left hand side of the when-statement is the name of the field in which I want to pass a certain value. The first two are input fields. The last hash "age" is a dropdown.
Can someone help me out by giving me an example ruby method, that would fill-in such a registration form, given the information above?
P.S. The automation framework I use consists of Ruby, Cucumber and Watir Webdriver.
The following code is untested, but something like this should work for you.
# Step definition
Given /^I enter the following credentials$/ do |table|
# .drop(1) is to get rid of your first row with titles
table.drop(1).each_pair do |setting, value|
browser.element(name: setting).to_subtype.set(value) }
end
end
Be carefull using Gherkin as a replacement for coding. It should be focussed on what you're trying to achieve, not how you're trying to achieve it.
I would recommend a scenario as follows:
Given RegularJohn is on the create account page
When he submits the create account form with his information
Then the successfully created message should display
Note that in your code you would need RegularJohn to be a configuration variable that is filled with the expected information information.
When you try to test a failure you could use a different variable, like BadEmailAndy. This way you keep it readable, maintainable and understandable.
Related
Is it possible to set any global defaults for use with the #Html.ValidationSummary?
We're using it throughout our solution and want it always to show the same text. For example, we can achieve the text as follows:
#Html.ValidationSummary(False, "Validation Errors Occured")
However, we want to avoid the developer needing to specify the text. Instead, we'd like them to simply code as follows:
#Html.ValidationSummary()
Not providing you exact answer you are looking but you can create new extension method as per your need for validation summary. and use that method across the site for validation summary. You will have more control on your create code.
Have a look at this post how James created new method for it.
I'm running in to an issue in that I need to get one value in a cucumber statement, and then give that value to another statement.
Specifically I am getting a JSON object from one page (where that object gets sent to an api endpoint as a preference) and then using information out of that after I query the api, which happens in a completely separate step.
I am suspecting that I have to write the value somewhere, and then pull that value when the step that needs it comes up, but I'm kind of at a loss for doing that as well.
I can provide any further needed details, thanks for any help!
Definitely a rookie question - to which the answer is to use instance variables - #variable_name = get_method in the helper method your step calls.
I am trying to link up Mturk to my external Website
I am using the external survey Hit on the GUI requester page
I know that I need to generate the code myself, but I do not know how the code is validated.
In what form or fashion do I, or the Amazon site validate this code? and how do I implement this.
For example: A person gets a code from my website, and pastes it into the box of their amazon hit on the amazon website. Who is that code validated by? and if amazon how to I tell them which codes have been generated?
Thanks in advance!
You would do it yourself. you will find the code that the worker enters on the HIT page in your results file. Than you compare the results file with the list of codes you generated, and approve the correct codes.
A method is described on my blog which is ideal for surveys with lots of participants. Basically, you export the data from both your survey and Mechanical Turk, then you put the code columns side-by-side for comparison, and then you use a formula that takes each row of one column of codes and performs a lookup in the other column of codes. For example, you could use a COUNTIF formula in Excel, which returns a 1 if there is a single match, and a 0 otherwise.
everyone!
At first, I made a single form with large amount of elements: text fields, text areas and so on. When I had got the form ready, I understood that it is not so user-friendly to have such a large form to be filled-in in a row. I don't want to use the "step" system (step 1 -> step 2 -> ... -> step n), because I want for the end-user to be able to have this form filled in any order (+ User would be able to see beforehead what forms he would need to fill), so I divided the form into the several tabs.
The idea is following: once user has filled the form in some tab, he hits the "Save" button and proceeds to the next one (in arbitrary order of his choice).
The thing I wanted to know - what would be the best approach to store the intermediate data ? Should I have some hidden input for each of the tab forms with tab-id to be passed to the model, so that at each 'step' only tab relevant data was validated and stored in DB. Or, maybe, I should have a session[:object] that would contain the current object and at the very end I would store it in DB and erase from the session.
Can this idea be realised ?
Thanks in advance! :)
there's a gem called wicked, it allows you create wizards in a very simple way, check it out
I'm not a ruby ninja, but in other languages (like php) we usually use sessions to do this. Why not to do this on rails?
Also you can consider creating a table for "temporary storage rows" in addition of using sessions, so every time you change the page you could save the data to that table and, at the end, save them all to your main tables.
This is useful if you usually loose your session... you can related the temporary storage rows with the user and if he looses the session, you can restore his uncompleted forms from your database.
You could simply go the Railscasts 217 - Multistep form approach, which works fine.
However, this may not suit you as you may only store the data AFTER you have everything collected, and not step by step.
Another solution - as you mentioned - would be using e.g. jQuery tabs to create your form steps and building a little validation via AJAX / backbone.js before storing the actual record with all its data.
Now before you burn me at the stake hear me out!
I want some keywords of a product description field to link to other products (kinda like mediawiki links), however at some point I need to make these associations and link the keywords up, so I'll need to do a search on each curly-braced word I find in the description and produce a formatted version of the description to cut down on processing these keyword links every time the description is displayed.
For ease/consistency I am creating all product links with a custom helper, and all I need to do is pass the product row in and the helper products a link for me with any options I specify. The only this is, is that I need to now do this in beforeSave() so I can populate description_formatted.
At the minute, beforeSave() checks for the original description row, then calls a private method in the model which matches each keyword, queries the db for a matching row... that is as far as I've got.
Just like any other MVC, Cake makes big restrictions how to couple your classes. This is needed to keep script kiddies to shoot themselves in the foot. However, there is a niche workaround for cake if you really need to get along: http://book.cakephp.org/view/933/The-App-Class
How I would do this? With the helper I would replace all curly braces words into links and when the user hovers the linked word I would call an Ajax which will get the word description or the link or whatever you need to do. This way you request the description only when it's needed.
If you still insist to use the helper - it's just a class in PHP, so you can include it in your Model, create an object of the class and use it's functions.
The third option is to create your own class and use it both in Model and the Helper.