diff --git a/msa/black-box-tests/README.md b/msa/black-box-tests/README.md index a4bbe48961..ae0e8b79a0 100644 --- a/msa/black-box-tests/README.md +++ b/msa/black-box-tests/README.md @@ -36,7 +36,7 @@ As result, in REPOSITORY column, next images should be present: - To run ui smoke tests in the [msa/black-box-tests](../black-box-tests) directory specifying suite name: - mvn clean install -DblackBoxTests.skip=false -Dsuite=uiTests + mvn clean install -DblackBoxTests.skip=false -Dsuite=uiTests - To run all tests in the [msa/black-box-tests](../black-box-tests) directory specifying suite name: diff --git a/msa/black-box-tests/chrome_install.sh b/msa/black-box-tests/chrome_install.sh new file mode 100755 index 0000000000..9d4588dcb4 --- /dev/null +++ b/msa/black-box-tests/chrome_install.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# +# Copyright © 2016-2022 The Thingsboard Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +set -e # Any subsequent commands which fail will cause the shell script to exit immediately +CHROME_PATH=/tmp/google-chrome + +echo "Installing google-chrome to the $CHROME_PATH" + +rm -rf $CHROME_PATH +mkdir -p $CHROME_PATH +wget --no-verbose -P $CHROME_PATH https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb +dpkg-deb -xv $CHROME_PATH/google-chrome-stable_current_amd64.deb /tmp/google-chrome/ +rm $CHROME_PATH/google-chrome-stable_current_amd64.deb + +echo "Use google-binary as ChromeOptions options = new ChromeOptions(); options.setBinary(\"${CHROME_PATH}/opt/google/chrome/chrome\");" diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/SeleniumRemoteWebDriverTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/SeleniumRemoteWebDriverTest.java new file mode 100644 index 0000000000..8c6f044f71 --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/SeleniumRemoteWebDriverTest.java @@ -0,0 +1,85 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.thingsboard.server.msa; + +import com.google.common.io.Files; +import io.qameta.allure.Attachment; +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.io.FileUtils; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.openqa.selenium.Dimension; +import org.openqa.selenium.OutputType; +import org.openqa.selenium.TakesScreenshot; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.chrome.ChromeOptions; +import org.openqa.selenium.remote.LocalFileDetector; +import org.openqa.selenium.remote.RemoteWebDriver; + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; + +@Slf4j +public class SeleniumRemoteWebDriverTest { + + static final int WIDTH = 1680; + static final int HEIGHT = 1050; + final Dimension dimension = new Dimension(WIDTH, HEIGHT); + WebDriver driver; + + @SneakyThrows + @Attachment(value = "Page screenshot", type = "image/png") + public static byte[] captureScreen(WebDriver driver, String dirPath) { + File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); + FileUtils.copyFile(screenshot, new File("./target/allure-results/screenshots/" + dirPath + "//" + screenshot.getName())); + return Files.toByteArray(screenshot); + } + + + /** + * Requirement: + * docker run --name=chrome --rm --network=host -p 4444:4444 -p 7900:7900 --shm-size="2g" -e SE_NODE_MAX_SESSIONS=8 -e SE_NODE_OVERRIDE_MAX_SESSIONS=true -e SE_NODE_SESSION_TIMEOUT=90 -e SE_SCREEN_WIDTH=1920 -e SE_SCREEN_HEIGHT=1080 -e SE_SCREEN_DEPTH=24 -e SE_SCREEN_DPI=74 selenium/standalone-chrome + * */ + @BeforeEach + void setUp() throws MalformedURLException { + log.info("Requirement:"); + log.info("docker run --name=chrome --rm --network=host -p 4444:4444 -p 7900:7900 --shm-size=\"2g\" -e SE_NODE_MAX_SESSIONS=8 -e SE_NODE_OVERRIDE_MAX_SESSIONS=true -e SE_NODE_SESSION_TIMEOUT=90 -e SE_SCREEN_WIDTH=1920 -e SE_SCREEN_HEIGHT=1080 -e SE_SCREEN_DEPTH=24 -e SE_SCREEN_DPI=74 selenium/standalone-chrome"); + log.info("*----------------------* Setup driver *----------------------*"); + ChromeOptions options = new ChromeOptions(); + RemoteWebDriver remoteWebDriver = new RemoteWebDriver(new URL("http://127.0.0.1:4444"), options); + remoteWebDriver.setFileDetector(new LocalFileDetector()); + driver = remoteWebDriver; + driver.manage().window().setSize(dimension); + } + + @AfterEach + void tearDown() { + log.info("*----------------------* Teardown *----------------------*"); + driver.quit(); + } + + @Test + void testSeleniumConnection() { + driver.get("https://thingsboard.io/"); + captureScreen(driver, "success"); + log.info("Check the screenshot on target/allure-results/screenshots/success/screenshot???????????????.png"); + //Thread.sleep(TimeUnit.SECONDS.toMillis(30)); + } + +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/base/AbstractDriverBaseTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/base/AbstractDriverBaseTest.java index d5c0d1625e..4fa500625e 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/base/AbstractDriverBaseTest.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/base/AbstractDriverBaseTest.java @@ -34,6 +34,7 @@ import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; +import org.testng.annotations.BeforeSuite; import org.testng.annotations.Listeners; import org.thingsboard.server.common.data.Customer; import org.thingsboard.server.common.data.page.PageLink; @@ -66,21 +67,19 @@ abstract public class AbstractDriverBaseTest extends AbstractContainerTest { public void openBrowser() { log.info("*----------------------* Setup driver *----------------------*"); ChromeOptions options = new ChromeOptions(); - options.addArguments("--ignore-certificate-errors"); - options.addArguments("--no-sandbox"); - options.addArguments("--disable-dev-shm-usage"); + options.setAcceptInsecureCerts(true); if (instance.isActive()) { RemoteWebDriver remoteWebDriver = new RemoteWebDriver(new URL(REMOTE_WEBDRIVER_HOST), options); remoteWebDriver.setFileDetector(new LocalFileDetector()); driver = remoteWebDriver; } else { WebDriverManager.chromedriver().setup(); - driver = new ChromeDriver(); + driver = new ChromeDriver(options); } driver.manage().window().setSize(dimension); } - @AfterMethod() + @AfterMethod public void closeBrowser() { log.info("*----------------------* Teardown *----------------------*"); driver.quit(); diff --git a/pom.xml b/pom.xml index 139bf53d90..756ebf4ed0 100755 --- a/pom.xml +++ b/pom.xml @@ -54,7 +54,7 @@ 4.15.0 4.0.5 3.11.14 - 30.0-jre + 31.1-jre 2.6.1 3.4 1.15 @@ -144,7 +144,7 @@ 6.1.0.202203080745-r 0.4.8 1.0.0 - 4.1.1 + 4.6.0 5.2.0 2.19.0 2.8