What am I missing to define a variable from a page object? Getting undefined error in watir-webdriver - watir-webdriver

I'm trying to create a page object for the forms I'm automating and getting undefined local variable or method for 'checkout_form', though I thought I've already defined the variable.
This is my page object page:
require "page-object"
class CheckoutForm
include PageObject
# Checkout page
# Billing info
text_field(:billingfirst, :id => 'CheckOut_BillingTag_FirstName')
text_field(:billingmiddle, :id => 'CheckOut_BillingTag_MiddleInitial')
text_field(:billinglast, :id => 'CheckOut_BillingTag_Lastname')
text_field(:billingaddress, :id => 'CheckOut_BillingTag_Address1')
text_field(:billingaddress2, :id => 'CheckOut_BillingTag_Address2')
text_field(:billingcity, :id => 'CheckOut_BillingTag_City')
text_field(:billingstate, :id => 'CheckOut_BillingTag_State')
text_field(:billingzip, :id => 'CheckOut_BillingTag_ZipCode')
text_field(:billingphone, :id => 'CheckOut_BillingTag_Phone')
text_field(:billingemail, :id => 'CheckOut_BillingTag_Email')
def billing_info( billingfirst, billingmiddle, billinglast, billingaddress, billingaddress2, billingcity, billingstate, billingzip, billingphone, billingemail )
self.billingfirst = billingfirst
self.billingmiddle = billingmiddle
self.billinglast = billinglast
self.billingaddress = billingaddress
self.billingaddress2 = billingaddress2
self.billingcity = billingcity
self.billingstate = billingstate
self.billingzip = billingzip
self.billingphone = billingphone
self.billingemail = billingemail
end
end
On a different page that will use the page object I've added ' require_relative "checkout-form.rb" '
And there I set up the driver:
#b = Watir::Browser.new :ff
checkout_form = CheckoutForm.new(#b)
And interacting with the pageobject methods here:
checkout_form.billing_info.set 'Mike', 'L', 'Jones', '13677 Ruette Le Parc', 'Unit G', 'Del Mar', 'CA', '92014', 'aaaaa', 'mike.jones#gmail.com'

Related

PayPal express checkout instant update callback not being called [Sandbox]

I'm having troubles with the PayPal callback feature, i can't for the life of me get it to work at all. I have double checked the callback URL path, it's correct. When the user logs into paypal, it always just returns the default shipping rate. I'm just really not sure what i am missing here, if anyone can help out. Also, i have the callback timeout set to 6, though it seems it only takes about 3 - 4 seconds for it to fail and return the default shipping rate.
I've followed the documentation here https://developer.paypal.com/docs/classic/express-checkout/integration-guide/ECInstantUpdateAPI/ and applied it to my website. I've also made sure i am logged into sandbox too.
SetExpressCheckout params:
// SetExpressCheckout
$params = array (
'METHOD' => 'SetExpressCheckout',
'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
'VERSION' => $version, // 124.0
'USER' => $paypal_user,
'PWD' => $paypal_password,
'SIGNATURE' => $signature,
'L_SHIPPINGOPTIONNAME0' => 'Flat',
'L_SHIPPINGOPTIONLABEL0' => 'N/A',
'L_SHIPPINGOPTIONAMOUNT0' => '6.99',
'L_SHIPPINGOPTIONISDEFAULT0' => 'true',
'PAYMENTREQUEST_0_INSURANCEOPTIONSOFFERED' => 'false',
'PAYMENTREQUEST_0_SHIPPINGAMT' => $shipping_default, // 6.99
'PAYMENTREQUEST_0_ITEMAMT' => $cart_total,
'PAYMENTREQUEST_0_AMT' => $cart_total + $shipping_default,
'MAXAMT' => $cart_total + 30, // 30 is the total possible shipping amount
'PAYMENTREQUEST_0_CURRENCYCODE' => $paypal_currency, // AUD
'RETURNURL' => $paypal_return,
'CANCELURL' => $paypal_cancel,
'CALLBACK' => 'HTTP://localhost/moes/php/paypal_callback_php.php',
'CALLBACKTIMEOUT' => 6,
'CALLBACKVERSION' => '61.0',
'ALLOWNOTE' => 1,
'PAYMENTREQUEST_0_INVNUM' => '123' /*$invoice_number*/,
'PAYMENTREQUEST_0_TAXAMT' => $tax, // 0.00
);
// List each product and add to exress check-out array
foreach ($paypal_products as $k => $product){
$params["L_PAYMENTREQUEST_0_NAME$k"] = $product['name'];
$params["L_PAYMENTREQUEST_0_AMT$k"] = number_format($product['price'],2);
$params["L_PAYMENTREQUEST_0_QTY$k"] = $product['qty'];
$params["L_PAYMENTREQUEST_0_NUMBER$k"] = $product['code'];
$params["L_PAYMENTREQUEST_0_DESC$k"] = '1';
/* Optional shipping options to calculate shipping costs on callback
Option weight (L_PAYMENTREQUEST_n_ITEMWEIGHTVALUEm, L_PAYMENTREQUEST_n_ITEMWEITHTUNITm)
Option height (L_PAYMENTREQUEST_n_ITEMHEIGHTVALUEm, L_PAYMENTREQUEST_n_ITEMHEIGHTUNITm)
Option length (L_PAYMENTREQUEST_n_ITEMLENGTHVALUEm, L_PAYMENTREQUEST_n_ITEMLENGTHUNITm)
Option width (L_PAYMENTREQUEST_n_ITEMWIDTHVALUEm, L_PAYMENTREQUEST_n_ITEMWIDTHUNITm)*/
}
Callback script:
<?php
// Populate variables into local variables
$method = $_POST['METHOD'];
$version = $_POST['CALLBACKVERSION'];
$token = $_POST['TOKEN'];
$currencycode = $_POST['CURRENCYCODE'];
$localecode = $_POST['LOCALECODE'];
$street = $_POST['SHIPTOSTREET'];
$street2 = $_POST['SHIPTOSTREET2'];
$city = $_POST['SHIPTOCITY'];
$state = $_POST['SHIPTOSTATE'];
$country = $_POST['SHIPTOCOUNTRY'];
$zip = $_POST['SHIPTOZIP'];
// Setting shipping rate based on country [Test only]
if ($country == "US"){
echo "METHOD=CallbackResponse&OFFERINSURANCEOPTION=false&L_SHIPPINGOPTIONNAME0=FLat&L_SHIPPINGOPTIONLABEL0=N/A&L_SHIPPINGOPTIONAMOUNT0=10.00&L_TAXAMT0=1.00&L_INSURANCEAMOUNT0=9.00&L_SHIPPINGOPTIONISDEFAULT0=true";
} else {
echo "METHOD=CallbackResponse&OFFERINSURANCEOPTION=false&L_SHIPPINGOPTIONNAME0=FLat&L_SHIPPINGOPTIONLABEL0=N/A&L_SHIPPINGOPTIONAMOUNT0=30.00&L_TAXAMT0=1.00&L_INSURANCEAMOUNT0=9.00&L_SHIPPINGOPTIONISDEFAULT0=true";
}
?>
I'm guessing i missing something fundamental here, or i'm going about it completely the wrong way.
The solution to my problem was :
localhost/moes/php/paypal_callback_php.php
Obviously PayPal can't send a HTTP request to 'localhost'. My WAMP server is not configured to be accessible over the internet.

Moodle - Invalid course module ID

I am adding a folder module to a Moodle course using the API:
folder_add_instance($data, null);
I am getting the error below when running the script using CMD:
!!! Invalid course module ID !!!
I looked into the folder_add_instance() function in the library, the error is occurring when trying to get the context:
$context = context_module::instance($cmid)//$cmid = 8
i looked into the mdl_context table in Moodle database but couldn't understand the values and their relation to the error i am getting.
Will deleting the mdl_context values from the database will help? or i am missing something here?
Note that the script was working fine, until i deleted all the courses i had on Moodle using the web interface.(i deleted the category containing all the courses).
To programmatically create a module in Moodle you should use function add_moduleinfo().
Look at the example in the folder generator:
https://github.com/moodle/moodle/blob/master/mod/forum/tests/generator/lib.php#L67
Will be something like:
require_once($CFG->dirroot.'/course/modlib.php');
$foldername = 'YOUR NAME HERE';
$courseid = 12345;
$sectionnum = 0;
$course = get_course($courseid);
$moduleid = $DB->get_field('modules', 'id', array('name' => 'folder'));
$data = (object)array(
'name' => $foldername,
'intro' => '',
'display' => FOLDER_DISPLAY_PAGE,
'revision' => 1,
'showexpanded' => 1,
'files' => file_get_unused_draft_itemid(),
'visible' => 1,
'modulename' => 'folder',
'module' => $moduleid,
'section' => $sectionnum,
'introformat' => FORMAT_HTML,
'cmidnumber' => '',
'groupmode' => NOGROUPS,
'groupingid' => 0,
'availability' => null,
'completion' => 0,
'completionview' => 0,
'completionexpected' => 0,
'conditiongradegroup' => array(),
'conditionfieldgroup' => array(),
'conditioncompletiongroup' => array()
);
return add_moduleinfo($data, $course, $mform = null);
Invalid course module ID . That means moodle can find a course module record, but the cm doesn't actually exist in the course object when fetching all the course data.
What you can do to fix it is add the broken module back into a section of this course. It might be in a section that exists, then you also need to add the cmid to the sequence field. (Just add this cmid on the end of the existing sequence).
update mdl_course_modules set section=<existingsection> where id=cmid;
update mdl_course_sections set sequence='XX,YY,ZZ,cmid' where id =<existingsection>;
Then after you purge caches, you should now be able to view the module again, eg. for an assignment:
https://moodle.com/mod/assign/view.php?id=cmid

add catalog product in wishlist programmatically in magento

I have created a product with custom option and I have showed the detail of this product on a custom page. Now I want to add the product in wishlist with filled custom option by user.
If i have to just add the product in wishlist, I can simply use the following code.
<a href="'.Mage::helper("wishlist")->getAddUrl($_product).'" class="link-cart">Add to Wishlist /a>
but i want to insert the product with custom option. For this i have use following code but it gives me error "Cannot specify wishlist"
$wishlist = Mage::getModel('wishlist/wishlist');
$storeId = Mage::app()->getStore()->getId();
$model = Mage::getModel('catalog/product');
$_product = $model->load($data['productId']);
$params = array(
'product' => $data['productId'],
'qty' => 1,
'store_id' => $storeId,
'options' => array(
'optionId' => 'option value',
'optionId2' => 'option value2',
)
);
$request = new Varien_Object();
$request->setData($params);
$result = $wishlist->addNewItem($_product, $request);
You have to change first line
$wishlist=Mage::getModel('wishlist/wishlist')
to
$wishlist = Mage::helper('wishlist')->getWishlist();

Attributes exchange using Net::OpenID::Consumer

my $csr = Net::OpenID::Consumer->new(
ua => LWP::UserAgent->new,
consumer_secret => '123456xXx',
required_root => "http://www.myopenidsample.net/",
);
my $openid = "https://me.yahoo.com";
my $claimed_id = $csr->claimed_identity($openid);
if ($claimed_id){
my $check_url = $claimed_id->check_url(
delayed_return => 1,
return_to => "http://www.myopenidsample.net/response.cgi",
trust_root => "http://www.myopenidsample.net/",
);
print $q->redirect($check_url);
}
How do I get attributes such as email, firstName, lastName, and country?
How do I append the following parameters to a URL?
openid.ext1.mode fetch_request
openid.ext1.required country,email,firstname,lastname,language
openid.ext1.type.country http://axschema.org/contact/country/home
openid.ext1.type.email http://axschema.org/contact/email
openid.ext1.type.firstname http://axschema.org/namePerson/first
openid.ext1.type.language http://axschema.org/pref/language
openid.ext1.type.lastname http://axschema.org/namePerson/
openid.ns.ext1 http://openid.net/srv/ax/1.0
You need to add the following code before the call to check_url (the example was tested with Google in order to get only the email):
$claimed_id->set_extension_args(
"http://openid.net/srv/ax/1.0",
{
'mode' => 'fetch_request',
'type.email' => 'http://axschema.org/contact/email',
'required' => 'email',
});
To get the value back in the return, I use:
my $email = $csr->message->get_ext
("http://openid.net/srv/ax/1.0", "value.email");

if else to render a different form in the view of a rails 2 app

I am trying to render one of two slightly different forms with an unless else:
unless many_items
form_tag purchases_url(:item1 => item1), :id => "id1_#{item1}", :method => "post", :class=> "order-form" do
else
form_tag purchases_url(:item1 => item1, :item2 => item2), :id => "upgrade_#{item2}", :class => "upgrade_form" do
end
rest of form
button
<%end%>
but I get an error, of course.
I don't really know haw to do this..
I used a nil to prevent from the second variable to exist
parent_order = item2.present? ? item2 : nil
form_id = gig.is_item? ? "1#{gig.id}" : "2#{gig.id}"
form_class = gig.is_item? ? "1" : "2"
form_tag purchases_url(:item1 => item1 ,:item2 => items), :id => form_id, :method => "post", :class=> form_class do
%>