Skip to content
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

Add UI Acceptance test #97

Merged
merged 2 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,18 @@
<artifactId>matrix-project</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.10.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.3.3</version>
<scope>test</scope>
</dependency>
</dependencies>

<scm>
Expand All @@ -131,4 +143,30 @@
<tag>${scmTag}</tag>
</scm>

<profiles>
<profile>
<id>windows-ci</id>
<activation>
<os>
<family>Windows</family>
</os>
<property>
<name>env.CI</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- TODO fails on CI on Windows for inscrutable reasons -->
<excludes>
<exclude>net.uaznia.lukanus.hudson.plugins.gitparameter.UiAcceptanceTest</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package net.uaznia.lukanus.hudson.plugins.gitparameter;

import io.github.bonigarcia.wdm.WebDriverManager;
import org.apache.commons.lang.StringUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.recipes.LocalData;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.time.Duration;

import static org.junit.Assert.assertTrue;

public class UiAcceptanceTest {
@Rule
public JenkinsRule j = new JenkinsRule();

private WebDriver driver;

@BeforeClass
public static void setUpClass() {
if (isCi()) {
// The browserVersion needs to match what is provided by the Jenkins Infrastructure
// If you see an exception like this:
//
// org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: session not created: This version of ChromeDriver only supports Chrome version 114
// Current browser version is 112.0.5615.49 with binary path /usr/bin/chromium-browser
//
// Then that means you need to update the version here to match the current browser version.
WebDriverManager.chromedriver().browserVersion("112").setup();
} else {
WebDriverManager.chromedriver().setup();
}
}

private static boolean isCi() {
return StringUtils.isNotBlank(System.getenv("CI"));
}

@Before
public void setUp() throws Exception {
if (isCi()) {
driver = new ChromeDriver(new ChromeOptions().addArguments("--headless", "--disable-dev-shm-usage", "--no-sandbox"));
} else {
driver = new ChromeDriver(new ChromeOptions());
}
}

@After
public void tearDown() {
driver.quit();
}

@LocalData
@Test
public void test() throws Exception {
driver.get(j.getURL().toString() + "job/test/build");

WebElement branchParam = driver.findElement(byParamName("Branch"));
WebElement tagParam = driver.findElement(byParamName("Tag"));
WebElement revisionParam = driver.findElement(byParamName("Revision"));

new WebDriverWait(driver, Duration.ofSeconds(60))
.until(driver1 -> new Select(driver1.findElement(byParamName("Revision"))).getOptions().size() > 1);

assertTrue(new Select(branchParam).getOptions().stream().anyMatch(option -> option.getAttribute("value").equals("origin/master")));
assertTrue(new Select(tagParam).getOptions().stream().anyMatch(option -> option.getAttribute("value").equals("git-parameter-0.9.7")));
assertTrue(new Select(revisionParam).getOptions().stream().anyMatch(option -> option.getAttribute("value").equals("00a8385cba1e4e32cf823775e2b3dbe5eb27931d")));

}

private static By byParamName(String paramName) {
return By.cssSelector("div[name='parameter']:has([name='name'][value='" + paramName + "']) > select");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?xml version='1.1' encoding='UTF-8'?>
<project>
<actions/>
<description></description>
<keepDependencies>false</keepDependencies>
<properties>
<com.sonyericsson.rebuild.RebuildSettings plugin="[email protected]">
<autoRebuild>false</autoRebuild>
<rebuildDisabled>false</rebuildDisabled>
</com.sonyericsson.rebuild.RebuildSettings>
<hudson.model.ParametersDefinitionProperty>
<parameterDefinitions>
<net.uaznia.lukanus.hudson.plugins.gitparameter.GitParameterDefinition plugin="[email protected]">
<name>Branch</name>
<uuid>47b5ed4f-09f1-4825-afe1-f32fcc4925d3</uuid>
<type>PT_BRANCH</type>
<branch></branch>
<tagFilter>*</tagFilter>
<branchFilter>.*</branchFilter>
<sortMode>NONE</sortMode>
<defaultValue>main</defaultValue>
<selectedValue>NONE</selectedValue>
<quickFilterEnabled>false</quickFilterEnabled>
<listSize>5</listSize>
<requiredParameter>false</requiredParameter>
</net.uaznia.lukanus.hudson.plugins.gitparameter.GitParameterDefinition>
<net.uaznia.lukanus.hudson.plugins.gitparameter.GitParameterDefinition plugin="[email protected]">
<name>Tag</name>
<uuid>a7d476bb-5cfe-47db-b9e8-a3e8737f37d9</uuid>
<type>PT_TAG</type>
<branch></branch>
<tagFilter>*</tagFilter>
<branchFilter>.*</branchFilter>
<sortMode>NONE</sortMode>
<defaultValue>0.1</defaultValue>
<selectedValue>NONE</selectedValue>
<quickFilterEnabled>false</quickFilterEnabled>
<listSize>5</listSize>
<requiredParameter>false</requiredParameter>
</net.uaznia.lukanus.hudson.plugins.gitparameter.GitParameterDefinition>
<net.uaznia.lukanus.hudson.plugins.gitparameter.GitParameterDefinition plugin="[email protected]">
<name>Revision</name>
<uuid>81de79f5-21ee-4e09-b9a4-b11460de0a04</uuid>
<type>PT_REVISION</type>
<branch>origin/master</branch>
<tagFilter>*</tagFilter>
<branchFilter>.*</branchFilter>
<sortMode>NONE</sortMode>
<defaultValue></defaultValue>
<selectedValue>NONE</selectedValue>
<quickFilterEnabled>false</quickFilterEnabled>
<listSize>5</listSize>
<requiredParameter>false</requiredParameter>
</net.uaznia.lukanus.hudson.plugins.gitparameter.GitParameterDefinition>
</parameterDefinitions>
</hudson.model.ParametersDefinitionProperty>
</properties>
<scm class="hudson.plugins.git.GitSCM" plugin="[email protected]">
<configVersion>2</configVersion>
<userRemoteConfigs>
<hudson.plugins.git.UserRemoteConfig>
<url>https://github.com/jenkinsci/git-parameter-plugin.git</url>
</hudson.plugins.git.UserRemoteConfig>
</userRemoteConfigs>
<branches>
<hudson.plugins.git.BranchSpec>
<name>*/master</name>
</hudson.plugins.git.BranchSpec>
</branches>
<doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
<submoduleCfg class="empty-list"/>
<extensions/>
</scm>
<canRoam>true</canRoam>
<disabled>false</disabled>
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<triggers/>
<concurrentBuild>false</concurrentBuild>
<builders/>
<publishers/>
<buildWrappers/>
</project>