From a65b94bc8d14a47adda83330d2747c1a4bf7778b Mon Sep 17 00:00:00 2001 From: Michael Shannon Date: Fri, 27 Jul 2012 13:34:27 +0100 Subject: [PATCH] Fix Issue #1 - Changes to order of forms in Shopify's activate account page have broken mechanize_activate_customer_login.rb To try and add a bit of resilience to future undocumented changes made by Shopify, the script will now loop through all the forms on the page, and identify the form which contains the 'password' fields. This will then assign the relevant form to the activate_form variable. While this solution is not completely bulletproof against future changes made by Shopify, it should mean that any future structural changes to that page will not break the mechanize script's functionality. --- mechanize_activate_customer_login.rb | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/mechanize_activate_customer_login.rb b/mechanize_activate_customer_login.rb index bb9da48..dc2194a 100755 --- a/mechanize_activate_customer_login.rb +++ b/mechanize_activate_customer_login.rb @@ -89,20 +89,31 @@ puts "Using activation code as customer password" pp activate_result_page - - activate_form = activate_result_page.forms.first - # if you're generating a random password, you could use the invite code + + # Loops through all forms on activate_result_page to identify form which contains password fields, + # and assigns discovered field to activate_form + activate_form = nil + activate_result_page.forms.each do |form| + form.fields.each do |field| + if field.name.include?('password') + activate_form = form + break + end + end + end + + # if you're generating a random password, you could use the invite code # because it is randomly generated each time the invite email is displayed activate_form['customer[password]'] = customer_password activate_form['customer[password_confirmation]'] = customer_password - + puts "Submitting activation form" - + pp agent.submit(activate_form, activate_form.buttons.first) - + last_time, this_time = this_time, Time.now puts " ... elapsed total (#{this_time-start_time}) since last (#{this_time-last_time})" - + puts "Email (#{customer_email})" -end +end \ No newline at end of file