-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use Chrome for testing #369
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
acceptance-tests/src/main/java/hudson/plugin/gradle/ath/config/WebDriverProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package hudson.plugin.gradle.ath.config; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import com.google.inject.Inject; | ||
import com.google.inject.Provider; | ||
import org.jenkinsci.test.acceptance.FallbackConfig; | ||
import org.jenkinsci.test.acceptance.guice.TestCleaner; | ||
import org.jenkinsci.test.acceptance.guice.TestName; | ||
import org.jenkinsci.test.acceptance.selenium.Scroller; | ||
import org.jenkinsci.test.acceptance.utils.ElasticTime; | ||
import org.junit.runners.model.Statement; | ||
import org.openqa.selenium.Dimension; | ||
import org.openqa.selenium.UnsupportedCommandException; | ||
import org.openqa.selenium.WebDriver; | ||
import org.openqa.selenium.chrome.ChromeDriver; | ||
import org.openqa.selenium.chrome.ChromeOptions; | ||
import org.openqa.selenium.support.events.EventFiringWebDriver; | ||
|
||
import java.io.IOException; | ||
import java.time.Duration; | ||
import java.util.Locale; | ||
import java.util.logging.Logger; | ||
|
||
class WebDriverProvider implements Provider<WebDriver> { | ||
|
||
private static final Logger LOGGER = Logger.getLogger(FallbackConfig.class.getName()); | ||
private final TestCleaner testCleaner; | ||
private final FallbackConfig fallbackConfig; | ||
private final TestName testName; | ||
private final ElasticTime time; | ||
|
||
@Inject | ||
public WebDriverProvider( | ||
TestCleaner testCleaner, | ||
FallbackConfig fallbackConfig, | ||
TestName testName, | ||
ElasticTime time) { | ||
this.testCleaner = testCleaner; | ||
this.fallbackConfig = fallbackConfig; | ||
this.testName = testName; | ||
this.time = time; | ||
} | ||
|
||
private String getBrowser() { | ||
String browser = System.getenv("BROWSER"); | ||
if (browser == null) browser = "chrome-container"; | ||
browser = browser.toLowerCase(Locale.ENGLISH); | ||
return browser; | ||
} | ||
|
||
@Override | ||
public WebDriver get() { | ||
if ("chrome".equals(getBrowser())) { | ||
return createChromeWebDriver(); | ||
} | ||
try { | ||
return fallbackConfig.createWebDriver(testCleaner, testName, time); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
private WebDriver createChromeWebDriver() { | ||
ChromeOptions chromeOptions = new ChromeOptions(); | ||
chromeOptions.setBinary("/usr/bin/google-chrome-for-testing"); | ||
chromeOptions.addArguments("--window-position=0,0"); | ||
chromeOptions.addArguments("--window-size=1280,720"); | ||
chromeOptions.addArguments("--lang=en_US"); | ||
chromeOptions.setExperimentalOption("prefs", ImmutableMap.of("intl.accept_languages", "en_US")); | ||
ChromeDriver d = new ChromeDriver(chromeOptions); | ||
Dimension oldSize = d.manage().window().getSize(); | ||
if (oldSize.height < 1050 || oldSize.width < 1680) { | ||
d.manage().window().setSize(new Dimension(1680, 1050)); | ||
} | ||
final EventFiringWebDriver driver = new EventFiringWebDriver(d); | ||
driver.register(new Scroller()); | ||
try { | ||
driver.manage().timeouts().pageLoadTimeout(Duration.ofMillis(time.seconds(FallbackConfig.PAGE_LOAD_TIMEOUT))); | ||
driver.manage().timeouts().implicitlyWait(Duration.ofMillis(time.seconds(FallbackConfig.IMPLICIT_WAIT_TIMEOUT))); | ||
} catch (UnsupportedCommandException e) { | ||
// sauce labs RemoteWebDriver doesn't support this | ||
LOGGER.info(d + " doesn't support page load timeout"); | ||
} | ||
testCleaner.addTask(new Statement() { | ||
@Override | ||
public void evaluate() { | ||
driver.quit(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Close WebDriver after test"; | ||
} | ||
}); | ||
return driver; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
/usr/bin/google-chrome-for-testing
would point you to the latest version and as soon as we would update this would conflict with your chromedriver version.I would change this to:
/opt/google/119.0.6045.105/chrome-linux64/chrome
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So actually, after investigating, it turned out we can delegate all the driver plumbing to Selenium. It will try to find the specified Chrome version installed and if not found, download it. So my latest commit specifies the version to
stable
which should afaik try to find a stable Chrome installed, and if not present will download the latest stable.