Is there a way to combine page object gem and javascript calls
NickName:charlietaylor Ask DateTime:2014-10-14T20:55:07

Is there a way to combine page object gem and javascript calls

Im using the page object gem and selenium,

when filling in a sign up form, the form fills in correctly, but when clicking apply it errors saying the fields are required even though they are filled in.

this seems to be caused because the page object/selenium method isn't firing the javascript change method which is needed for the application to know the field has been filled in

this can be fixed by using code such as

on(SettingsPage).payment_method_account_number = number
@browser.execute_script("$('input[name=account_number]').change()")

but this is obviously not ideal and breaks the whole point of using page object in the first place by having to declare the fields name attribute again

is there a way better way to solve this problem than what i have shown?

Copyright Notice:Content Author:「charlietaylor」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/26361397/is-there-a-way-to-combine-page-object-gem-and-javascript-calls

Answers
Justin Ko 2014-10-14T16:24:13

To avoid duplicating an element definition within the page object as well as the execute_script script, you can pass the page object element to the script.\n\nThe underlying Selenium-WebDriver (and therefore the Page-Object gem) supports an arguments array within the script being executed. This arguments array basically takes a Selenium-WebDriver elements and converts them to something usable by the script. The Page-Object execute_script method handles the conversion of elements to the right type, so you simply need to:\n\n\nDeclare a script that uses the arguments array\nPass in a PageObject::Element\n\n\nFor example, let us assume your page object has used the accessor:\n\ntext_field(:payment_method_account_number, :name => 'account_number')\n\n\nTherefore, the page object will have a payment_method_account_number_element method that returns the PageObject::Element for this text field. \n\nWithin the script you want to execute, you can replace how you locate the element with the arguments array and pass in the PageObject::Element to the execute_script method:\n\nexecute_script(\"$(arguments[0]).change();\", payment_method_account_number_element)\n\n\nThen you can re-write the call to on as:\n\non(SettingsPage) do |page|\n page.payment_method_account_number = number\n page.execute_script(\"$(arguments[0]).change();\", page.payment_method_account_number_element)\nend\n\n\n(Or, as Dane pointed out, put this into a method in the page object.)",


More about “Is there a way to combine page object gem and javascript calls” related questions

Is there a way to combine page object gem and javascript calls

Im using the page object gem and selenium, when filling in a sign up form, the form fills in correctly, but when clicking apply it errors saying the fields are required even though they are filled...

Show Detail

Is there a way to combine an observable with an object?

Is there a way to combine an observable with an object that is not an observable in JavaScript? If not, what about adding data to the observable?

Show Detail

framework using page Object gem - bundle as a gem

I would like to create a framework using the ruby page object gem. The idea is simple. I want to seperate the common re-uable components under framework project and then finally bundle all these as...

Show Detail

page object gem - when are the required methods generated?

I believe that when using page-object gem, having a method call like link(:sym, text: "example.com") generates three methods - sym, sym_element and sym? Can anybody clear the following doubts? ...

Show Detail

Page object gem with Bootstrap

I have been using the Ruby page object gem successfully for the last few months, however the new software I'm testing is using Bootstrap so it has become harder. e.g I'm trying to select from a dr...

Show Detail

Making parallel calls with twitter gem

I am using twitter gem to make API calls from my app and fetch some data. I have an array of user_ids and I want to fetch all tweets of each user by doing something like this: user_ids.map {|use...

Show Detail

Looking for a way to edit a JavaScript file as it is added to the page

I am not sure the best way to word this, or even if it is possible. Any suggestions are welcome. We have a JavaScript file on our site that creates an Object, sets values on the Object, and calls a

Show Detail

page-object gem seems not working

I am trying to use page-object gem in my watir-webdriver scripts and I think I might be missing something. Here is my code for log_in.rb: require "./all_deals" class LogIn include PageObject

Show Detail

Is there a good way to combine array and object in JavaScript?

There is an object and an array. list: [ { oldData: { title: 'abc', id: 1, date: '1982-09-30', budget: 250000, }, newData: [ { key: 1,

Show Detail

Recommend approach for adding javascript from Ruby On Rails Gem

I'm working on a Gem that adds extra functionality to ActiveRecords. During installation, someone has to add the following to their form's erb file to get extra form elements provided by my gem: &l...

Show Detail