rspec assert disabled input value - ruby-on-rails-3.1

I am using rspec2 for acceptance testing.
I have a textbox which is disabled and has a text.
Now what is a proper asserting statement to check that the particular disabled textbox has a particular value
Eg: my disabled textbox has a value "heaven"
has_content?("heaven") cant find a text heaven in page
Thanks

Has content is a capybara call if I'm not mistaken, not RSpec. (Watir-webdriver example)
#browser.text_field(:name => 'my_input').text.should include 'heaven'

Related

Cypress checking disabled input field?

So maybe this is a HTML thing and not a Cypress thing, but when I check an a disabled input fields text it shows as ''
However doing the same with value ie: cy.get(input).should('have.value', 'Some Text') works, but not should('have.text')
Curious why this is?

How to set a span value with capybara?

Does anyone know how to set a value to span tag using capybara?
I tried using element.set or element.send_keys, they only selected the targeted element without modifing the previous value.
<div data-offset-key="bbpvo-0-0" class="_1mf _1mj"><span data-offset-key="bbpvo-0-0"><span data-text="true">aa</span></span></div>
HTML snippet is above, I want to set aa to bb.
Capybara is designed to emulate a user - A user can't edit a span unless there's some sort of javascript widget attached to it. If you have a JS widget attached to the span you would need to perform whatever actions a user would do in order to edit the span. So you say the user has to click on the span and then type on the span - if that is so then you could try something like
span = find('span[data-text="true"]')
span.click
span.send_keys("new content", :enter) # if enter is needed to end the editing
which may work - although I'm going to guess the element actually gets replaced with an input or something after it's clicked on, in which case you need to figure out what those elements are (using the browsers inspector) and then find and use send_keys or set on that element instead
To set text in span value,jquery can be used with capybara as shown below:
page.execute_script("$("<span css selector>").text("testing")");
or
page.execute_script("$("<span css selector>").html("testing <b>1 2 3</b>")");

How to find specific text field with same id?

I am testing this one angularjs application that has
text_field(:date, :id => 'transfer_date')
Problem is that there are two text fields with this id the reason being that the first one has ng-show = externalaccount and the second has ng-show = !externalaccount.
So when I test something that is not externalaccount, I will receive an error saying that the text_field is not visible. However when I test externalaccount, the test will pass fine. I looked around and found
Page-object gem: Identifying object with same properties based on their visibility
I tried this but it there are other text_fields on the page. I need to find the first visible text_field that has id='transfer_date'. How do I set this up with pageobject or step definitions?
You can find the first visible text field with specific attributes using:
text_field(:date){ text_field_elements(:id => 'transfer_date').find(&:visible?) }
This says to find all text fields with the specific id and then from that list find the first that is visible.

Duplicate Checkbox in Page-Object is not defined?

I am trying to click a checkbox that enables a purchase button to appear. When I try to use it, I get a "NoMethodError: undefined method 'eula' for Cart:0x101f54810" error. I think it may be because there are two identical checkboxes, but I am just not certain.
HTML:
<p id="eula-box" class="annoy cc"><input type="checkbox" name="terms_of_service" value="terms_of_service" tabindex=20 />I have read & agree to the End-User License Agreement.</p>
<p id="eula-box" class="annoy pp"><input type="checkbox" name="terms_of_service" value="terms_of_service" tabindex=20 />I have read & agree to the End-User License Agreement.</p>
My class:
require 'rubygems'
require 'page-object'
require 'page-object/page_factory'
require 'watir-webdriver'
CART_URL = 'http://www.anonymizer.com/cart/checkout.html?SKU=ANONUNV12'
class Cart
include PageObject
page_url CART_URL
checkbox(:eula, :class=>"annoy_cc")
button(:purchase, :value=>'purchase')
def complete_order(data = {})
self.eula.click
end
end
Udpated: I was changing the object type around trying to get it to work. Element was the last type I tried. I changed my example back to checkbox (my original attempt). Thanks for pointing that out.
When you call the class level checkbox method in page-object it generates five methods. The call:
checkbox(:summary, :id => 'valid_checkbox')
will generate:
check_summary # check the checkbox
uncheck_summary # uncheck the checkbox
summary_checked? # returns true if it is checked. otherwise false
summary_element # returns the Checkbox object
summary? # returns true if the element exists. otherwise false
These are the method to interact with when using the checkbox.
PageObject's checkbox generate the following method to check (i.e. click) it.
check_eula
See http://rubydoc.info/gems/page-object/0.6.3/PageObject/Accessors:checkbox
I'm not very familiar with page-objects, but is element a valid accessor? I'm looking at the documentation and don't see it. Perhaps it would be better to use the checkbox accessor?
As an aside, the easiest way to see if your problem is caused by having two similar checkboxes, would be to just remove one and see if the problem goes away!

How do I identify a dynamic-id custom-type text field in WATiR?

I have this input of type "Submit" that Watir cannot see. I can identify it by ID, but it doesn't turn up in browser.text_fields, or by any other idenfication method. The ID is dynamically generated so I cannot use it for testing. Any ideas on how to make this readable? I'm willing to change the WATiR source code if necessary.
<INPUT id=t8CPm value=Submit type=submit>
I have obviously tried text_field(:value, 'Submit') and text_field(:type, 'Submit'), and I get an "Unable to locate element" error.
Did you try treating it as a button element? Inputs of type submit are generally considered to be a button because the browser generally renders them that way.
try
browser.button(:value, 'Submit').flash
and see if it works for you
I changed INPUT_TYPES to ["text", "password", "textarea", "submit"] in the TextField class of input_elements.rb and there it was.
I should also probably edit the collections to read the type too.
Edit: I am an idiot and I didn't need to do this, but I'm leaving it here in case anyone else needs to identify a real dynamic-id custom-type text field, not a fake dynamic-id custom-type text field otherwise known in my particular case as a "button".

Resources