1717
1818package org .openqa .selenium .chrome ;
1919
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 ;
2622import org .junit .jupiter .api .Test ;
2723import org .openqa .selenium .By ;
2824import org .openqa .selenium .WebElement ;
2925import org .openqa .selenium .build .InProject ;
3026import org .openqa .selenium .testing .JupiterTestBase ;
3127import 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 ;
3336
3437class ChromeOptionsFunctionalTest extends JupiterTestBase {
3538
3639 private static final String EXT_PATH = "common/extensions/webextensions-selenium-example.crx" ;
3740
41+ @ AfterAll
42+ public static void resetBrowser () {
43+ seleniumExtension .removeDriver ();
44+ }
45+
3846 @ Test
39- @ NoDriverBeforeTest
4047 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 ();
4549 options .addArguments ("user-agent=foo;bar" );
46- localDriver = new ChromeDriver (options );
50+ localDriver = seleniumExtension . createNewDriver (options );
4751
4852 localDriver .get (pages .clickJacker );
4953 Object userAgent =
@@ -63,12 +67,9 @@ void optionsStayEqualAfterSerialization() {
6367 @ Test
6468 @ NoDriverBeforeTest
6569 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 ();
7071 options .setAcceptInsecureCerts (true );
71- localDriver = new ChromeDriver (options );
72+ localDriver = seleniumExtension . createNewDriver (options );
7273
7374 assertThat (((ChromeDriver ) localDriver ).getCapabilities ().getCapability (ACCEPT_INSECURE_CERTS ))
7475 .isEqualTo (true );
@@ -77,15 +78,11 @@ public void canSetAcceptInsecureCerts() {
7778 @ Test
7879 @ NoDriverBeforeTest
7980 public void canAddExtensionFromFile () {
80- ChromeOptions options = new ChromeOptions ();
81- if (TestUtilities .isOnTravis ()) {
82- options .addArguments ("--headless=chrome" );
83- }
81+ ChromeOptions options = createChromeOptionsForExtensions ();
8482 options .addExtensions (InProject .locate (EXT_PATH ).toFile ());
85- localDriver = new ChromeDriver (options );
86-
87- localDriver .get (pages .echoPage );
83+ localDriver = seleniumExtension .createNewDriver (options );
8884
85+ localDriver .get (toLocalUrl (pages .echoPage ));
8986 WebElement footerElement = localDriver .findElement (By .id ("webextensions-selenium-example" ));
9087
9188 String footText = footerElement .getText ();
@@ -95,13 +92,10 @@ public void canAddExtensionFromFile() {
9592 @ Test
9693 @ NoDriverBeforeTest
9794 public void canAddExtensionFromStringEncodedInBase64 () throws IOException {
98- ChromeOptions options = new ChromeOptions ();
99- if (TestUtilities .isOnTravis ()) {
100- options .addArguments ("--headless=chrome" );
101- }
95+ ChromeOptions options = createChromeOptionsForExtensions ();
10296 options .addEncodedExtensions (
10397 Base64 .getEncoder ().encodeToString (Files .readAllBytes (InProject .locate (EXT_PATH ))));
104- localDriver = new ChromeDriver (options );
98+ localDriver = seleniumExtension . createNewDriver (options );
10599
106100 localDriver .get (pages .echoPage );
107101
@@ -110,4 +104,9 @@ public void canAddExtensionFromStringEncodedInBase64() throws IOException {
110104 String footText = footerElement .getText ();
111105 assertThat (footText ).isEqualTo ("Content injected by webextensions-selenium-example" );
112106 }
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+ }
113112}
0 commit comments