Passed
Pull Request — 1.x (#15)
by Kevin
33:03 queued 30:38
created

can_wait_until_visible_and_not_visible()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

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