Automatic tests with Selenium – part #2

Testing PHP aplication is not the native task for Selenium, but thanks to facebook api developers we have a tool to make it. Facebook PHP WebDriver alows to use Selenium and even combine it with PHPUnit.

You should first read Automatic tests with Selenium – part #1.

Let’s drive

Like in the previous article, we need a Selenium server, but this time for PHP. We can get it from here. Download the newest one standalone java version and run it (the most recent at the time of writing this article is 3.3.1)

sudo wget http://selenium-release.storage.googleapis.com/3.3/selenium-server-standalone-3.3.1.jar
java -jar selenium-server-standalone-3.3.1.jar

It should be running all the time, as a single process. You will also need a PHPUnit installed on your WebSever.

So we need to create some environment for testing. We will use composer. If you don’t have it installed, do it now. Create a new directory test in your localhost web directory.

In a new terminal window type

	cd /path/to/test
	composer init

you will see a composer wizard. When it ask you for a package to search, type facebook/webdriver, like below


Welcome to the Composer config generator  

This command will guide you through creating your composer.json config.

Package name (<vendor>/<name>) [root/webdriver]: 
Description []: 
Author [picios <example@example.com>, n to skip]: 
Minimum Stability []: 
Package Type (e.g. library, project, metapackage, composer-plugin) []: 
License []: 

Define your dependencies.

Would you like to define your dependencies (require) interactively [yes]? yes               
Search for a package: facebook/webdriver
Enter the version constraint to require (or leave blank to use the latest version): facebook/webdriver

Hit empty ENTER in another Search for a package prompt and confirm generating of a new composer.json file. Now type

	composer update

Composer will take care to download the newest version of the package.

Let’s test

We need something to test, so let’s create a new html file tested_page.html in our test directory.

<!doctype html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<title>The tested page</title>
		<meta name="description" content="The tested page">
		<meta name="author" content="Me">
		<!-- stylesheets assets here -->
	</head>
	<body>
		<h1>It works!</h1>
		<!-- scripts assets here -->
	</body>
</html>

And now create a new test php file MyPageSeleniumTest.php in the same directory.

<?php

require 'vendor/autoload.php';

use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\WebDriverBy;

class MyPageSeleniumTest extends \PHPUnit_Framework_TestCase {

	public function testPage() {

		$driver = RemoteWebDriver::create('http://localhost:4444/wd/hub', DesiredCapabilities::chrome());
		$driver->get('http://localhost/test/tested_page.html');
		$heading = $driver->findElement(WebDriverBy::tagName("h1"));
		$this->assertContains('It works', $heading->getText());
	}
}

Save it. While your Selenium server is running, type in terminal

	phpunit --verbose MyPageSeleniumTest

If everything goes ok, you will see a new Chrome window with a ‘It works!’ sign. Moreover you will get your test result from PHPUnit.

	OK (1 test, 1 assertion)

6 thoughts on “Automatic tests with Selenium – part #2”

  • MeShellAngelo says:

    I read both of your Selenium articles. They are pretty fast but clear. Only you should’ve mentioned, that your OS is Ubuntu. Some beginners might be confused.

  • Do you love teen hardcore sex? Or when young girls suck cocks until guys cum? Or you like crazy dorm actions with drunk students drink beer and fuck at parties? All of these and much more you will see on this site 18-teen-porn.com. All kinds of teen porn with beautiful girls. Big tits, small tits, shaved and hairy pussies penetrated by cocks, skilled mouths suck dicks and sure with lots of sperm! Have fun with our teen HD videos!
    With a huge variety of quality teen porn, this top notch tube is sure to grant the best adult experiences online. Once you step inside, you get to see a lot of niches and plenty of available HD videos, all carefully selected and with daily updates to keep you aroused. Enjoy an impressive number of amateur teen porn, cam girls gone wild and a whole lot of other categories in one single and very impressive collection of teen videos. Each comes with HD image and the tube’s fantastic streaming speed, something which will surely improve your adult experiences. Only rate teen porn and quality action, girls on fire in the mood to spin large inches of cock into each of their tiny love holes. Barely legal hotties working cock like true pornstars and a huge number of amateurs trying to make it into the big league. Either way you like your porn, this awesome teen tube will provide young flesh and spicy action at any hour. Only exclusive teen porn which is not available on other movie sites or tubes. Quality content with premium action and girls to die for. Enjoy such fantastic content on a tube that’s set to become number one, a tube which will make your delight with a very large variety of niches. Never mind browsing for teen sex on other tubes, this one right here offers a huge variety of movies and what you need for unbelievable experiences.

    http://www.datingnzcougar.info

  • Do you love teen hardcore sex? Or when young girls suck cocks until guys cum? Or you like crazy dorm actions with drunk students drink beer and fuck at parties? All of these and much more you will see on this site 18-teen-porn.com. All kinds of teen porn with beautiful girls. Big tits, small tits, shaved and hairy pussies penetrated by cocks, skilled mouths suck dicks and sure with lots of sperm! Have fun with our teen HD videos!
    With a huge variety of quality teen porn, this top notch tube is sure to grant the best adult experiences online. Once you step inside, you get to see a lot of niches and plenty of available HD videos, all carefully selected and with daily updates to keep you aroused. Enjoy an impressive number of amateur teen porn, cam girls gone wild and a whole lot of other categories in one single and very impressive collection of teen videos. Each comes with HD image and the tube’s fantastic streaming speed, something which will surely improve your adult experiences. Only rate teen porn and quality action, girls on fire in the mood to spin large inches of cock into each of their tiny love holes. Barely legal hotties working cock like true pornstars and a huge number of amateurs trying to make it into the big league. Either way you like your porn, this awesome teen tube will provide young flesh and spicy action at any hour. Only exclusive teen porn which is not available on other movie sites or tubes. Quality content with premium action and girls to die for. Enjoy such fantastic content on a tube that’s set to become number one, a tube which will make your delight with a very large variety of niches. Never mind browsing for teen sex on other tubes, this one right here offers a huge variety of movies and what you need for unbelievable experiences.

    datingnzcougar.info

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>