Skip to content

Instantly share code, notes, and snippets.

@Khanashima
Created February 14, 2016 14:34
Show Gist options
  • Save Khanashima/f601625cbbb6c84a924e to your computer and use it in GitHub Desktop.
Save Khanashima/f601625cbbb6c84a924e to your computer and use it in GitHub Desktop.
windowsでPHPでSelenium webdriverを使ってブラウザテスト ref: http://qiita.com/kiimiiis/items/30e173a3950e09816921
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
composer require phpunit/phpunit
composer require facebook/webdriver
<div id="test-id">test-value</div>
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.
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)
<?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