You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hop.apache.org by ha...@apache.org on 2022/11/18 11:51:17 UTC
[hop] branch master updated: HOP-4550: change way tests are run
This is an automated email from the ASF dual-hosted git repository.
hansva pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hop.git
The following commit(s) were added to refs/heads/master by this push:
new 851dc1a33d HOP-4550: change way tests are run
new a3f9d52f3a Merge pull request #1807 from hansva/master
851dc1a33d is described below
commit 851dc1a33dfabd98519e509fa695f5f251409446
Author: Hans Van Akelyen <ha...@gmail.com>
AuthorDate: Fri Nov 18 12:50:24 2022 +0100
HOP-4550: change way tests are run
---
Jenkinsfile.hop-web-selenium | 5 +-
integration-tests/hopweb/Dockerfile | 40 +++++++---
integration-tests/hopweb/docker-compose.yml | 14 +---
integration-tests/hopweb/pom.xml | 6 ++
.../java/org/apache/hop/ui/hopgui/HopWebTest.java | 82 ++++++++++++---------
.../hopweb/src/test/resources/chromedriver-mac | Bin 0 -> 17211808 bytes
.../test/resources/hopwebtest-docker.properties | 1 -
.../src/test/resources/hopwebtest.properties | 3 +-
.../hopweb/src/test/resources/run-tests.sh | 4 +
9 files changed, 90 insertions(+), 65 deletions(-)
diff --git a/Jenkinsfile.hop-web-selenium b/Jenkinsfile.hop-web-selenium
index c089776da1..422ae50f6c 100644
--- a/Jenkinsfile.hop-web-selenium
+++ b/Jenkinsfile.hop-web-selenium
@@ -79,13 +79,10 @@ pipeline {
}
stage('Run Selenium tests'){
steps {
- sh "docker-compose -f integration-tests/hopweb/docker-compose.yml build"
- sh "docker-compose -f integration-tests/hopweb/docker-compose.yml up --abort-on-container-exit"
- sh "docker-compose -f integration-tests/hopweb/docker-compose.yml down --rmi all --remove-orphans"
+ sh "mvn -f integration-tests/hopweb/pom.xml clean test"
}
post {
always {
- sh "sleep 30"
archiveArtifacts(artifacts: 'integration-tests/hopweb/integration-tests/hopweb/target/surefire-reports/images/*.png', allowEmptyArchive: true)
junit(testResults: 'integration-tests/**/surefire-reports/*.xml', allowEmptyResults: true)
}
diff --git a/integration-tests/hopweb/Dockerfile b/integration-tests/hopweb/Dockerfile
index 7f1f337f9b..713a948f6d 100644
--- a/integration-tests/hopweb/Dockerfile
+++ b/integration-tests/hopweb/Dockerfile
@@ -17,25 +17,43 @@
FROM selenium/standalone-chrome
-RUN sudo useradd -s /bin/bash -m hop
-
COPY integration-tests/hopweb/src/ /home/hop/src/
COPY integration-tests/hopweb/pom.xml /home/hop/
-RUN sudo chown -R hop:hop /home/hop/
-RUN sudo mkdir /surefire-reports/ && sudo chown -R hop:hop /surefire-reports
+RUN sudo useradd -s /bin/bash -m hop \
+ && sudo chown -R hop:hop /home/hop/ \
+ && sudo mkdir /surefire-reports/ && sudo chown -R hop:hop /surefire-reports
+
+
+RUN sudo apt-get -qqy update \
+ && sudo apt-get -qqy remove docker docker.io containerd runc \
+ && sudo apt-get -qqy --no-install-recommends install \
+ ca-certificates \
+ curl \
+ gnupg \
+ lsb-release \
+ uidmap \
+ apt-utils \
+ && sudo mkdir -p /etc/apt/keyrings \
+ && curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg \
+ && echo \
+ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
+ $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null \
+ && sudo apt-get -qqy update \
+ && sudo apt-get -qqy install docker-ce docker-ce-cli containerd.io docker-compose-plugin \
+ && sudo rm -rf /var/lib/apt/lists/* /var/cache/apt/*
+
USER hop
-RUN wget https://dlcdn.apache.org/maven/maven-3/3.8.6/binaries/apache-maven-3.8.6-bin.tar.gz -P /tmp
-RUN cd /tmp/ && tar -xvzf apache-maven-3.8.6-bin.tar.gz
+RUN wget https://dlcdn.apache.org/maven/maven-3/3.8.6/binaries/apache-maven-3.8.6-bin.tar.gz -P /tmp \
+ && cd /tmp/ && tar -xvzf apache-maven-3.8.6-bin.tar.gz \
+ && cp /home/hop/src/test/resources/hopwebtest-docker.properties /home/hop/src/test/resources/hopwebtest.properties \
+ && cp /home/hop/src/test/resources/run-tests.sh /home/hop/ \
+ && chmod +x /home/hop/run-tests.sh
-ENV PATH=$PATH:/tmp/apache-maven-3.8.6/bin/
-RUN cp /home/hop/src/test/resources/hopwebtest-docker.properties /home/hop/src/test/resources/hopwebtest.properties
-RUN cp /home/hop/src/test/resources/run-tests.sh /home/hop/
-
-RUN chmod +x /home/hop/run-tests.sh
+ENV PATH=$PATH:/tmp/apache-maven-3.8.6/bin/
WORKDIR /home/hop
ENTRYPOINT ["/bin/bash", "/home/hop/run-tests.sh"]
diff --git a/integration-tests/hopweb/docker-compose.yml b/integration-tests/hopweb/docker-compose.yml
index b4e453561c..d9366df4ca 100644
--- a/integration-tests/hopweb/docker-compose.yml
+++ b/integration-tests/hopweb/docker-compose.yml
@@ -17,21 +17,9 @@
version: '2.4'
services:
- hopweb:
- image: apache/hop-web:Development
- container_name: hopweb
- ports:
- - "8080"
-
hop-web-test:
- depends_on:
- - hopweb
build:
context: ../../.
dockerfile: integration-tests/hopweb/Dockerfile
- ports:
- - "4444"
volumes:
- - ./integration-tests/hopweb/target/surefire-reports:/surefire-reports:rw
- links:
- - hopweb
+ - ../../integration-tests/hopweb/target/surefire-reports:/surefire-reports
diff --git a/integration-tests/hopweb/pom.xml b/integration-tests/hopweb/pom.xml
index 5aecf3f107..8f57ed5205 100644
--- a/integration-tests/hopweb/pom.xml
+++ b/integration-tests/hopweb/pom.xml
@@ -60,6 +60,12 @@
<version>2.11.0</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.testcontainers</groupId>
+ <artifactId>testcontainers</artifactId>
+ <version>1.17.6</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<reporting>
diff --git a/integration-tests/hopweb/src/test/java/org/apache/hop/ui/hopgui/HopWebTest.java b/integration-tests/hopweb/src/test/java/org/apache/hop/ui/hopgui/HopWebTest.java
index 3f7f528dbb..143c9a5ff5 100644
--- a/integration-tests/hopweb/src/test/java/org/apache/hop/ui/hopgui/HopWebTest.java
+++ b/integration-tests/hopweb/src/test/java/org/apache/hop/ui/hopgui/HopWebTest.java
@@ -36,6 +36,9 @@ import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.opentest4j.AssertionFailedError;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.wait.strategy.Wait;
+import org.testcontainers.utility.DockerImageName;
import java.io.File;
import java.io.FileInputStream;
@@ -59,7 +62,7 @@ public class HopWebTest {
private static int WAIT_SHORT = 500;
private static int WAIT_MEDIUM = 1000;
private static int WAIT_LONG = 2000;
- private static int WAIT_VERY_LONG = 5000;
+ private static int WAIT_VERY_LONG = 5000;
private static WebDriver driver;
private static Actions actions;
private static WebDriverWait wait;
@@ -70,19 +73,23 @@ public class HopWebTest {
private static String baseUrl, transformName;
private static String transformsFile;
private static ScreenshotUtil screenshotUtil;
-
+ private static GenericContainer<?> hopWebContainer;
@BeforeAll
public static void setUp() throws Exception {
+ //network = Network.builder().driver("bridge").build();
+ hopWebContainer = new GenericContainer<>(DockerImageName.parse("apache/hop-web:Development")).withExposedPorts(8080)
+ .waitingFor(Wait.forHttp("/ui"));
+ hopWebContainer.start();
screenshotUtil = new ScreenshotUtil();
InputStream input = new FileInputStream(HopWebTest.class.getClassLoader().getResource("hopwebtest.properties").getFile());
Properties properties = new Properties();
properties.load(input);
-
driverFile = new File(properties.getProperty("driverfile"));
- baseUrl = properties.getProperty("baseUrl");
+ baseUrl = "http://" + hopWebContainer.getHost() + ":" + hopWebContainer.getFirstMappedPort() + "/ui";
+ System.out.println("Connection URL used: " + baseUrl);
isHeadless = Boolean.valueOf(properties.getProperty("headless"));
transformsFile = properties.getProperty("transformsFile");
@@ -111,6 +118,11 @@ public class HopWebTest {
}
+ @AfterAll
+ public static void cleanUp() throws Exception {
+ hopWebContainer.stop();
+ }
+
@Test
@Order(1)
public void testNewPipeline() throws InterruptedException, IOException {
@@ -127,7 +139,7 @@ public class HopWebTest {
clickFirstCanvasElement(contextCanvas);
- WebDriverWait wait = new WebDriverWait(driver,Duration.ofSeconds(5));
+ WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(5));
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[text()='New pipeline']")));
assertEquals(1, driver.findElements(By.xpath("//div[text()='New pipeline']")).size());
Thread.sleep(WAIT_LONG);
@@ -141,7 +153,7 @@ public class HopWebTest {
* @throws InterruptedException
* @throws IOException
*/
- @ParameterizedTest(name = "{index} => transform=''{0}''" )
+ @ParameterizedTest(name = "{index} => transform=''{0}''")
@CsvFileSource(files = "src/test/resources/transforms.csv")
@Order(2)
public void testAddTransform(String transformName) throws InterruptedException, IOException {
@@ -156,13 +168,13 @@ public class HopWebTest {
*/
private static void checkWelcomeDialog() throws InterruptedException, IOException {
- try{
+ try {
WebElement welcomeCloseElement = driver.findElement(By.xpath("//div[text()='" + "Apache Hop" + "']/../div[5]"));
- if(welcomeCloseElement != null){
+ if (welcomeCloseElement != null) {
new Actions(driver).moveToElement(welcomeCloseElement).click().perform();
}
- }catch(NoSuchElementException e){
+ } catch (NoSuchElementException e) {
screenshotUtil.takeScreenshot(driver, "welcome-dialog-close-failed.png");
}
}
@@ -206,7 +218,7 @@ public class HopWebTest {
// can we pick up the transform's dialog?
try {
assertTrue(isElementPresent(transformName));
- }catch(AssertionFailedError e) {
+ } catch (AssertionFailedError e) {
restartOnFailure(e);
}
@@ -220,7 +232,7 @@ public class HopWebTest {
// for some transforms (e.g. Append Streams), the dialog is closed correctly, but the dialog element keeps floating around, causing this assertion to fail.
// check that we can't get the transform's dialog anymore
assertFalse(isElementPresent(transformName));
- }catch(AssertionFailedError e) {
+ } catch (AssertionFailedError e) {
screenshotUtil.takeScreenshot(driver, transformName + "-could-not-get-dialog.png");
restartOnFailure(e);
}
@@ -242,12 +254,12 @@ public class HopWebTest {
// the context dialog should have popped up, so we have 2 canvas elements available.
// int nbCanvasElements = driver.findElements(By.xpath("//canvas")).size();
// assertEquals(2, nbCanvasElements);
- }catch(AssertionFailedError e) {
+ } catch (AssertionFailedError e) {
screenshotUtil.takeScreenshot(driver, transformName + "-could-not-get-delete-dialog.png");
restartOnFailure(e);
}
- try{
+ try {
Thread.sleep(WAIT_SHORT);
contextCanvas = getLastCanvas();
@@ -261,14 +273,14 @@ public class HopWebTest {
// check if the context dialog was closed correctly.
// assertEquals(1, driver.findElements(By.xpath("//canvas")).size());
- }catch(AssertionFailedError e){
+ } catch (AssertionFailedError e) {
screenshotUtil.takeScreenshot(driver, transformName + "-delete-dialog-not-closed.png");
restartOnFailure(e);
}
}
- private String getElementHtml(String transformName){
- try{
+ private String getElementHtml(String transformName) {
+ try {
WebElement transformNameElement = driver.findElement(By.xpath("//div[text()='" + transformName + "']"));
WebElement transformElement = transformNameElement.findElement(By.xpath("./../.."));
@@ -276,24 +288,24 @@ public class HopWebTest {
return transformHtml;
- }catch(Exception e){
+ } catch (Exception e) {
e.printStackTrace();
screenshotUtil.takeScreenshot(driver, transformName + "-get-element-html.png");
}
return null;
}
- private boolean isElementPresent(String transformName){
- try{
+ private boolean isElementPresent(String transformName) {
+ try {
WebElement transformNameElement = driver.findElement(By.xpath("//div[text()='" + transformName + "']"));
String transformHtml = transformNameElement.getAttribute("innerHTML");
- if(transformNameElement != null){
+ if (transformNameElement != null) {
return true;
- }else{
+ } else {
return false;
}
- }catch(NoSuchElementException e){
+ } catch (NoSuchElementException e) {
return false;
}
}
@@ -303,7 +315,7 @@ public class HopWebTest {
new Actions(driver).moveToElement(element).click().perform();
}
- private void clickElementById(String id){
+ private void clickElementById(String id) {
WebElement element = driver.findElement(By.id(id));
new Actions(driver).moveToElement(element).click().perform();
}
@@ -312,26 +324,26 @@ public class HopWebTest {
canvasDimension = canvas.getSize();
- int posX = 0-(canvasDimension.getWidth()/2)+MARGIN_LEFT;
- int posY = 0-(canvasDimension.getHeight()/2)+MARGIN_TOP;
+ int posX = 0 - (canvasDimension.getWidth() / 2) + MARGIN_LEFT;
+ int posY = 0 - (canvasDimension.getHeight() / 2) + MARGIN_TOP;
clickCanvasAtPos(canvas, posX, posY);
}
private void clickCanvasAtPos(WebElement canvas, int posX, int posY) {
- try{
+ try {
new Actions(driver).moveToElement(canvas, posX, posY).click().pause(Duration.ofMillis(WAIT_SHORT)).perform();
- }catch(Exception e){
+ } catch (Exception e) {
screenshotUtil.takeScreenshot(driver, transformName + "-canvas-click" + posX + "-" + posY + ".png");
}
}
private WebElement getCanvas(int canvasNb) throws IOException, InterruptedException {
- try{
+ try {
WebElement canvas = driver.findElements(By.xpath("//canvas")).get(canvasNb);
assertNotNull(canvas);
return canvas;
- }catch(AssertionFailedError e){
+ } catch (AssertionFailedError e) {
screenshotUtil.takeScreenshot(driver, transformName + "-get-canvas.png");
restartOnFailure(e);
}
@@ -342,6 +354,7 @@ public class HopWebTest {
// pipeline and workflow canvas is the first one in the dom.
return getCanvas(0);
}
+
private WebElement getContextCanvas() throws InterruptedException, IOException {
// context canvas is the second one in the dom.
return getCanvas(1);
@@ -349,7 +362,7 @@ public class HopWebTest {
private WebElement getLastCanvas() throws InterruptedException, IOException {
List<WebElement> canvasList = driver.findElements(By.xpath("//canvas"));
- WebElement canvas = canvasList.get(canvasList.size()-1);
+ WebElement canvas = canvasList.get(canvasList.size() - 1);
assertNotNull(canvas);
return canvas;
}
@@ -361,22 +374,23 @@ public class HopWebTest {
public void sendInput(String inputString) throws InterruptedException, IOException {
// safe to assume the input we need is the last one added.
- try{
+ try {
List<WebElement> inputElements = driver.findElements(By.tagName("input"));
- WebElement inputElement = inputElements.get(inputElements.size()-1);
+ WebElement inputElement = inputElements.get(inputElements.size() - 1);
assertTrue(inputElement.isDisplayed());
Thread.sleep(WAIT_SHORT);
inputElement.sendKeys(inputString);
Thread.sleep(WAIT_SHORT);
- }catch(ElementNotInteractableException e){
+ } catch (ElementNotInteractableException e) {
e.printStackTrace();
closeAndcreateNewPipeline();
Thread.sleep(WAIT_LONG);
- }catch(AssertionFailedError e){
+ } catch (AssertionFailedError e) {
restartOnFailure(e);
Thread.sleep(WAIT_LONG);
}
}
+
private void restartOnFailure(AssertionFailedError e) throws InterruptedException, IOException {
e.printStackTrace();
closeAndcreateNewPipeline();
diff --git a/integration-tests/hopweb/src/test/resources/chromedriver-mac b/integration-tests/hopweb/src/test/resources/chromedriver-mac
new file mode 100755
index 0000000000..0b46cc423f
Binary files /dev/null and b/integration-tests/hopweb/src/test/resources/chromedriver-mac differ
diff --git a/integration-tests/hopweb/src/test/resources/hopwebtest-docker.properties b/integration-tests/hopweb/src/test/resources/hopwebtest-docker.properties
index 2195ea14b3..826cf4903d 100644
--- a/integration-tests/hopweb/src/test/resources/hopwebtest-docker.properties
+++ b/integration-tests/hopweb/src/test/resources/hopwebtest-docker.properties
@@ -16,7 +16,6 @@
# under the License.
driverfile=/home/hop/src/test/resources/chromedriver
-baseUrl=http://hopweb:8080/ui
headless=true
transformsFile=src/test/resources/transforms.csv
sleepStart=120000
\ No newline at end of file
diff --git a/integration-tests/hopweb/src/test/resources/hopwebtest.properties b/integration-tests/hopweb/src/test/resources/hopwebtest.properties
index d0c5416870..aa314a269d 100755
--- a/integration-tests/hopweb/src/test/resources/hopwebtest.properties
+++ b/integration-tests/hopweb/src/test/resources/hopwebtest.properties
@@ -16,7 +16,6 @@
# under the License.
driverfile=src/test/resources/chromedriver
-baseUrl=http://localhost:8080/ui
headless=true
transformsFile=src/test/resources/transforms.csv
-sleepStart=1000
\ No newline at end of file
+sleepStart=10000
\ No newline at end of file
diff --git a/integration-tests/hopweb/src/test/resources/run-tests.sh b/integration-tests/hopweb/src/test/resources/run-tests.sh
index 156ef198f5..cd9fd27994 100644
--- a/integration-tests/hopweb/src/test/resources/run-tests.sh
+++ b/integration-tests/hopweb/src/test/resources/run-tests.sh
@@ -17,6 +17,10 @@
# specific language governing permissions and limitations
# under the License.
+echo "Starting docker deamon"
+
+sudo systemctl start docker
+
echo "Starting Hop Web UI tests"
# make sure the chrome driver is executable.