Skip to content

Commit

Permalink
Copy static resources required by java tests into place
Browse files Browse the repository at this point in the history
  • Loading branch information
shs96c committed Nov 6, 2018
1 parent ed3aa1e commit c9b57f0
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 4 deletions.
3 changes: 0 additions & 3 deletions java/client/client.iml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
<output url="file://$MODULE_DIR$/build/production" />
<output-test url="file://$MODULE_DIR$/build/test" />
<exclude-output />
<content url="file://$MODULE_DIR$/../../buck-out/gen">
<sourceFolder url="file://$MODULE_DIR$/../../buck-out/gen/java/client/src" type="java-test-resource" />
</content>
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
Expand Down
2 changes: 1 addition & 1 deletion java/client/test/org/openqa/selenium/BuckBuild.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public Path go() throws IOException {
commandLine.execute();

if (!commandLine.isSuccessful()) {
throw new WebDriverException("Build failed! " + target);
throw new WebDriverException("Build failed! " + target + "\n" + commandLine.getStdOut());
}

return findOutput(projectRoot);
Expand Down
1 change: 1 addition & 0 deletions java/client/test/org/openqa/selenium/testing/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ java_library(name = 'test-base',
srcs = [
'JUnit4TestBase.java',
'SeleniumTestRunner.java',
'StaticResources.java',
'TestUtilities.java',
],
exported_deps = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ private static WebDriver actuallyCreateDriver() {

if (driver == null ||
(driver instanceof RemoteWebDriver && ((RemoteWebDriver)driver).getSessionId() == null)) {
StaticResources.ensureAvailable();
driver = new WebDriverBuilder().get();
storedDriver.set(driver);
}
Expand All @@ -221,6 +222,7 @@ private static WebDriver actuallyCreateDriver(Capabilities capabilities) {

if (driver == null ||
(driver instanceof RemoteWebDriver && ((RemoteWebDriver)driver).getSessionId() == null)) {
StaticResources.ensureAvailable();
driver = new WebDriverBuilder().get(capabilities);
storedDriver.set(driver);
}
Expand Down
70 changes: 70 additions & 0 deletions java/client/test/org/openqa/selenium/testing/StaticResources.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.testing;

import org.openqa.selenium.BuckBuild;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;

class StaticResources {

static void ensureAvailable() {
if (!DevMode.isInDevMode()) {
return;
}

System.out.println("Copying resources");

// W3C emulation
copy(
"//javascript/atoms/fragments:is-displayed",
"org/openqa/selenium/remote/isDisplayed.js");
copy(
"//javascript/webdriver/atoms:get-attribute",
"org/openqa/selenium/remote/getAttribute.js");

// Firefox XPI
copy(
"//javascript/firefox-driver:webdriver_prefs",
"org/openqa/selenium/firefox/webdriver_prefs.json");
copy(
"//java/client/src/org/openqa/selenium/firefox:webdriver.xpi",
"org/openqa/selenium/firefox/webdriver.xpi");
}

private static void copy(String buildTarget, String copyTo) {
try {
Path dest = InProject.locate("java/client/build/test").resolve(copyTo);

if (Files.exists(dest)) {
// Assume we're good.
return;
}

Path source = new BuckBuild().of(buildTarget).go();

Files.copy(source, dest);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

}

0 comments on commit c9b57f0

Please sign in to comment.