I have the following Feature file which is attempting to visit a page, select a link then edit user data.
Scenario: Edit an existing member of the club
Given I go to the member list page
And I choose the first item
And I fill in the "First Name" with "Bloggs
When I press "Update"
Then I should be on the member list page
And I should see "Bloggs"
and the member_step.rb file contains
Given /^I choose the first item$/ do
#save_and_open_page
visit members_path
click_link "1"
end
My routes.rb file has
Gfs::Application.routes.draw do
resources :members
end
The problem is that I can't get the click_link "1" step to work. The intention is that it will
Navigate to the '/members' index page
The index page displays a list of users each prefixed with a number, that is the link.
Select the link
What I know is that the index page does display a list, my route works ('/members), but my Cucumber is failing and I'm not basking in the glory of green.
The save_and_open_page diagnostic shows only the title of the index page and not the details, as though the controller is not accessing the data
Suggestions are most welcome.
Is there a Background where you create the members data? If not, it may be that the data does not exist.
I'd also suggest adding a step like
And I should not see "Bloggs"
before you update the record.
If I understood your cuke correctly, you really won't see the "1" link because:
Given I go to the member list page <-- first step
And I choose the first item <-- second step
...which expands to:
Given I go to the member list page <-- first step
visit members_path
click_link "1"
why are you visiting the member's path after you just visited the member list page? you should be checking that you ARE in the member's path. Something like:
Given I have existing users(generate members here using factory or whatever)
And I go to the member list page( go to member page)
When I follow "1" (click the first member)
Then I should be on the "1"'s member page
When I fill in...etc you get the point
Hope that helps!
I'm going to suggest that IFF the "1" is a true html anchor link, then you might consider using
And I follow "1"
You could easily wrap this in your own syntax to make it more aesthetically pleasing but the And I follow... step is one that you get out of the box in web_steps.rb.
Another gain in using that one is that you can use a selector to make the click more specific:
And I follow "1" within ".my-kickbutt-div"
Or something along those lines.
Another thing to check into. If you have #javascript enabled you might be seeing incorrect data in your save_and_open_page. My app is javascript/ajax heavy and I have to open the output in a browser with javascript turned off to see what is really visible there :P This might not be your issue, but just in case...
Related
I am simply looking to automate a button click on a homepage. I am using the following snippet of code
Given /^I press "(.*)"$/ do |action|
browser.button(:text => action).click
end
My feature file has the following
Scenario: Default Search
Given I press "Search"
On executing the feature file, I receive the following error
*** WARNING: You must use ANSICON 1.31 or higher (https://github.com/adoxa/ansicon/) to get coloured output on Windows
Ambiguous match of "I press "Search"":
C:/Users/............test/features/step_definitions/Moorings.rb:8:in `/^I press "(.*)"$/'
Haa... you have like 3 occurrence of the text "Search" on that page (www.moorings.com), so the watir driver does not really know which one to click.
As I mentioned above, try to use something unique, maybe an id, as below:
#step definition
Given /^I press "(.*)", with id "(.*)"$/ do |text, id|
browser.button(id: id, :text => text).when_present.fire_event :click
end
#feature
Scenario: Default Search
Given I press "Search", with id "edit-search"
Notice that I have added another constraint of id to the attributes to search for.
Also notice that I added an extra layer of check: .when_present. This will ensure that the test waits for the specified button to appear on the page before attempting to click it. A timeout of about 30 seconds is attached to this however.
I am using watir to perform some functions
I need to show that a link is actually clicked by the watir-driver, so I'm trying to put somthing to the console if a link is clicked as follow:
puts "profile clicked" if click_my_profile_link(browser)
and:
def self.click_my_profile_link(browser)
browser.div(class: "topbar").when_present
.link(class: 'my-profile').click
end
but nothing gets printed to the console when the link gets clicked. this behaviour is the same for everywhere I have a click action. Another example is:
puts "Next button clicked" if browser.input(id: 'next', value: 'Next').fire_event :click
How can I get some kind of log when there is a click action fired like this? thanks
Procedural methods are called for their action/side-effect and shouldn't be expected to have a response.
If you didn't get an error, then Watir found the element and sent a click command to it.
So maybe this is sufficient expect {click_my_profile_link(browser)}.to_not raise_error
Typically you write tests to verify the result of the link. In this case that would be something like expect(browser.title == "My Profile Title").to be true
You could create an AfterHook that will take an additional action after every navigation and click, but it wouldn't distinguish between the two, and I really don't think that is what you actually want.
I want to click on the second of the two following links:
photo
photo
As you can see, the URLs are actually different, but the link title, "photo", is the same in both. I am not using IDs on my links, and there is no nesting class context by which to distinguish the links.
Ideally, I would like to be able to click even a third, or nth ambiguous link.
An example of a DSL for this purpose would be something like:
click_link photo.title, match: 2
I find that using all is easier to read than locating by xpath:
all('a', :text => 'photo')[1].click
However, it not as fast as using xpath.
You should be able to use xpath for this. Something like:
find(:xpath, '//a[text()='photo'][2]').click
I currently have a landing page /vouchers and then many pages linked to that for example /vouchers/1, /vouchers/2 etc.
I currently have the functionality that if this is entered /vouchers/1?offer=50 then the form on that page is sent with the offer included in the url.
Now I need to add the functionality so if /vouchers?offer=50 is entered, any page that is then navigated to, will keep these parameters. (for example /vouchers/1 should then include the offer from the url)
I see only one way.
store all "special" parameters in session
in any handler — if "special" parameters are in session — form new url with this parameters and redirect user there
Let me guess :
1. you have a model , named "Voucher"
2. In case you want to see the entry for , let's say , voucher#1 , you see URL voucher/1 (notice the singular form of the word 'voucher')
3. you assign the value of the offer by some interaction by user , for example - link or list . Let's say it's a link . Try this (HAML):
= link_to "Accept this offer and create a new voucher", new_voucher_path(:offer => #offer_value)
(in your case #offer_value = 50)
The following view (or partial ) will be able to read the value in :offer .
You can refer to this useful discusion .
I solved this, probably not in the best way. On the /voucher page, I added if statements to all the links, so if there's an offer in the url, the links are appended appropriately.
2/28: Seems the Go uri is only if you create your own persisten layer. I'm going to try and use a link on my form to do this. If I can figure out how to find the form_id of the current form.
Original Question:
I'm trying to restrict who can delete a form instance. It seems if people can get to the form-runner summary page, they can click the delete button and delete a form (even if they are not allowed to do any "/orbeon/fr/hr/expense-report/edit/*" options.
Anyone found a way around this issue. I wonder if we could use the GO button on the form /edit/ view to build our own delete feature.
If I look at the page source from the hr/expense-report/edit/f36b446c3ddbf7c63ec033d5c6fa7ce4 view, that the from does have the details to the actual form instance.
Example:
form id="xforms-form" class="xforms-form xforms-initially-hidden xforms-layout-nospan" action="/orbeon/fr/Test/Hidden_Search/edit/f36b446c3ddbf7c63ec033d5c6fa7ce4"
I wonder if that information could be passed to the "GO" button, if I have that on my page?
Right now, if users can access the Form Runner summary page, they can also access the "delete" button. Showing the "delete" button on the summary page for some users but not others, requires a change to Form Runner, which shouldn't very complicated.
For instance, if you only want the "delete" button to be shown for users with the role can-delete, on this xforms:bind of fr/summary/view.xhtml add the attribute:
relevant="xxforms:is-user-in-role('can-delete')"