|
|
|
@ -15,12 +15,10 @@ |
|
|
|
*/ |
|
|
|
package org.thingsboard.server.msa.ui.base; |
|
|
|
|
|
|
|
import com.google.common.io.Files; |
|
|
|
import io.github.bonigarcia.wdm.WebDriverManager; |
|
|
|
import io.qameta.allure.Attachment; |
|
|
|
import lombok.SneakyThrows; |
|
|
|
import io.qameta.allure.Allure; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.io.FileUtils; |
|
|
|
import org.openqa.selenium.By; |
|
|
|
import org.openqa.selenium.Dimension; |
|
|
|
import org.openqa.selenium.JavascriptExecutor; |
|
|
|
import org.openqa.selenium.OutputType; |
|
|
|
@ -34,7 +32,9 @@ import org.openqa.selenium.remote.LocalFileDetector; |
|
|
|
import org.openqa.selenium.remote.RemoteWebDriver; |
|
|
|
import org.openqa.selenium.support.ui.ExpectedConditions; |
|
|
|
import org.openqa.selenium.support.ui.WebDriverWait; |
|
|
|
import org.testng.annotations.AfterClass; |
|
|
|
import org.testng.annotations.AfterMethod; |
|
|
|
import org.testng.annotations.BeforeClass; |
|
|
|
import org.testng.annotations.BeforeMethod; |
|
|
|
import org.thingsboard.server.common.data.Customer; |
|
|
|
import org.thingsboard.server.common.data.DeviceProfile; |
|
|
|
@ -44,9 +44,11 @@ import org.thingsboard.server.common.data.rule.RuleChain; |
|
|
|
import org.thingsboard.server.msa.AbstractContainerTest; |
|
|
|
import org.thingsboard.server.msa.ContainerTestSuite; |
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.io.ByteArrayInputStream; |
|
|
|
import java.net.MalformedURLException; |
|
|
|
import java.net.URL; |
|
|
|
import java.time.Duration; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
import static org.thingsboard.server.msa.TestProperties.getBaseUiUrl; |
|
|
|
@ -65,9 +67,8 @@ abstract public class AbstractDriverBaseTest extends AbstractContainerTest { |
|
|
|
private static final ContainerTestSuite instance = ContainerTestSuite.getInstance(); |
|
|
|
private JavascriptExecutor js; |
|
|
|
|
|
|
|
@SneakyThrows |
|
|
|
@BeforeMethod |
|
|
|
public void openBrowser() { |
|
|
|
@BeforeClass |
|
|
|
public void startUp() throws MalformedURLException { |
|
|
|
log.info("===>>> Setup driver"); |
|
|
|
testRestClient.login(TENANT_EMAIL, TENANT_PASSWORD); |
|
|
|
ChromeOptions options = new ChromeOptions(); |
|
|
|
@ -84,8 +85,18 @@ abstract public class AbstractDriverBaseTest extends AbstractContainerTest { |
|
|
|
openLocalhost(); |
|
|
|
} |
|
|
|
|
|
|
|
@BeforeMethod |
|
|
|
public void open() { |
|
|
|
openHomePage(); |
|
|
|
} |
|
|
|
|
|
|
|
@AfterMethod |
|
|
|
public void closeBrowser() { |
|
|
|
public void addScreenshotToReport() { |
|
|
|
captureScreen(driver, "After test page screenshot"); |
|
|
|
} |
|
|
|
|
|
|
|
@AfterClass |
|
|
|
public void teardown() { |
|
|
|
log.info("<<<=== Teardown"); |
|
|
|
driver.quit(); |
|
|
|
} |
|
|
|
@ -94,6 +105,10 @@ abstract public class AbstractDriverBaseTest extends AbstractContainerTest { |
|
|
|
driver.get(getBaseUiUrl()); |
|
|
|
} |
|
|
|
|
|
|
|
public void openHomePage() { |
|
|
|
driver.get(getBaseUiUrl() + "/home"); |
|
|
|
} |
|
|
|
|
|
|
|
public String getUrl() { |
|
|
|
return driver.getCurrentUrl(); |
|
|
|
} |
|
|
|
@ -157,11 +172,10 @@ abstract public class AbstractDriverBaseTest extends AbstractContainerTest { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@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); |
|
|
|
public void captureScreen(WebDriver driver, String screenshotName) { |
|
|
|
if (driver instanceof TakesScreenshot) { |
|
|
|
Allure.addAttachment(screenshotName, |
|
|
|
new ByteArrayInputStream(((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES))); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|