Changes between Version 3 and Version 4 of howto_write_ajax_tests

Show
Ignore:
Timestamp:
09/09/09 12:55:41 (12 months ago)
Author:
carlos (IP: 217.126.199.230)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • howto_write_ajax_tests

    v3 v4  
    8888== Testing Siwapp == 
    8989 
     90=== Very basic example === 
     91 
    9092We will reproduce the prior example with a few changes. Navigate to the `/path/to/your/siwapp/test/selenium` directory and create an `ExampleTest.php` file there: 
    9193 
     
    111113}}} 
    112114 
    113 `$this->getAppBaseUrl()` returns 'http://siwapp.test/siwapp_dev.php' by default. You can change it with `$this->setAppBaseUrl('http://demo.siwapp.org')` or similar. 
     115`$this->getAppBaseUrl()` returns 'http://siwapp.test/siwapp_dev.php/' by default. You can change it with `$this->setAppBaseUrl('http://demo.siwapp.org')` or similar. 
    114116 
    115117{{{ 
     
    119121This should open a Firefox instance, load the base url and check if the title is 'siwapp'. 
    120122 
     123=== Dashboard Example === 
     124 
     125{{{ 
     126<?php 
     127require_once(dirname(__FILE__).'/../bootstrap/Selenium.php'); 
     128 
     129class DashboardTest extends SiwappSeleniumTest 
     130{ 
     131  public function testShowPayments() 
     132  { 
     133    $this->login(); 
     134     
     135    $this->log("::testShowPayments()"); 
     136    $this->open("dashboard"); 
     137     
     138    $this->log("show payment details for the most recent invoice (top table).", 'click'); 
     139     
     140    $this->click("//*/table[@class=\"listing\"][1]/tbody/tr[1]/td[8]/a"); 
     141    $ret = $this->waitForCondition("selenium.isElementPresent('//*/table[@class=\"listing\"][1]/tbody/tr[2]/td[1]/form[@class=\"payments-form\"]') == true"); 
     142     
     143    $this->log("show payment details for the most recent overdue invoice (bottom table).", 'click'); 
     144     
     145    // Bottom Table 
     146    $this->click("//*/table[@class=\"listing\"][2]/tbody/tr[1]/td[7]/a"); 
     147    $this->waitForCondition("selenium.isElementPresent('//*/table[@class=\"listing\"][2]/tbody/tr[2]/td[1]/form[@class=\"payments-form\"]') == true"); 
     148  } 
     149} 
     150?> 
     151}}} 
     152 
     153The `login` method performs the login action if you are not logged in. It is recommended to put that line in every test function if you don't know which one is going to be executed first. 
     154 
     155'''Important:''' Try to use relative xpath routes as much as you can because if we change the layout the test could fail. Let's see an example: 
     156 
     157{{{ 
     158BAD: 
     159//tr[@id="invoice-50"]/td[8]/a/span/span 
     160//form[@id="invoice-50_payments"] 
     161}}} 
     162 
     163{{{ 
     164OK: 
     165//*/table[@class="listing"][1]/tbody/tr[1]/td[8]/a 
     166}}} 
     167 
     168In this case we got the payments button of the first row in the first listing table. 
     169 
    121170== Notes == 
    122171 
     
    124173 * Selenium tests must be executed from the /path/to/siwapp/test/selenium directory or will throw an error. 
    125174 * Read the documentation to learn Selenium: http://seleniumhq.org/docs/ 
     175 * You can use `/path/to/siwapp/doc/selenium-commands.txt` and `/path/to/siwapp/web/js/core/selenium-api.js` as reference.