18
18
package org .openqa .selenium .grid .router ;
19
19
20
20
import static org .assertj .core .api .AssertionsForClassTypes .assertThat ;
21
+ import static org .openqa .selenium .testing .drivers .Browser .*;
21
22
22
23
import java .io .StringReader ;
23
24
import java .util .Collections ;
25
+ import java .util .Objects ;
24
26
import java .util .concurrent .CompletableFuture ;
25
27
import java .util .concurrent .ExecutionException ;
26
28
import java .util .concurrent .TimeUnit ;
27
29
import java .util .concurrent .TimeoutException ;
30
+ import org .junit .jupiter .api .AfterEach ;
31
+ import org .junit .jupiter .api .BeforeEach ;
28
32
import org .junit .jupiter .api .Test ;
29
33
import org .openqa .selenium .By ;
30
34
import org .openqa .selenium .WebDriver ;
40
44
import org .openqa .selenium .bidi .module .LogInspector ;
41
45
import org .openqa .selenium .environment .webserver .AppServer ;
42
46
import org .openqa .selenium .environment .webserver .NettyAppServer ;
43
- import org .openqa .selenium .firefox .FirefoxOptions ;
44
47
import org .openqa .selenium .grid .config .TomlConfig ;
45
48
import org .openqa .selenium .grid .router .DeploymentTypes .Deployment ;
46
49
import org .openqa .selenium .remote .Augmenter ;
47
50
import org .openqa .selenium .remote .RemoteWebDriver ;
51
+ import org .openqa .selenium .testing .Ignore ;
52
+ import org .openqa .selenium .testing .NotYetImplemented ;
48
53
import org .openqa .selenium .testing .drivers .Browser ;
49
54
50
55
class RemoteWebDriverBiDiTest {
56
+ private WebDriver driver ;
57
+ private AppServer server ;
51
58
52
- @ Test
53
- void ensureBiDiSessionCreation () {
54
- Browser browser = Browser .FIREFOX ;
59
+ @ BeforeEach
60
+ void setup () {
61
+ Browser browser = Objects . requireNonNull ( Browser .detect ()) ;
55
62
56
63
Deployment deployment =
57
64
DeploymentTypes .STANDALONE .start (
@@ -63,47 +70,34 @@ void ensureBiDiSessionCreation() {
63
70
+ "driver-implementation = "
64
71
+ browser .displayName ())));
65
72
66
- FirefoxOptions options = createFirefoxOptions ();
67
- // Enable BiDi
68
- options .setCapability ("webSocketUrl" , true );
69
- options .merge (Browser .FIREFOX .getCapabilities ());
70
-
71
- WebDriver driver = new RemoteWebDriver (deployment .getServer ().getUrl (), options );
73
+ driver = new RemoteWebDriver (deployment .getServer ().getUrl (), browser .getCapabilities ());
72
74
driver = new Augmenter ().augment (driver );
73
75
76
+ server = new NettyAppServer ();
77
+ server .start ();
78
+ }
79
+
80
+ @ Test
81
+ @ Ignore (IE )
82
+ @ Ignore (SAFARI )
83
+ @ NotYetImplemented (EDGE )
84
+ void ensureBiDiSessionCreation () {
74
85
try (BiDi biDi = ((HasBiDi ) driver ).getBiDi ()) {
75
86
BiDiSessionStatus status =
76
87
biDi .send (
77
88
new Command <>("session.status" , Collections .emptyMap (), BiDiSessionStatus .class ));
78
89
assertThat (status ).isNotNull ();
79
- assertThat (status .getMessage ()).isEqualTo ( "Session already started" );
90
+ assertThat (status .getMessage ()).isNotEmpty ( );
80
91
}
81
92
}
82
93
83
94
@ Test
95
+ @ Ignore (IE )
96
+ @ Ignore (SAFARI )
97
+ @ NotYetImplemented (EDGE )
84
98
void canListenToLogs () throws ExecutionException , InterruptedException , TimeoutException {
85
- Browser browser = Browser .FIREFOX ;
86
-
87
- Deployment deployment =
88
- DeploymentTypes .STANDALONE .start (
89
- browser .getCapabilities (),
90
- new TomlConfig (
91
- new StringReader (
92
- "[node]\n "
93
- + "selenium-manager = false\n "
94
- + "driver-implementation = "
95
- + browser .displayName ())));
96
-
97
- FirefoxOptions options = createFirefoxOptions ();
98
- // Enable BiDi
99
- options .setCapability ("webSocketUrl" , true );
100
-
101
- WebDriver driver = new RemoteWebDriver (deployment .getServer ().getUrl (), options );
102
99
driver = new Augmenter ().augment (driver );
103
100
104
- AppServer server = new NettyAppServer ();
105
- server .start ();
106
-
107
101
try (LogInspector logInspector = new LogInspector (driver )) {
108
102
CompletableFuture <ConsoleLogEntry > future = new CompletableFuture <>();
109
103
logInspector .onConsoleEntry (future ::complete );
@@ -120,34 +114,14 @@ void canListenToLogs() throws ExecutionException, InterruptedException, TimeoutE
120
114
assertThat (logEntry .getType ()).isEqualTo ("console" );
121
115
assertThat (logEntry .getLevel ()).isEqualTo (LogLevel .INFO );
122
116
assertThat (logEntry .getMethod ()).isEqualTo ("log" );
123
- assertThat (logEntry .getStackTrace ()).isNull ();
124
117
}
125
118
}
126
119
127
120
@ Test
121
+ @ Ignore (IE )
122
+ @ Ignore (SAFARI )
123
+ @ NotYetImplemented (EDGE )
128
124
void canNavigateToUrl () {
129
- Browser browser = Browser .FIREFOX ;
130
-
131
- Deployment deployment =
132
- DeploymentTypes .STANDALONE .start (
133
- browser .getCapabilities (),
134
- new TomlConfig (
135
- new StringReader (
136
- "[node]\n "
137
- + "selenium-manager = false\n "
138
- + "driver-implementation = "
139
- + browser .displayName ())));
140
-
141
- FirefoxOptions options = createFirefoxOptions ();
142
- // Enable BiDi
143
- options .setCapability ("webSocketUrl" , true );
144
-
145
- WebDriver driver = new RemoteWebDriver (deployment .getServer ().getUrl (), options );
146
- driver = new Augmenter ().augment (driver );
147
-
148
- AppServer server = new NettyAppServer ();
149
- server .start ();
150
-
151
125
BrowsingContext browsingContext = new BrowsingContext (driver , WindowType .TAB );
152
126
153
127
String url = server .whereIs ("/bidi/logEntryAdded.html" );
@@ -158,7 +132,9 @@ void canNavigateToUrl() {
158
132
assertThat (info .getUrl ()).contains ("/bidi/logEntryAdded.html" );
159
133
}
160
134
161
- private FirefoxOptions createFirefoxOptions () {
162
- return (FirefoxOptions ) Browser .FIREFOX .getCapabilities ();
135
+ @ AfterEach
136
+ void clean () {
137
+ driver .quit ();
138
+ server .stop ();
163
139
}
164
140
}
0 commit comments