-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathFacebook.php
More file actions
103 lines (80 loc) · 3.07 KB
/
Facebook.php
File metadata and controls
103 lines (80 loc) · 3.07 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
/**
* Created by PhpStorm.
* User: Findwayinsea
* Date: 2016/9/3
* Time: 14:57
*/
require __DIR__.'/vendor/autoload.php';
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\WebDriverBy;
use Facebook\WebDriver\WebDriverKeys;
use Facebook\WebDriver\WebDriverExpectedCondition;
class Facebook extends PHPUnit_Framework_TestCase {
/**
* @var \RemoteWebDriver
*/
protected $webDriver;
protected $url = 'https://github.com';
public function setUp()
{
$host = 'http://localhost:4444/wd/hub';
//$host = 'http://localhost:4444/wd/hub';
$desired_capabilities = DesiredCapabilities::chrome();
$desired_capabilities->setCapability('acceptSslCerts', false);
$this->webDriver = RemoteWebDriver::create($host, $desired_capabilities);
}
public function testGitHubHome()
{
$this->webDriver->get($this->url);
// checking that page title contains word 'GitHub'
$this->assertContains('GitHub', $this->webDriver->getTitle());
}
public function testSearch()
{
$this->webDriver->get($this->url);
// find search field by its id
$search = $this->webDriver->findElement(WebDriverBy::cssSelector('.header-search-input'));
$search->click();
$search->sendKeys('microsoft');
$search->submit();
}
public function testLogin()
{
$this->webDriver->get($this->url);
$this->webDriver->findElement(WebDriverBy::cssSelector('a.btn:nth-child(2)'))->click();
$this->webDriver->wait(10, 500)->until(
WebDriverExpectedCondition::titleContains('Sign in')
);
$this->webDriver->findElement(WebDriverBy::cssSelector('#login_field'))->sendKeys('github account email');
$pass = $this->webDriver->findElement(WebDriverBy::cssSelector('#password'));
$pass->sendKeys('password');
$pass->submit();
}
public function testSearch2()
{
$this->webDriver->get($this->url);
// find search field by its id
$search = $this->webDriver->findElement(WebDriverBy::cssSelector('.header-search-input'));
$search->click();
$search->sendKeys('php-webdriver');
$search->sendKeys(WebDriverKeys::ENTER);
$this->webDriver->wait(10, 500)->until(
WebDriverExpectedCondition::titleContains('Search')
);
$firstResult = $this->webDriver->findElement(WebDriverBy::cssSelector('li.repo-list-item:nth-child(1) > h3:nth-child(2) > a:nth-child(1)'));
$firstResult->click();
$this->webDriver->wait(10, 500)->until(
WebDriverExpectedCondition::not(WebDriverExpectedCondition::titleContains('Search'))
);
// we expect that facebook/php-webdriver was the first result
$this->assertContains("php-webdriver",$this->webDriver->getTitle());
// checking current url
$this->assertEquals(
'https://github.com/facebook/php-webdriver',
$this->webDriver->getCurrentURL()
);
}
}
?>