Wed 21 Jul 2010
So you installed the Selenium IDE firefox plugin and you recorded a check-out transaction of your Magento-powered ecommerce site. Then you save as a php file and fire up your Selenium RC server and run the script. It gets to the checkout page and … Nothing. What’s wrong?
What’s wrong is that you’ve submitted too quickly. You need to do some checking with xpath ids for the “updating totals” div before you can click submit. Here’s a working Selenium Magento script for your reference:
require_once 'PHPUnit/Extensions/SeleniumTestCase.php'; class Example extends PHPUnit_Extensions_SeleniumTestCase { function setUp() { $this->setBrowser("*chrome"); $this->setBrowserUrl("http://www.example.com"); } public function testMyTestCase() { //$this->maxRunningTime= 30; //(this is a special function I implemented) $this->open("/"); $this->click("//ul[@id='nav']/li[1]/ul/li[1]/a/span"); $this->waitForPageToLoad("30000"); $this->click("//img[@alt='ADD TO CART']"); $this->waitForPageToLoad("30000"); $this->click("//div[2]/div[1]/ul/li/a/img"); $this->waitForPageToLoad("30000"); $this->type("billing:email", "test@example.com"); $this->type("billing:firstname", "test"); $this->type("billing:lastname", "test"); $this->type("billing:telephone", "8015551212"); $this->type("billing:street1", "100 Main Street"); $this->type("billing:city", "Salt Lake City"); $this->select("billing:region_id", "label=Utah"); $this->type("billing:postcode", "84116"); $this->click("//*[@id=\"billing:street1\"]"); for ($second = 0; ; $second++) { if ($second >= 7) break; try { if (!$this->isElementPresent("//span[@id='billing-please-wait' and contains(@style,'display: none')]")) break; } catch (Exception $e) {} sleep(1); } for ($second = 0; ; $second++) { if ($second >= 7) break; try { if ($this->isElementPresent("//span[@id='billing-please-wait' and contains(@style,'display: none')]")) break; } catch (Exception $e) {} sleep(1); } $this->type("merchant_cc_number", "511111111111111"); $this->click("advice-validate-cc-number-merchant_cc_number"); $this->type("merchant_cc_number", "4111111111111111"); $this->select("merchant_expiration", "label=01 - January"); $this->select("merchant_expiration_yr", "label=2016"); $this->type("merchant_cc_cid", "432"); $this->click("//*[@id=\"submit-order-button\"]"); sleep(1); $this->click("//*[@id=\"submit-order-button\"]"); $this->waitForPageToLoad("30000"); $this->waitForPageToLoad(""); try { $this->assertTrue($this->isTextPresent("Thank you for your purchase!")); } catch (PHPUnit_Framework_AssertionFailedError $e) { array_push($this->verificationErrors, $e->toString()); } } }
Here is the Selenium timeout/maxRunningTime modification code explained.