-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGitHubLoginValidationTest.php
More file actions
91 lines (79 loc) · 3.34 KB
/
Copy pathGitHubLoginValidationTest.php
File metadata and controls
91 lines (79 loc) · 3.34 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
<?php
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\WebDriverBy;
use PHPUnit\Framework\TestCase;
use Facebook\WebDriver\WebDriverExpectedCondition;
use Facebook\WebDriver\WebDriverWait;
use Facebook\WebDriver\Exception\TimeOutException;
class GitHubLoginValidationTest extends TestCase
{
private $driver;
private $wait;
protected function setUp(): void
{
$options = new ChromeOptions();
$options->addArguments(['--no-sandbox', '--disable-dev-shm-usage']);
$capabilities = DesiredCapabilities::chrome();
$capabilities->setCapability(ChromeOptions::CAPABILITY, $options);
$this->driver = RemoteWebDriver::create('http://localhost:9515', $capabilities);
$this->wait = new WebDriverWait($this->driver, 20); // 20 second timeout
}
/**
* @dataProvider loginCredentialsProvider
*/
public function testGitHubLoginValidation(string $email, string $password)
{
try {
// Navigate to GitHub login page
$this->driver->get('https://github.com/login');
// Wait for login form
$loginField = $this->wait->until(
WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::id('login_field'))
);
$this->assertNotNull($loginField, 'Login field should be present');
// Fill login form
$this->driver->findElement(WebDriverBy::id('login_field'))->sendKeys($email);
$this->driver->findElement(WebDriverBy::id('password'))->sendKeys($password);
// Click sign-in and wait
$this->driver->findElement(WebDriverBy::cssSelector('input[type="submit"]'))->click();
sleep(3);
// Check for success or error
try {
$avatar = $this->wait->until(
WebDriverExpectedCondition::presenceOfElementLocated(
WebDriverBy::cssSelector('.avatar')
)
);
$this->assertNotNull($avatar, 'Avatar should be present after successful login');
return ['success' => true, 'message' => 'Login successful'];
} catch (TimeOutException $e) {
$errorMessage = '';
try {
$errorElement = $this->driver->findElement(WebDriverBy::cssSelector('.flash-error'));
$errorMessage = $errorElement->getText();
$this->fail("Login failed with message: $errorMessage");
} catch (\Exception $inner) {
$this->fail('Login failed without error message');
}
return ['success' => false, 'message' => $errorMessage];
}
} catch (\Exception $e) {
$this->fail("Test failed with exception: " . $e->getMessage());
return ['success' => false, 'message' => $e->getMessage()];
}
}
public static function loginCredentialsProvider(): array
{
return [
'valid_credentials' => ['test@gmail.com', 'test']
];
}
protected function tearDown(): void
{
if ($this->driver) {
$this->driver->quit();
}
}
}