-
Notifications
You must be signed in to change notification settings - Fork 1
/
README
86 lines (62 loc) · 2.6 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
PHPWebdriver
This is library for writing functional Selenium 2 Webdriver tests in PHP.
It works using JsonWireProtocol to communicate with Selenium server.
To see how it works see test directory.
/////
Introduction
This is site for developers of PHP bindings for Selenium WebDriver (Selenium 2). This PHP library allows creating functional webdriver tests with PHP.
Details
Library communicates with Selenium Server using JsonWireProtocol. Requires curl in PHP. List of implemented methods: implemented_methods.
Latest version 0.9.1 works properly with Selenium server 2.37.0
Example
<?php
require_once "phpwebdriver/WebDriver.php";
require_once "phpwebdriver/LocatorStrategy.php";
$webdriver = new WebDriver("localhost", "4444");
$webdriver->connect("firefox");
$webdriver->get("http://google.com");
$element = $webdriver->findElementBy(LocatorStrategy::name, "q");
$element->sendKeys(array("selenium with php"));
$element->submit();
//$webdriver->close();
combobox handling
$this->webdriver->get($this->test_url);
$element = $this->webdriver->findElementBy(LocatorStrategy::name, "sel1");
$option3 = $element->findOptionElementByText("option 3");
$option3->click();
$this->assertTrue($option3->isSelected());
$option2 = $element->findOptionElementByValue("2");
$option2->click();
$this->assertFalse($option3->isSelected());
$this->assertTrue($option2->isSelected());
Use your existing Selenium1 tests (also generated with Selenium IDE)
Use CWebDriverTestCase.php class which provides interface like classic selenium test class:
class WebTestCase extends CWebDriverTestCase
{
protected function setUp()
{
parent::setUp();
$this->setBrowserUrl('http://yourapp123.com');
}
/** generate screenshot if any test has failed */
protected function tearDown()
{
if( $this->hasFailed() ) {
$date = "screenshot_" . date('Y-m-d-H-i-s') . ".png" ;
$this->webdriver->getScreenshotAndSaveToFile( $date );
}
$this->close();
}
protected function testSomething( )
{
$this->open( "/index-test.php/user/login", "expect-div-with-this-id-after-load-page" );
$this->type( "LoginForm_username", "your_login" );
$this->type( "LoginForm_password", "your_pass" );
$this->click( "login-button" );
// getElement will try few times to find element
$this->getElement( LocatorStrategy::id, 'top-user-data' );
$this->assertTrue( $this->isTextPresent( "Logged as: your_pass" ) );
}
}
Yii framework extension
Use Webdriver/Selenium2 in your Yii application: http://www.yiiframework.com/extension/webdriver-test