Skip to content

Commit

Permalink
Use headless chrome instead of Firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
michalgh committed Feb 24, 2018
1 parent 5bc1c2d commit 833f3c6
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 12 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Expand Up @@ -105,6 +105,12 @@
<version>${jira.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.rauschig</groupId>
<artifactId>jarchivelib</artifactId>
<version>0.7.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
Expand Down
@@ -1,30 +1,24 @@
package it.com.sunrayapps.jira.plugin.ir;

import com.atlassian.jira.pageobjects.JiraTestedProduct;
import com.atlassian.pageobjects.DefaultProductInstance;
import com.atlassian.pageobjects.TestedProductFactory;
import it.com.sunrayapps.jira.plugin.ir.po.ExtendedCreateIssuePage;
import it.com.sunrayapps.jira.plugin.ir.po.TopMenuPage;
import it.com.sunrayapps.jira.plugin.ir.rule.JiraIntegrationTestRule;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;

public class CreateRecurringIssueTest {
private final JiraTestedProduct jira = TestedProductFactory
.create(
JiraTestedProduct.class,
new DefaultProductInstance("http://localhost:2990/jira",
"jira",
2990,
"/jira"
),
null
);
@Rule
public JiraIntegrationTestRule jiraIntegrationTestRule = new JiraIntegrationTestRule();
private final JiraTestedProduct jira = jiraIntegrationTestRule.getJira();

@Test
public void shouldInjectCheckbox() {
jira.quickLoginAsAdmin();
final TopMenuPage topMenuPage = jira.goTo(TopMenuPage.class);
final ExtendedCreateIssuePage createIssuePage = topMenuPage.createIssue();

Assert.assertTrue(createIssuePage.isCrateRecurringCheckboxVisible());
}
}
@@ -0,0 +1,66 @@
package it.com.sunrayapps.jira.plugin.ir.chrome;

import org.rauschig.jarchivelib.ArchiveFormat;
import org.rauschig.jarchivelib.ArchiverFactory;

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.nio.file.Path;
import java.nio.file.Paths;

import static org.apache.commons.io.FileUtils.copyURLToFile;

/**
* Downloads chrome driver and sets up Chrome driver.
* Currently, only 64 bit Linux is supported.
*/
public class ChromeDriverInstaller {
private final String chromeDriverZip = "chromedriver_linux64.zip";
private final URI uri = URI.create("https://chromedriver.storage.googleapis.com/2.35/" + chromeDriverZip);
private final Path installDirectory;

public ChromeDriverInstaller() {
this(Paths.get("target"));
}

public ChromeDriverInstaller(Path installDirectory) {
this.installDirectory = installDirectory;
}

public void setup() {
download();
unzip();
System.setProperty(
"webdriver.chrome.driver",
installDirectory.resolve("chromedriver").toString()
);
}

private void download() {
try {
copyURLToFile(
uri.toURL(),
getChromeDriverZip()
);
} catch (Exception e) {
throw new RuntimeException(e);
}
}

private File getChromeDriverZip() {
return new File(installDirectory
.resolve(chromeDriverZip)
.toUri());
}

private void unzip() {
try {
ArchiverFactory
.createArchiver(ArchiveFormat.ZIP)
.extract(getChromeDriverZip(), installDirectory.toFile());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
@@ -0,0 +1,37 @@
package it.com.sunrayapps.jira.plugin.ir.chrome;

import com.atlassian.pageobjects.TestedProductFactory;
import com.atlassian.pageobjects.browser.Browser;
import com.atlassian.webdriver.DefaultAtlassianWebDriver;
import com.atlassian.webdriver.pageobjects.DefaultWebDriverTester;
import com.atlassian.webdriver.pageobjects.WebDriverTester;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class ChromeTestedFactory implements TestedProductFactory.TesterFactory<WebDriverTester> {
private final boolean headless;

public ChromeTestedFactory() {
this(true);
}

public ChromeTestedFactory(boolean headless) {
this.headless = headless;
}

@Override
public WebDriverTester create() {
new ChromeDriverInstaller().setup();
final ChromeOptions options = new ChromeOptions();
options.addArguments(
"--no-sandbox",
"--disable-infobars"
);
if (headless) {
options.addArguments("--headless");
}
final ChromeDriver driver = new ChromeDriver(options);
final DefaultAtlassianWebDriver atlassianWebDriver = new DefaultAtlassianWebDriver(driver, Browser.CHROME);
return new DefaultWebDriverTester(atlassianWebDriver);
}
}
@@ -0,0 +1,40 @@
package it.com.sunrayapps.jira.plugin.ir.rule;

import com.atlassian.jira.pageobjects.JiraTestedProduct;
import com.atlassian.pageobjects.DefaultProductInstance;
import com.atlassian.pageobjects.TestedProductFactory;
import it.com.sunrayapps.jira.plugin.ir.chrome.ChromeTestedFactory;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

public class JiraIntegrationTestRule implements TestRule {
private final JiraTestedProduct jira = TestedProductFactory
.create(
JiraTestedProduct.class,
new DefaultProductInstance("http://localhost:2990/jira",
"jira",
2990,
"/jira"
),
new ChromeTestedFactory()
);

@Override
public Statement apply(Statement statement, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
try {
statement.evaluate();
} finally {
jira.getTester().getDriver().quit();
}
}
};
}

public JiraTestedProduct getJira() {
return jira;
}
}

0 comments on commit 833f3c6

Please sign in to comment.