Created
February 14, 2016 14:34
-
-
Save Khanashima/f601625cbbb6c84a924e to your computer and use it in GitHub Desktop.
windowsでPHPでSelenium webdriverを使ってブラウザテスト ref: http://qiita.com/kiimiiis/items/30e173a3950e09816921
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
C:\D\selenium>java -jar selenium-server-standalone-2.52.0.jar -role hub -port 4445 | |
C:\D\selenium>java -jar selenium-server-standalone-2.52.0.jar -role node -hub http://localhost:4445/grid/register |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
composer require phpunit/phpunit | |
composer require facebook/webdriver |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="test-id">test-value</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
C:\D\vagrant\laravel51\selenium>vendor\bin\phpunit webTest | |
PHPUnit 5.2.5 by Sebastian Bergmann and contributors. | |
F 1 / 1 (100%) | |
Time: 29.34 seconds, Memory: 2.50Mb | |
There was 1 failure: | |
1) webTest::testWebUI | |
Failed asserting that two strings are identical. | |
--- Expected | |
+++ Actual | |
@@ @@ | |
-Expected | |
+test-value | |
C:\D\vagrant\laravel51\selenium\webTest.php:23 | |
FAILURES! | |
Tests: 1, Assertions: 1, Failures: 1. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
C:\D\vagrant\laravel51\selenium>vendor\bin\phpunit webTest | |
PHPUnit 5.2.5 by Sebastian Bergmann and contributors. | |
. 1 / 1 (100%) | |
Time: 15.56 seconds, Memory: 2.50Mb | |
OK (1 test, 1 assertion) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Facebook\WebDriver; | |
use Facebook\WebDriver\WebDriverExpectedCondition; | |
use Facebook\WebDriver\WebDriverBy; | |
use Facebook\WebDriver\Remote; | |
use Facebook\WebDriver\Remote\RemoteWebDriver; | |
use Facebook\WebDriver\Remote\DesiredCapabilities; | |
class webTest extends PHPUnit_Framework_TestCase | |
{ | |
public function testWebUI() | |
{ | |
//hostの登録 | |
$host = 'http://localhost:4445/wd/hub'; | |
//どのブラウザを使うか設定 | |
$driver = RemoteWebDriver::create($host, DesiredCapabilities::firefox()); | |
//テストするサイトに移動 | |
$driver->get('http://192.168.33.51/'); | |
//idがtest-idの要素を取得 | |
$testId = $driver->findElement( | |
WebDriverBy::id('test-id') | |
); | |
//test-idのテキストを取得する | |
$text = $testId->getText(); | |
//期待値とあっているかのテスト | |
$this->assertSame('Expected', $text); | |
//ブラウザを閉じる | |
//$driver->close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment