Skip to content

Commit

Permalink
Playwright web ui tests
Browse files Browse the repository at this point in the history
  • Loading branch information
michalxo committed Dec 5, 2024
1 parent 4fdc558 commit 1cbf750
Show file tree
Hide file tree
Showing 13 changed files with 665 additions and 36 deletions.
5 changes: 5 additions & 0 deletions common/src/main/java/io/brokerqe/claire/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public interface Constants {

// Environment Variables
String EV_KUBE_CONTEXT = "KUBE_CONTEXT";
String EV_KUBE_CREDENTIALS = "KUBE_CREDENTIALS";
String EV_ARTEMIS_VERSION = "ARTEMIS_VERSION";
String EV_ARTEMIS_TEST_VERSION = "ARTEMIS_TEST_VERSION";
String EV_DISABLE_RANDOM_NAMESPACES = "DISABLE_RANDOM_NAMESPACES";
Expand All @@ -47,6 +48,7 @@ public interface Constants {
String EV_DUMP_LOCATION = "DUMP_LOCATION";
String EV_DUMP_FORMAT = "DUMP_FORMAT";
String EV_TEARDOWN = "TEARDOWN_ENV";
String EV_PLAYWRIGHT_DEBUG = "PLAYWRIGHT_DEBUG";
String EV_CLUSTER_OPERATOR_MANAGED = "CLUSTER_OPERATOR_MANAGED";
String EV_COLLECT_TEST_DATA = "COLLECT_TEST_DATA";
String EV_JDBC_DATA = "JDBC_DATA";
Expand Down Expand Up @@ -99,6 +101,9 @@ public interface Constants {

// Files
String PROJECT_USER_DIR = System.getProperty("user.dir");
String PROJECT_DIR = PROJECT_USER_DIR + "/..";
String STANDALONE_MODULE = PROJECT_DIR + "/standalone-suite";
String OPERATOR_MODULE = PROJECT_DIR + "/operator-suite";
String PROJECT_TEST_DIR = PROJECT_USER_DIR + "/src/test";
String LOGS_DEFAULT_DIR = PROJECT_USER_DIR + "/test-logs";
String TMP_DEFAULT_DIR = PROJECT_USER_DIR + "/test-tmp";
Expand Down
1 change: 1 addition & 0 deletions common/src/main/java/io/brokerqe/claire/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public String getCertificatesLocation() {
public abstract String getKeycloakVersion();
public abstract boolean isCollectTestData();
public abstract boolean isTeardownEnv();
public abstract boolean isPlaywrightDebug();
public abstract int getCustomExtraDelay();
public abstract void setupDatabase();

Expand Down
10 changes: 9 additions & 1 deletion common/src/main/java/io/brokerqe/claire/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,25 @@ public static Path getProjectRelativeFilePath(String projectRelativeFile) {
return Paths.get(Constants.PROJECT_USER_DIR, projectRelativeFile).toAbsolutePath();
}

public static Path getStandaloneArtemisDefaultDir() {
return Paths.get(Constants.STANDALONE_MODULE, ArtemisConstants.INSTALL_DIR, ArtemisConstants.BIN_DIR);
}

// ========== Execute command Operations ==========

public static String executeLocalCommand(String cmd) {
return executeLocalCommand(cmd.split(" "));
}

public static String executeLocalCommand(String... cmd) {
return executeLocalCommand(10, cmd);
}

public static String executeLocalCommand(long timeoutSecs, String... cmd) {
LocalExecutor executor = new LocalExecutor();
LOGGER.debug("[CMD][local] {}", String.join(" ", cmd));
executor.executeCommand(cmd);
return executor.getCommandData(Duration.ofSeconds(10).toSeconds());
return executor.getCommandData(Duration.ofSeconds(timeoutSecs).toSeconds());
}

// ========== Junit Test Operations ==========
Expand Down
52 changes: 27 additions & 25 deletions operator-suite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,33 @@ If you would want to try your own OLM operator, you would need to specify only f

## List of available Environment Variables

| Name | Description | Default | Possible values |
|---------------------------|---------------------------------------------------------------------|-----------------------------|--------------------------------------------|
| ARTEMIS_VERSION | ArtemisCloud Version to be used (Makefile) | 7.10.2 | \<major\>.\<minor\>.\<micro\> |
| ARTEMIS_TEST_VERSION | ArtemisCloud Version to be used by tests | not set | \<major\>.\<minor\> |
| OPERATOR_IMAGE | ArtemisCloud Operator image url | not set | \<image registry url\> |
| BROKER_IMAGE | Broker image url | not set | \<image registry url\> |
| BROKER_INIT_IMAGE | Broker init image url | not set | \<image registry url\> |
| BUNDLE_IMAGE | Bundle image url | not set | \<image registry url\> |
| OLM | Whether to install latest available Operator | false | `true`, `false` |
| OLM_LTS | Whether to install lts or latest available operator (tied to `OLM`) | false | `true`, `false` |
| OLM_IIB | OLM Index Image Bundle to use | not set | \<iib image registry url\> |
| OLM_CHANNEL | OLM channel to use with Subscription | not set | \<channel\> |
| DISABLE_RANDOM_NAMESPACES | Whether to use random string suffices | not set (`false`) | `true`, `false` |
| LOGS_LOCATION | Location where to generate collected logs | `test-logs` | \<directory\> |
| TEST_LOG_LEVEL | Set logging level of test suite | `INFO` set in `logback.xml` | `TRACE`, `DEBUG`, `INFO`, `WARN`, `ERROR`, `OFF` |
| CLUSTER_OPERATOR_MANAGED | Whether test suite manages CO or not (Makefile) | `true` | `false` |
| COLLECT_TEST_DATA | Whether to gather test data on error or not | `true` | `true`, `false` |
| CUSTOM_EXTRA_DELAY | Prolonged all internal waitFor calls (seconds) | `0` | \<number of seconds\> |
| OPERATOR_INSTALL_ZIP | Url to zip file with install/examples (Makefile) | 7.10.2 url | \<url\> |
| OPERATOR_VERSION_UPSTREAM | Version/branch of repository (Makefile) | main | \<branch\> |
| DUMP_ENABLED | Enabled serialization of deployed resources | `false` | `true`, `false` |
| DUMP_FORMAT | Format of serialized deployed resources | `yaml` | `yaml`, `json` |
| DUMP_LOCATION | Location to dump serialized deployed resources | `serialization-dump` | \<directory\> |
| KUBE_CONTEXT | Provide comma separated context(s) for kubernetes client | `default/null` | null, \<contextA,contextB,contextC,...\> |
| TEARDOWN_ENV | Teardown down deployment or leave it as is | `true` | `true`, `false` |
| Name | Description | Default | Possible values |
|--------------------------------------------------------|---------------------------------------------------------------------|-----------------------------|--------------------------------------------------|
| ARTEMIS_VERSION | ArtemisCloud Version to be used (Makefile) | 7.10.2 | \<major\>.\<minor\>.\<micro\> |
| ARTEMIS_TEST_VERSION | ArtemisCloud Version to be used by tests | not set | \<major\>.\<minor\> |
| OPERATOR_IMAGE | ArtemisCloud Operator image url | not set | \<image registry url\> |
| BROKER_IMAGE | Broker image url | not set | \<image registry url\> |
| BROKER_INIT_IMAGE | Broker init image url | not set | \<image registry url\> |
| BUNDLE_IMAGE | Bundle image url | not set | \<image registry url\> |
| OLM | Whether to install latest available Operator | false | `true`, `false` |
| OLM_LTS | Whether to install lts or latest available operator (tied to `OLM`) | false | `true`, `false` |
| OLM_IIB | OLM Index Image Bundle to use | not set | \<iib image registry url\> |
| OLM_CHANNEL | OLM channel to use with Subscription | not set | \<channel\> |
| DISABLE_RANDOM_NAMESPACES | Whether to use random string suffices | not set (`false`) | `true`, `false` |
| LOGS_LOCATION | Location where to generate collected logs | `test-logs` | \<directory\> |
| TEST_LOG_LEVEL | Set logging level of test suite | `INFO` set in `logback.xml` | `TRACE`, `DEBUG`, `INFO`, `WARN`, `ERROR`, `OFF` |
| CLUSTER_OPERATOR_MANAGED | Whether test suite manages CO or not (Makefile) | `true` | `false` |
| COLLECT_TEST_DATA | Whether to gather test data on error or not | `true` | `true`, `false` |
| CUSTOM_EXTRA_DELAY | Prolonged all internal waitFor calls (seconds) | `0` | \<number of seconds\> |
| OPERATOR_INSTALL_ZIP | Url to zip file with install/examples (Makefile) | 7.10.2 url | \<url\> |
| OPERATOR_VERSION_UPSTREAM | Version/branch of repository (Makefile) | main | \<branch\> |
| DUMP_ENABLED | Enabled serialization of deployed resources | `false` | `true`, `false` |
| DUMP_FORMAT | Format of serialized deployed resources | `yaml` | `yaml`, `json` |
| DUMP_LOCATION | Location to dump serialized deployed resources | `serialization-dump` | \<directory\> |
| KUBE_CONTEXT | Provide comma separated context(s) for kubernetes client | `default/null` | null, \<contextA,contextB,contextC,...\> |
| TEARDOWN_ENV | Teardown down deployment or leave it as is | `true` | `true`, `false` |
| PLAYWRIGHT_DEBUG | Playwright will run in head mode (show browser) & record video | `false` | `true`, `false` |
| KUBE_CREDENTIALS | Kubernetes credentials provided in `user/password` format | not set | `claire/c1airePassw0rd` |

## Setting log level
Currently, there is supported `TEST_LOG_LEVEL` environment variable, which can set desired logging level of test suite.
Expand Down
21 changes: 13 additions & 8 deletions operator-suite/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,19 @@
<groupId>org.junit-pioneer</groupId>
<artifactId>junit-pioneer</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>io.sundr</groupId>
<artifactId>builder-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>io.sundr</groupId>
<artifactId>builder-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.playwright</groupId>
<artifactId>playwright</artifactId>
<version>1.49.0</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import io.brokerqe.claire.database.Database;
import io.brokerqe.claire.exception.ClaireNotImplementedException;
import io.brokerqe.claire.exception.ClaireRuntimeException;
import io.brokerqe.claire.helpers.SerializationFormat;
import io.brokerqe.claire.operator.ArtemisCloudClusterOperatorFile;
import io.brokerqe.claire.operator.ArtemisFileProvider;
Expand Down Expand Up @@ -33,6 +34,7 @@ public class EnvironmentOperator extends Environment {
private final String artemisOperatorName;
private final String artemisOperatorType;
private List<String> kubeContexts;
private String kubeCredentials;
private String artemisVersion;
private final ArtemisVersion artemisTestVersion;
private final String brokerImage;
Expand All @@ -49,6 +51,7 @@ public class EnvironmentOperator extends Environment {
private Map<String, KubeClient> kubeClients;
private final boolean collectTestData;
private boolean teardownEnv = true;
private boolean playwrightDebug;
private final int customExtraDelay;
private final boolean serializationEnabled;
private final String serializationDirectory;
Expand All @@ -59,6 +62,7 @@ public EnvironmentOperator() {
this.set(this);
String initialTimestamp = TestUtils.generateTimestamp();
initializeKubeContexts(System.getenv().getOrDefault(Constants.EV_KUBE_CONTEXT, null));
kubeCredentials = System.getenv().getOrDefault(Constants.EV_KUBE_CREDENTIALS, null);
artemisVersion = System.getenv(Constants.EV_ARTEMIS_VERSION);
testLogLevel = System.getenv(Constants.EV_TEST_LOG_LEVEL);
logsDirLocation = System.getenv().getOrDefault(Constants.EV_LOGS_LOCATION, Constants.LOGS_DEFAULT_DIR) + Constants.FILE_SEPARATOR + initialTimestamp;
Expand All @@ -68,6 +72,7 @@ public EnvironmentOperator() {
serializationDirectory = System.getenv().getOrDefault(Constants.EV_DUMP_LOCATION, Constants.DUMP_DEFAULT_DIR) + Constants.FILE_SEPARATOR + initialTimestamp;
serializationFormat = System.getenv().getOrDefault(Constants.EV_DUMP_FORMAT, Constants.DUMP_DEFAULT_TYPE);
teardownEnv = Boolean.parseBoolean(System.getenv().getOrDefault(Constants.EV_TEARDOWN, "true"));
playwrightDebug = Boolean.parseBoolean(System.getenv().getOrDefault(Constants.EV_PLAYWRIGHT_DEBUG, "false"));

disabledRandomNs = Boolean.parseBoolean(System.getenv(Constants.EV_DISABLE_RANDOM_NAMESPACES));
customExtraDelay = Integer.parseInt(System.getenv().getOrDefault(Constants.EV_CUSTOM_EXTRA_DELAY, "0"));
Expand Down Expand Up @@ -115,6 +120,9 @@ private void printAllUsedTestVariables() {
envVarsSB.append(Constants.EV_DUMP_ENABLED).append("=").append(serializationEnabled).append(Constants.LINE_SEPARATOR);
envVarsSB.append(Constants.EV_TEARDOWN).append("=").append(teardownEnv).append(Constants.LINE_SEPARATOR);

if (kubeCredentials != null) {
envVarsSB.append(Constants.EV_KUBE_CREDENTIALS).append("=").append(kubeCredentials).append(Constants.LINE_SEPARATOR);
}
if (testLogLevel != null) {
envVarsSB.append(Constants.EV_TEST_LOG_LEVEL).append("=").append(testLogLevel).append(Constants.LINE_SEPARATOR);
}
Expand Down Expand Up @@ -165,6 +173,9 @@ private void printAllUsedTestVariables() {
envVarsSB.append(Constants.EV_DUMP_LOCATION).append("=").append(serializationDirectory).append(Constants.LINE_SEPARATOR);
envVarsSB.append(Constants.EV_DUMP_FORMAT).append("=").append(serializationFormat).append(Constants.LINE_SEPARATOR);
}
if (playwrightDebug) {
envVarsSB.append(Constants.EV_PLAYWRIGHT_DEBUG).append("=").append(playwrightDebug).append(Constants.LINE_SEPARATOR);
}

LOGGER.info(envVarsSB.toString());
}
Expand All @@ -189,6 +200,11 @@ public boolean isTeardownEnv() {
return teardownEnv;
}

@Override
public boolean isPlaywrightDebug() {
return playwrightDebug;
}

@Override
public boolean isUpstreamArtemis() {
return artemisOperatorType.equals("upstream");
Expand Down Expand Up @@ -306,6 +322,18 @@ public boolean isProjectManagedClusterOperator() {
return projectManagedClusterOperator;
}

public String[] getKubeCredentials() {
if (kubeCredentials != null) {
if (kubeCredentials.contains("/")) {
return kubeCredentials.split("/");
} else {
throw new ClaireRuntimeException("Provided " + Constants.EV_KUBE_CREDENTIALS +
" credentials are in incorrect format! Missing '/' as username/password delimiter!");
}
} else {
throw new ClaireRuntimeException("Missing environment variable " + Constants.EV_KUBE_CREDENTIALS);
}
}
public String getBrokerImage() {
return brokerImage;
}
Expand Down
Loading

0 comments on commit 1cbf750

Please sign in to comment.