Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit a0485d4

Browse files
committed
Unit tests for WebDriverCommand and DesiredCapabilities
1 parent ef5d089 commit a0485d4

File tree

2 files changed

+161
-0
lines changed

2 files changed

+161
-0
lines changed
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
<?php
2+
// Copyright 2004-present Facebook. All Rights Reserved.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
namespace Facebook\WebDriver\Remote;
17+
18+
use Facebook\WebDriver\Firefox\FirefoxDriver;
19+
use Facebook\WebDriver\Firefox\FirefoxPreferences;
20+
use Facebook\WebDriver\Firefox\FirefoxProfile;
21+
use Facebook\WebDriver\WebDriverPlatform;
22+
23+
class DesiredCapabilitiesTest extends \PHPUnit_Framework_TestCase
24+
{
25+
public function testShouldInstantiateWithCapabilitiesGivenInConstructor()
26+
{
27+
$capabilities = new DesiredCapabilities(
28+
array('fooKey' => 'fooVal', WebDriverCapabilityType::PLATFORM => WebDriverPlatform::ANY)
29+
);
30+
31+
$this->assertSame('fooVal', $capabilities->getCapability('fooKey'));
32+
$this->assertSame('ANY', $capabilities->getPlatform());
33+
34+
$this->assertSame(
35+
array('fooKey' => 'fooVal', WebDriverCapabilityType::PLATFORM => WebDriverPlatform::ANY),
36+
$capabilities->toArray()
37+
);
38+
}
39+
40+
public function testShouldInstantiateEmptyInstance()
41+
{
42+
$capabilities = new DesiredCapabilities();
43+
44+
$this->assertNull($capabilities->getCapability('foo'));
45+
$this->assertSame(array(), $capabilities->toArray());
46+
}
47+
48+
public function testShouldProvideAccessToCapabilitiesUsingSettersAndGetters()
49+
{
50+
$capabilities = new DesiredCapabilities();
51+
// generic capability setter
52+
$capabilities->setCapability('custom', 1337);
53+
// specific setters
54+
$capabilities->setBrowserName(WebDriverBrowserType::CHROME);
55+
$capabilities->setPlatform(WebDriverPlatform::LINUX);
56+
$capabilities->setVersion(333);
57+
58+
$this->assertSame(1337, $capabilities->getCapability('custom'));
59+
$this->assertSame(WebDriverBrowserType::CHROME, $capabilities->getBrowserName());
60+
$this->assertSame(WebDriverPlatform::LINUX, $capabilities->getPlatform());
61+
$this->assertSame(333, $capabilities->getVersion());
62+
}
63+
64+
/**
65+
* @expectedException \Exception
66+
* @expectedExceptionMessage isJavascriptEnable() is a htmlunit-only option
67+
*/
68+
public function testShouldNotAllowToDisableJavascriptForNonHtmlUnitBrowser()
69+
{
70+
$capabilities = new DesiredCapabilities();
71+
$capabilities->setBrowserName(WebDriverBrowserType::FIREFOX);
72+
$capabilities->setJavascriptEnabled(false);
73+
}
74+
75+
public function testShouldAllowToDisableJavascriptForHtmlUnitBrowser()
76+
{
77+
$capabilities = new DesiredCapabilities();
78+
$capabilities->setBrowserName(WebDriverBrowserType::HTMLUNIT);
79+
$capabilities->setJavascriptEnabled(false);
80+
81+
$this->assertFalse($capabilities->isJavascriptEnabled());
82+
}
83+
84+
/**
85+
* @dataProvider browserCapabilitiesProvider
86+
* @param string $setupMethod
87+
* @param string $expectedBrowser
88+
* @param string $expectedPlatform
89+
*/
90+
public function testShouldProvideShortcutSetupForCapabilitiesOfEachBrowser(
91+
$setupMethod,
92+
$expectedBrowser,
93+
$expectedPlatform
94+
)
95+
{
96+
/** @var DesiredCapabilities $capabilities */
97+
$capabilities = call_user_func(array('Facebook\WebDriver\Remote\DesiredCapabilities', $setupMethod));
98+
99+
$this->assertSame($expectedBrowser, $capabilities->getBrowserName());
100+
$this->assertSame($expectedPlatform, $capabilities->getPlatform());
101+
}
102+
103+
/**
104+
* @return array
105+
*/
106+
public function browserCapabilitiesProvider()
107+
{
108+
return array(
109+
array('android', WebDriverBrowserType::ANDROID, WebDriverPlatform::ANDROID),
110+
array('chrome', WebDriverBrowserType::CHROME, WebDriverPlatform::ANY),
111+
array('firefox', WebDriverBrowserType::FIREFOX, WebDriverPlatform::ANY),
112+
array('htmlUnit', WebDriverBrowserType::HTMLUNIT, WebDriverPlatform::ANY),
113+
array('htmlUnitWithJS', WebDriverBrowserType::HTMLUNIT, WebDriverPlatform::ANY),
114+
array('internetExplorer', WebDriverBrowserType::IE, WebDriverPlatform::WINDOWS),
115+
array('iphone', WebDriverBrowserType::IPHONE, WebDriverPlatform::MAC),
116+
array('ipad', WebDriverBrowserType::IPAD, WebDriverPlatform::MAC),
117+
array('opera', WebDriverBrowserType::OPERA, WebDriverPlatform::ANY),
118+
array('safari', WebDriverBrowserType::SAFARI, WebDriverPlatform::ANY),
119+
array('phantomjs', WebDriverBrowserType::PHANTOMJS, WebDriverPlatform::ANY),
120+
);
121+
}
122+
123+
public function testShouldSetupFirefoxProfileAndDisableReaderViewForFirefoxBrowser()
124+
{
125+
$capabilities = DesiredCapabilities::firefox();
126+
127+
/** @var FirefoxProfile $firefoxProfile */
128+
$firefoxProfile = $capabilities->getCapability(FirefoxDriver::PROFILE);
129+
$this->assertInstanceOf('Facebook\WebDriver\Firefox\FirefoxProfile', $firefoxProfile);
130+
131+
$this->assertSame('false', $firefoxProfile->getPreference(FirefoxPreferences::READER_PARSE_ON_LOAD_ENABLED));
132+
}
133+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
// Copyright 2004-present Facebook. All Rights Reserved.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
namespace Facebook\WebDriver\Remote;
17+
18+
class WebDriverCommandTest extends \PHPUnit_Framework_TestCase
19+
{
20+
public function testShouldSetOptionsUsingConstructot()
21+
{
22+
$command = new WebDriverCommand('session-id-123', 'bar-baz-name', array('foo' => 'bar'));
23+
24+
$this->assertSame('session-id-123', $command->getSessionID());
25+
$this->assertSame('bar-baz-name', $command->getName());
26+
$this->assertSame(array('foo' => 'bar'), $command->getParameters());
27+
}
28+
}

0 commit comments

Comments
 (0)