Skip to content

Instantly share code, notes, and snippets.

@susanBuck
Created December 14, 2012 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save susanBuck/4285279 to your computer and use it in GitHub Desktop.
Save susanBuck/4285279 to your computer and use it in GitHub Desktop.
Learning Selenium / PHPUnit Final code from the following tutorial: http://net.tutsplus.com/tutorials/php/how-to-use-selenium-2-with-phpunit/?search_index=1
<html>
<head>
<title></title>
</head>
<body>
<h1>Hello, susan</h1>
</body>
</html>
<!doctype html>
<html>
<head>
<title></title>
</head>
<body>
<form action="admin.php">
<input type="text" name="username" id="username">
<input type="text" name="password" id="password">
<input type="submit" value="Login" id="submit">
<a href="">Sign Up!</a>
<a href="">Forgot Password?</a>
</form>
<script src="http://code.jquery.com/jquery.js"></script>
<script>
(function() {
var username = $('#username');
var password = $('#password');
var submit = $('#submit').attr('disabled', 'disabled');
$('input').on('keyup', function() {
var notEmpty = username.val() && password.val();
notEmpty
? submit.removeAttr('disabled')
: submit.attr('disabled', 'disabled');
});
})();
</script>
</body>
</html>
<?php
class TestLogin extends PHPUnit_Extensions_Selenium2TestCase {
public function setUp()
{
$this->setHost('localhost');
$this->setPort(4444);
$this->setBrowser('firefox');
$this->setBrowserUrl('http://localhost/seleniumTut');
}
public function testHasLoginForm()
{
$this->url('index.php');
$username = $this->byName('username');
$password = $this->byName('password');
$this->assertEquals('', $username->value());
$this->assertEquals('', $password->value());
}
public function testLoginFormSubmitsToAdmin()
{
$this->url('index.php');
$form = $this->byCssSelector('form');
$action = $form->attribute('action');
$this->assertContains('admin.php', $action);
$this->byName('username')->value('susan');
$this->byName('password')->value('1234');
$form->submit();
$welcome = $this->byCssSelector('h1')->text();
$this->assertRegExp('/susan/i', $welcome);
}
public function testSubmitButtonIsDisabledUntilFieldsAreFilled()
{
$this->url('index.php');
$username = $this->byName('username');
$password = $this->byName('password');
$submit = $this->byId('submit');
$this->assertFalse($submit->enabled());
$username->value('susan');
$password->value('1234');
$this->assertTrue($submit->enabled());
$username->clear();
$password->clear();
$username->value(' '); // force keyup event
$this->assertFalse($submit->enabled());
}
public function testOffersSignUpAndForgotPasswordLinks()
{
$this->url('index.php');
$this->assertRegExp('/sign ?up/i', $this->source());
$this->assertRegExp('/forgot password/i', $this->source());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment