17
17
18
18
package org .openqa .selenium .chrome ;
19
19
20
- import static org .assertj .core .api .Assertions .assertThat ;
21
- import static org .openqa .selenium .remote .CapabilityType .ACCEPT_INSECURE_CERTS ;
22
-
23
- import java .io .IOException ;
24
- import java .nio .file .Files ;
25
- import java .util .Base64 ;
20
+ import com .google .common .collect .ImmutableMap ;
21
+ import org .junit .jupiter .api .AfterAll ;
26
22
import org .junit .jupiter .api .Test ;
27
23
import org .openqa .selenium .By ;
28
24
import org .openqa .selenium .WebElement ;
29
25
import org .openqa .selenium .build .InProject ;
30
26
import org .openqa .selenium .testing .JupiterTestBase ;
31
27
import org .openqa .selenium .testing .NoDriverBeforeTest ;
32
- import org .openqa .selenium .testing .TestUtilities ;
28
+ import org .openqa .selenium .testing .drivers .Browser ;
29
+
30
+ import java .io .IOException ;
31
+ import java .nio .file .Files ;
32
+ import java .util .Base64 ;
33
+
34
+ import static org .assertj .core .api .Assertions .assertThat ;
35
+ import static org .openqa .selenium .remote .CapabilityType .ACCEPT_INSECURE_CERTS ;
33
36
34
37
class ChromeOptionsFunctionalTest extends JupiterTestBase {
35
38
36
39
private static final String EXT_PATH = "common/extensions/webextensions-selenium-example.crx" ;
37
40
41
+ @ AfterAll
42
+ public static void resetBrowser () {
43
+ seleniumExtension .removeDriver ();
44
+ }
45
+
38
46
@ Test
39
- @ NoDriverBeforeTest
40
47
public void canStartChromeWithCustomOptions () {
41
- ChromeOptions options = new ChromeOptions ();
42
- if (TestUtilities .isOnTravis ()) {
43
- options .addArguments ("--headless=chrome" );
44
- }
48
+ ChromeOptions options = (ChromeOptions ) Browser .CHROME .getCapabilities ();
45
49
options .addArguments ("user-agent=foo;bar" );
46
- localDriver = new ChromeDriver (options );
50
+ localDriver = seleniumExtension . createNewDriver (options );
47
51
48
52
localDriver .get (pages .clickJacker );
49
53
Object userAgent =
@@ -63,12 +67,9 @@ void optionsStayEqualAfterSerialization() {
63
67
@ Test
64
68
@ NoDriverBeforeTest
65
69
public void canSetAcceptInsecureCerts () {
66
- ChromeOptions options = new ChromeOptions ();
67
- if (TestUtilities .isOnTravis ()) {
68
- options .addArguments ("--headless=chrome" );
69
- }
70
+ ChromeOptions options = (ChromeOptions ) Browser .CHROME .getCapabilities ();
70
71
options .setAcceptInsecureCerts (true );
71
- localDriver = new ChromeDriver (options );
72
+ localDriver = seleniumExtension . createNewDriver (options );
72
73
73
74
assertThat (((ChromeDriver ) localDriver ).getCapabilities ().getCapability (ACCEPT_INSECURE_CERTS ))
74
75
.isEqualTo (true );
@@ -77,15 +78,11 @@ public void canSetAcceptInsecureCerts() {
77
78
@ Test
78
79
@ NoDriverBeforeTest
79
80
public void canAddExtensionFromFile () {
80
- ChromeOptions options = new ChromeOptions ();
81
- if (TestUtilities .isOnTravis ()) {
82
- options .addArguments ("--headless=chrome" );
83
- }
81
+ ChromeOptions options = createChromeOptionsForExtensions ();
84
82
options .addExtensions (InProject .locate (EXT_PATH ).toFile ());
85
- localDriver = new ChromeDriver (options );
86
-
87
- localDriver .get (pages .echoPage );
83
+ localDriver = seleniumExtension .createNewDriver (options );
88
84
85
+ localDriver .get (toLocalUrl (pages .echoPage ));
89
86
WebElement footerElement = localDriver .findElement (By .id ("webextensions-selenium-example" ));
90
87
91
88
String footText = footerElement .getText ();
@@ -95,13 +92,10 @@ public void canAddExtensionFromFile() {
95
92
@ Test
96
93
@ NoDriverBeforeTest
97
94
public void canAddExtensionFromStringEncodedInBase64 () throws IOException {
98
- ChromeOptions options = new ChromeOptions ();
99
- if (TestUtilities .isOnTravis ()) {
100
- options .addArguments ("--headless=chrome" );
101
- }
95
+ ChromeOptions options = createChromeOptionsForExtensions ();
102
96
options .addEncodedExtensions (
103
97
Base64 .getEncoder ().encodeToString (Files .readAllBytes (InProject .locate (EXT_PATH ))));
104
- localDriver = new ChromeDriver (options );
98
+ localDriver = seleniumExtension . createNewDriver (options );
105
99
106
100
localDriver .get (pages .echoPage );
107
101
@@ -110,4 +104,9 @@ public void canAddExtensionFromStringEncodedInBase64() throws IOException {
110
104
String footText = footerElement .getText ();
111
105
assertThat (footText ).isEqualTo ("Content injected by webextensions-selenium-example" );
112
106
}
107
+
108
+ private ChromeOptions createChromeOptionsForExtensions () {
109
+ ChromeOptions options = (ChromeOptions ) Browser .CHROME .getCapabilities ();
110
+ return options .setExperimentalOption ("prefs" , ImmutableMap .of ("extensions.ui.developer_mode" , true ));
111
+ }
113
112
}
0 commit comments