3737import org .junit .rules .TestWatcher ;
3838import org .junit .runner .Description ;
3939import org .junit .runners .model .Statement ;
40- import org .openqa .selenium .build .BazelBuild ;
4140import org .openqa .selenium .Capabilities ;
4241import org .openqa .selenium .JavascriptExecutor ;
4342import org .openqa .selenium .MutableCapabilities ;
4443import org .openqa .selenium .WebDriver ;
4544import org .openqa .selenium .WrapsDriver ;
45+ import org .openqa .selenium .build .BazelBuild ;
46+ import org .openqa .selenium .build .InProject ;
4647import org .openqa .selenium .chrome .ChromeOptions ;
4748import org .openqa .selenium .edge .EdgeOptions ;
4849import org .openqa .selenium .environment .GlobalTestEnvironment ;
5152import org .openqa .selenium .ie .InternetExplorerOptions ;
5253import org .openqa .selenium .opera .OperaOptions ;
5354import org .openqa .selenium .remote .DesiredCapabilities ;
54- import org .openqa .selenium .build .InProject ;
5555import org .openqa .selenium .safari .SafariOptions ;
5656import org .openqa .selenium .testing .drivers .Browser ;
5757import org .openqa .selenium .testing .drivers .WebDriverBuilder ;
@@ -84,53 +84,6 @@ public class InternalSelenseTestBase extends SeleneseTestBase {
8484 "type" );
8585
8686 private static Selenium INSTANCE ;
87-
88- @ BeforeClass
89- public static void buildJavascriptLibraries () throws IOException {
90- if (!Files .exists (InProject .findProjectRoot ().resolve ("Rakefile" ))) {
91- // we're not in dev mode
92- return ;
93- }
94-
95- log .info ("In dev mode. Copying required files in case we're using a WebDriver-backed Selenium" );
96-
97- BazelBuild bazel = new BazelBuild ();
98-
99- Path dir =
100- InProject .locate ("java/build/production/com/thoughtworks/selenium/webdriven" );
101- Files .createDirectories (dir );
102- for (String target : ATOM_TARGETS ) {
103- bazel .build ("//javascript/selenium-atoms:" + target );
104- copy ("javascript/selenium-atoms/" + target + ".js" ,
105- "com/thoughtworks/selenium/webdriven/" + target + ".js" );
106- }
107- bazel .build ("//third_party/js/sizzle:sizzle" );
108- copy ("third_party/js/sizzle/sizzle.js" ,
109- "com/thoughtworks/selenium/webdriven/sizzle.js" );
110- }
111-
112- private static void copy (String copyFrom , String copyTo ) {
113- try {
114- Path source = InProject .locate ("bazel-bin" ).resolve (copyFrom );
115- Path dest = InProject .locate ("java/build/test" ).resolve (copyTo );
116-
117- if (Files .exists (dest )) {
118- // Assume we're good.
119- return ;
120- }
121-
122- Files .createDirectories (dest .getParent ());
123- Files .copy (source , dest );
124- } catch (IOException e ) {
125- throw new UncheckedIOException (e );
126- }
127- }
128-
129- @ BeforeClass
130- public static void initializeServer () {
131- GlobalTestEnvironment .getOrCreate (InProcessTestEnvironment ::new );
132- }
133-
13487 public TestWatcher traceMethodName = new TestWatcher () {
13588 @ Override
13689 protected void starting (Description description ) {
@@ -144,7 +97,6 @@ protected void finished(Description description) {
14497 log .info ("<<< Finished " + description );
14598 }
14699 };
147-
148100 public ExternalResource initializeSelenium = new ExternalResource () {
149101 @ Override
150102 protected void before () {
@@ -165,39 +117,6 @@ protected void before() {
165117 INSTANCE = selenium ;
166118 }
167119 };
168-
169- private Capabilities createCapabilities () {
170- String property = System .getProperty ("selenium.browser" , "ff" );
171-
172- Browser browser = Browser .detect ();
173- switch (browser ) {
174- case CHROME :
175- return new ChromeOptions ();
176-
177- case EDGE :
178- return new EdgeOptions ();
179-
180- case IE :
181- return new InternetExplorerOptions ();
182-
183- case LEGACY_FIREFOX_XPI :
184- case FIREFOX :
185- return new FirefoxOptions ();
186-
187- case LEGACY_OPERA :
188- case OPERA :
189- return new OperaOptions ();
190-
191- case SAFARI :
192- return new SafariOptions ();
193-
194- default :
195- fail ("Attempt to use an unsupported browser: " + property );
196- // we never get here, but keep null checks happy anyway
197- return new DesiredCapabilities ();
198- }
199- }
200-
201120 public ExternalResource addNecessaryJavascriptCommands = new ExternalResource () {
202121 @ Override
203122 protected void before () {
@@ -220,7 +139,6 @@ protected void before() {
220139 }
221140 }
222141 };
223-
224142 public ExternalResource returnFocusToMainWindow = new ExternalResource () {
225143 @ Override
226144 protected void before () {
@@ -232,7 +150,6 @@ protected void before() {
232150 selenium .windowFocus ();
233151 }
234152 };
235-
236153 public TestWatcher filter = new TestWatcher () {
237154 @ Override
238155 public Statement apply (Statement base , Description description ) {
@@ -245,7 +162,6 @@ public Statement apply(Statement base, Description description) {
245162 return super .apply (base , description );
246163 }
247164 };
248-
249165 @ Rule
250166 public TestRule chain =
251167 RuleChain .outerRule (filter )
@@ -254,13 +170,50 @@ public Statement apply(Statement base, Description description) {
254170 .around (addNecessaryJavascriptCommands )
255171 .around (traceMethodName );
256172
257- @ After
258- public void checkVerifications () {
259- checkForVerificationErrors ();
173+ @ BeforeClass
174+ public static void buildJavascriptLibraries () throws IOException {
175+ if (!Files .exists (InProject .findProjectRoot ().resolve ("Rakefile" ))) {
176+ // we're not in dev mode
177+ return ;
178+ }
179+
180+ log .info ("In dev mode. Copying required files in case we're using a WebDriver-backed Selenium" );
181+
182+ BazelBuild bazel = new BazelBuild ();
183+
184+ Path dir =
185+ InProject .locate ("java/build/production/com/thoughtworks/selenium/webdriven" );
186+ Files .createDirectories (dir );
187+ for (String target : ATOM_TARGETS ) {
188+ bazel .build ("//javascript/selenium-atoms:" + target );
189+ copy ("javascript/selenium-atoms/" + target + ".js" ,
190+ "com/thoughtworks/selenium/webdriven/" + target + ".js" );
191+ }
192+ bazel .build ("//third_party/js/sizzle:sizzle" );
193+ copy ("third_party/js/sizzle/sizzle.js" ,
194+ "com/thoughtworks/selenium/webdriven/sizzle.js" );
260195 }
261196
262- private String whereIs (String location ) {
263- return GlobalTestEnvironment .get ().getAppServer ().whereIs (location );
197+ private static void copy (String copyFrom , String copyTo ) {
198+ try {
199+ Path source = InProject .locate ("bazel-bin" ).resolve (copyFrom );
200+ Path dest = InProject .locate ("java/build/test" ).resolve (copyTo );
201+
202+ if (Files .exists (dest )) {
203+ // Assume we're good.
204+ return ;
205+ }
206+
207+ Files .createDirectories (dest .getParent ());
208+ Files .copy (source , dest );
209+ } catch (IOException e ) {
210+ throw new UncheckedIOException (e );
211+ }
212+ }
213+
214+ @ BeforeClass
215+ public static void initializeServer () {
216+ GlobalTestEnvironment .getOrCreate (InProcessTestEnvironment ::new );
264217 }
265218
266219 @ AfterClass
@@ -275,4 +228,44 @@ public static void destroyDriver() {
275228 INSTANCE = null ;
276229 }
277230 }
231+
232+ private Capabilities createCapabilities () {
233+ String property = System .getProperty ("selenium.browser" , "ff" );
234+
235+ Browser browser = Browser .detect ();
236+ switch (browser ) {
237+ case CHROME :
238+ return new ChromeOptions ();
239+
240+ case EDGE :
241+ return new EdgeOptions ();
242+
243+ case IE :
244+ return new InternetExplorerOptions ();
245+
246+ case FIREFOX :
247+ return new FirefoxOptions ();
248+
249+ case LEGACY_OPERA :
250+ case OPERA :
251+ return new OperaOptions ();
252+
253+ case SAFARI :
254+ return new SafariOptions ();
255+
256+ default :
257+ fail ("Attempt to use an unsupported browser: " + property );
258+ // we never get here, but keep null checks happy anyway
259+ return new DesiredCapabilities ();
260+ }
261+ }
262+
263+ @ After
264+ public void checkVerifications () {
265+ checkForVerificationErrors ();
266+ }
267+
268+ private String whereIs (String location ) {
269+ return GlobalTestEnvironment .get ().getAppServer ().whereIs (location );
270+ }
278271}
0 commit comments