Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use headless chrome instead of Firefox
- Loading branch information
Showing
5 changed files
with
155 additions
and
12 deletions.
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
18 changes: 6 additions & 12 deletions
18
src/test/java/it/com/sunrayapps/jira/plugin/ir/CreateRecurringIssueTest.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 |
---|---|---|
@@ -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()); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
src/test/java/it/com/sunrayapps/jira/plugin/ir/chrome/ChromeDriverInstaller.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,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); | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/test/java/it/com/sunrayapps/jira/plugin/ir/chrome/ChromeTestedFactory.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,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); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/test/java/it/com/sunrayapps/jira/plugin/ir/rule/JiraIntegrationTestRule.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,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; | ||
} | ||
} |