27 Sep

Tutorial – How TO run Selenium with PHPUnit

By Đặng Minh Kỳ Phong

1.  Summary

-          Selenium is an automation testing tool which is opensoure

-          Selenium is a suite of tools specifically for testing web applications.

-          Selenium is composed of three major tools. Each one has a specific role in aiding the development of web application test automation: Selenium IDE, Selenium RC, Selenium Gird

2.  Setup the selenium server/client

Installing Selenium Remote Control (RC) requires three steps in the process:

a. First: Install JRE 1.5 or later

b.      Second: Install the Selenium RC

c.       Third: Install php Client

3.   Install the Selenium RC

a.       See slides (see detail file slide)

b.      Run PHP with php unit test

4.  How it works

5.  Run with phpunit testing

Setup selenium php client

If you have gone through configuring Selenium in Windows by Setting up Selenium RC server in Windows and Setting up PHP in Windows using Abyss server, next thing you need to setup is the Selenium PHP client. Let me show you the steps I’ve gone through to accomplish this:

1. Open up the console with all administrative privileges especially in windowns
2. Go to the directory where PHP is installed
3. Execute command: php PEAR/go-pear.phar
4. Follow the instructions, and ignore the additional offerings to configure it
5. Install PHPUnit by:
pear channel-discover pear.phpunit.de
pear install phpunit/PHPUnit

6. Download Selenium PHP PEAR extension and place into your PHP directory
7. Run: pear install Testing_Selenium-0.4.2.tar // install selenium client for windows
8. Record a testcase with selenium IDE, the sample GoogleTest, assuming you put it in C:\Tests folder
9. Now run: phpunit –verbose GoogleTest C:/Tests/GoogleTest.php
10. Remember the class name GoogleTest must be the same as the class name defined in the GoogleTest.php
Note: when installing phpunit test that the system requires the correct pear’sversion (test it by phpunit test), you must be update it by doing so:

Update pear by running

pear upgrade –force http://pear.php.net/get/Archive_Tar http://pear.php.net/get/XML_Parser http://pear.php.net/get/Console_Getopt

See this link:

http://www.phpunit.de/manual/3.2/en/selenium.html

Run testcase: C:\wamp\bin\php\php5.2.6>phpunit –verbose GoogleTest C:\Tests\GoogleTest.php

6.  Goal

-          design a test case then you can test it on all browsers, example: FF, IE

-          when running on FF, you can setBrowser in the code.php file:

1.      $this->setBrowser(“*chrome”); // test on FF

2.      $this->setBrowser(“*iexplore”); // test on IE

-          Export to a lot of language: PHP, C#, Java, …

-          Re-testing to run automtically

7.  Design test case for all projects:

8.  Example

<?php

require_once ‘PHPUnit/Extensions/SeleniumTestCase.php’;

class iwsmall extends PHPUnit_Extensions_SeleniumTestCase

{

function setUp()

{

$this->setBrowser(“*chrome”);

$this->setBrowserUrl(“http://www.hypotheekrentelijsten.nl/Hypotheekrente”);

#$this->browser = new Testing_Selenium(“*iexplore”, “http://www.hypotheekrentelijsten.nl/Hypotheekrente”);

#$this->browser->start();

}

public function tearDown()

{

$this->stop();

}

function testMyTestCase()

{

$this->open(“/Hypotheekrente”);

$this->type(“form_initials”, “dongmimi”);

$this->type(“form_middle_name”, “dong”);

$this->type(“form_last_name”, “le”);

$this->type(“form_datetime”,”12/09/1991″);

$this->select(“form_gender”, “label=Mannelijk”);

$this->type(“form_street”, “ly thuong kiet”);

$this->type(“form_house_no”, “hcm”);

$this->type(“input-postcode”, “1234 ds”);

$this->type(“form_hometown”, “lgh”);

$this->type(“input-phone”, “0123343546″);

$this->type(“form_tel_mobile”, “0123334546″);

$this->type(“input-email”, “dongl@dbb4.com”);

$this->select(“marial”, “label=Inwonend”);

$this->select(“form_employment_1″, “label=Geen inkomen”);

$this->type(“form_gross_annual_income1″, “3000″);

$this->type(“form_outstanding_loans”, “algh”);

$this->select(“form_bkr_listing”, “label=Ja”);

$this->select(“form_current_housing”, “label=Huurwoning”);

$this->select(“form_current_hypotheeksomn”, “label=Overige”);

$this->select(“form_new_mortgage”, “label=Oversluiten”);

$this->type(“form_new_mortgage_amount”, “500″);

$this->click(“form-submit”);

}

}

In command line:

Before running tests, run the selenium server first

C:\wamp\bin\php\php version(?) > phpunit  –verbose iwsmall c:\tests\iwsmall.php

Server run:

Results after running @ command line php client

C:\wamp\bin\php\php version(?) > phpunit  –verbose iwsmall c:\tests\iwsmall.php




  • Comments are closed.