Question

I'm using Watir-Webdriver. The script works for me on Firefox, however on Google and IE it breaks right once I enter in data into the modal. I also noticed for IEDriver that inputting text into a text field is very slow compared to ChromeDriver and Firefox, which also breaks the script.

This is the error I get when I run ChromeDriver or IEDriver:

    ===============================================================================
    Failure: <nil> is not true.
    test_orderjellybean(TestShoppingCart)
    C:/Users/cameron.sampson/Desktop/shopping cart auto/shoppingcart-jellybean.rb:69
    :in `test_orderjellybean'
         66:
         67:                # Select Monthly Plans for data, minutes and text
         68:                assert @b.div(:class, 'modal-body')
      => 69:                assert @b.text_field(:id, 'ZipCode').set '92130'
         70:                assert @b.button(:value, 'Confirm').click
         71:                sleep 5
         72:
    ===============================================================================

I have updated ChromeDriver, Watir-Webdriver and Selenium-Webdriver. Is there some other gem I should have installed to make cross-browser automation more functional?

Here's the HTML source where I'm running it from:

    <div class="modal fade" id="modal-checkplans">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-body">
                    <h3>Confirm Coverage</h3>
                    <div class="alert alert-danger fade hidden">
                        <p><strong>We are sorry :(</strong>
                            <br>
                            This product should work almost anywhere in the U.S. where it is available, your address is one of the few locations where coverage is not available. If you feel that this is an error, please call customer service at 000-000-0000. </p>
                    </div>
                    <form class="form-ajax form-inline" action="/Cart/cart/checkservice" data-callback="OnCheckNetworkCoverageComplete">
                        <label for="PostalCode">Enter the zip code where the phone will be used most often:</label>
                        <div class="input-group col-4 col-8">
                            <input autofocus="autofocus" class="form-control" data-val="true" data-val-length="Postal code must be between 5 and 10 digits." data-val-length-max="10" data-val-length-min="5" data-val-required="*required" id="ZipCode" name="ZipCode" type="text" value="" />
                            <span class="input-group-btn">
                                <input type="submit" class="btf btf-info" data-loading-text="Checking..." value="Confirm" />
                            </span>
                        </div>
                        <span class="field-validation-valid" data-for="ZipCode" data-replace="true"></span>
                    </form>
                </div>
            </div>
        </div>
    </div>
Était-ce utile?

La solution

It looks like the Chromedriver and Firefoxdriver are not consistent with the value returned when setting a text field:

# Chrome
@b.text_field(:id, 'ZipCode').set '92130'
#=> ""

# Firefox
@b.text_field(:id, 'ZipCode').set '92130'
#=> nil

This is why your test fails for Firefox but not Chrome - ie a nil value will fail the assertion.

That said, I think the root problem is the way assert is being used. It does not make sense to perform an assert on the any of these lines.

For example, the line:

assert @b.div(:class, 'modal-body')

Will always pass. The div method always returns a Watir object, regardless of whether the element exists on the page. This means that the assert will never fail.

You should remove the assert for the lines you have shown. Then add an assert to test a specific value.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top