Passed
Push — 1.x ( 25b111...22285f )
by Kevin
06:44
created

PantherBrowserTest::cannot_follow_invisible_link()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 8
rs 10
c 1
b 1
f 0
1
<?php
2
3
namespace Zenstruck\Browser\Tests;
4
5
use PHPUnit\Framework\AssertionFailedError;
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\AssertionFailedError was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Symfony\Component\Panther\PantherTestCase;
7
use Zenstruck\Browser\PantherBrowser;
8
9
/**
10
 * @author Kevin Bond <[email protected]>
11
 *
12
 * @group panther
13
 */
14
final class PantherBrowserTest extends PantherTestCase
15
{
16
    use BrowserTests;
17
18
    /**
19
     * @test
20
     */
21
    public function can_take_screenshot(): void
22
    {
23
        self::catchFileContents(__DIR__.'/../var/browser/screenshots/screen.png', function() {
24
            $this->browser()
25
                ->visit('/page1')
26
                ->takeScreenshot('screen.png')
27
            ;
28
        });
29
    }
30
31
    /**
32
     * @test
33
     */
34
    public function can_wait(): void
35
    {
36
        $this->browser()
37
            ->visit('/javascript')
38
            ->assertNotSeeIn('#timeout-box', 'Contents of timeout box')
39
            ->wait(600)
40
            ->assertSeeIn('#timeout-box', 'Contents of timeout box')
41
        ;
42
    }
43
44
    /**
45
     * @test
46
     */
47
    public function can_wait_until_visible_and_not_visible(): void
48
    {
49
        $this->browser()
50
            ->visit('/javascript')
51
            ->assertNotSeeIn('#timeout-box', 'Contents of timeout box')
52
            ->waitUntilVisible('#timeout-box')
53
            ->assertSeeIn('#timeout-box', 'Contents of timeout box')
54
            ->assertNotSeeIn('#show-box', 'Contents of show box')
55
            ->click('show')
56
            ->waitUntilVisible('#show-box')
57
            ->assertSeeIn('#show-box', 'Contents of show box')
58
            ->assertSeeIn('#hide-box', 'Contents of hide box')
59
            ->click('hide')
60
            ->waitUntilNotVisible('#hide-box')
61
            ->assertNotSeeIn('#hide-box', 'Contents of hide box')
62
            ->assertSeeIn('#toggle-box', 'Contents of toggle box')
63
            ->click('toggle')
64
            ->waitUntilNotVisible('#toggle-box')
65
            ->assertNotSeeIn('#toggle-box', 'Contents of toggle box')
66
            ->click('toggle')
67
            ->waitUntilVisible('#toggle-box')
68
            ->assertSeeIn('#toggle-box', 'Contents of toggle box')
69
        ;
70
    }
71
72
    /**
73
     * @test
74
     */
75
    public function can_wait_until_see_in_and_not_see_in(): void
76
    {
77
        $this->browser()
78
            ->visit('/javascript')
79
            ->assertNotSeeIn('#timeout-box', 'Contents of timeout box')
80
            ->waitUntilSeeIn('#timeout-box', 'timeout')
81
            ->assertSeeIn('#timeout-box', 'Contents of timeout box')
82
            ->assertNotSeeIn('#show-box', 'Contents of show box')
83
            ->click('show')
84
            ->waitUntilSeeIn('#show-box', 'show')
85
            ->assertSeeIn('#show-box', 'Contents of show box')
86
            ->assertSeeIn('#hide-box', 'Contents of hide box')
87
            ->click('hide')
88
            ->waitUntilNotSeeIn('#hide-box', 'hide')
89
            ->assertNotSeeIn('#hide-box', 'Contents of hide box')
90
            ->assertNotSeeIn('#output', 'some text')
91
            ->fillField('input', 'some text')
92
            ->click('submit')
93
            ->waitUntilSeeIn('#output', 'some text')
94
            ->assertSeeIn('#output', 'some text')
95
            ->click('clear')
96
            ->waitUntilNotSeeIn('#output', 'some text')
97
            ->assertNotSeeIn('#output', 'some text')
98
        ;
99
    }
100
101
    /**
102
     * @test
103
     */
104
    public function can_check_if_element_is_visible_and_not_visible(): void
105
    {
106
        $this->browser()
107
            ->visit('/javascript')
108
            ->assertVisible('#hide-box')
109
            ->assertNotVisible('#show-box')
110
            ->assertNotVisible('#invalid-element')
111
        ;
112
    }
113
114
    /**
115
     * @test
116
     */
117
    public function can_save_console_log(): void
118
    {
119
        $contents = self::catchFileContents(__DIR__.'/../var/browser/console-logs/console.log', function() {
120
            $this->browser()
121
                ->visit('/javascript')
122
                ->click('log error')
123
                ->saveConsoleLog('console.log')
124
            ;
125
        });
126
127
        $this->assertStringContainsString('        "level": "SEVERE",', $contents);
128
        $this->assertStringContainsString('console.error message', $contents);
129
    }
130
131
    /**
132
     * @test
133
     */
134
    public function can_dump_console_log_with_console_error(): void
135
    {
136
        $output = self::catchVarDumperOutput(function() {
137
            $this->browser()
138
                ->visit('/javascript')
139
                ->click('log error')
140
                ->dumpConsoleLog()
141
            ;
142
        });
143
144
        $this->assertStringContainsString('console.error message', \json_encode($output, JSON_THROW_ON_ERROR));
145
    }
146
147
    /**
148
     * @test
149
     */
150
    public function can_dump_console_log_with_throw_error(): void
151
    {
152
        $output = self::catchVarDumperOutput(function() {
153
            $this->browser()
154
                ->visit('/javascript')
155
                ->click('throw error')
156
                ->dumpConsoleLog()
157
            ;
158
        });
159
160
        $this->assertStringContainsString('Error: error object message', \json_encode($output, JSON_THROW_ON_ERROR));
161
    }
162
163
    /**
164
     * @test
165
     */
166
    public function cannot_follow_invisible_link(): void
167
    {
168
        $this->expectException(AssertionFailedError::class);
169
        $this->expectErrorMessage('Link "invisible link" is not visible.');
170
171
        $this->browser()
172
            ->visit('/javascript')
173
            ->follow('invisible link')
174
        ;
175
    }
176
177
    protected function browser(): PantherBrowser
178
    {
179
        return $this->pantherBrowser();
180
    }
181
}
182