merge with smatvienko-tb:UITests

This commit is contained in:
Serafym Tuhai 2022-12-08 22:36:27 +02:00
commit 3fdd0b644d
5 changed files with 122 additions and 8 deletions

View File

@ -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:

View File

@ -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\");"

View File

@ -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));
}
}

View File

@ -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();

View File

@ -54,7 +54,7 @@
<cassandra.version>4.15.0</cassandra.version>
<metrics.version>4.0.5</metrics.version>
<cassandra-all.version>3.11.14</cassandra-all.version>
<guava.version>30.0-jre</guava.version>
<guava.version>31.1-jre</guava.version>
<caffeine.version>2.6.1</caffeine.version>
<commons-lang3.version>3.4</commons-lang3.version>
<commons-codec.version>1.15</commons-codec.version>
@ -144,7 +144,7 @@
<jgit.version>6.1.0.202203080745-r</jgit.version>
<exp4j.version>0.4.8</exp4j.version>
<aerogear-otp.version>1.0.0</aerogear-otp.version>
<selenium.version>4.1.1</selenium.version>
<selenium.version>4.6.0</selenium.version>
<webdrivermanager.version>5.2.0</webdrivermanager.version>
<allure-testng.version>2.19.0</allure-testng.version>
<allure-maven.version>2.8</allure-maven.version>