Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use cypress dashboard and stabilize e2e tests #10807

Merged
merged 7 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,8 @@ jobs:
run: SUB_BUILD=PLATFORM ./gradlew --no-daemon assemble --scan

- name: Run End-to-End Frontend Tests
env:
CYPRESS_WEBAPP_KEY: ${{ secrets.CYPRESS_WEBAPP_KEY }}
run: ./tools/bin/e2e_test.sh
# In case of self-hosted EC2 errors, remove this block.
stop-frontend-test-runner:
Expand Down
11 changes: 9 additions & 2 deletions airbyte-webapp-e2e-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@ node {

task e2etest(type: NpmTask) {
dependsOn npmInstall

args = ['run', 'cypress:ci']
// If the cypressWebappKey property has been set from the outside (see tools/bin/e2e_test.sh)
// we'll record the cypress session, otherwise we're not recording
def recordCypress = project.hasProperty('cypressWebappKey') && project.getProperty('cypressWebappKey')
if (recordCypress) {
environment = [CYPRESS_KEY: project.getProperty('cypressWebappKey')]
args = ['run', 'cypress:ci:record']
} else {
args = ['run', 'cypress:ci']
}
inputs.files fileTree('cypress')
inputs.file 'package.json'
inputs.file 'package-lock.json'
Expand Down
1 change: 1 addition & 0 deletions airbyte-webapp-e2e-tests/cypress.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"projectId": "916nvw",
"baseUrl": "http://localhost:3000",
"testFiles": [
"base.spec.js",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
describe("Connection main actions", () => {
beforeEach(() => {
cy.initialSetupCompleted();
});

it("Create new connection", () => {
cy.createTestConnection("Test connection source cypress", "Test destination cypress");

cy.get("div").contains("Test connection source cypress").should("exist");
cy.get("div").contains("Test destination cypress").should("exist");
});

it.only("Update connection", () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ This was (I guess) accidentally merged from https://github.com/airbytehq/airbyte/pull/9025/files

it("Update connection", () => {
cy.intercept("/api/v1/web_backend/connections/update").as("updateConnection");

cy.createTestConnection("Test update connection source cypress", "Test update connection destination cypress");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
describe("Destination main actions", () => {
beforeEach(() => {
cy.initialSetupCompleted();
});

it("Create new destination", () => {
cy.createTestDestination("Test destination cypress");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
describe("Preferences actions", () => {
beforeEach(() => {
cy.initialSetupCompleted(false);
});

it("Should redirect to onboarding after email is entered", () => {
cy.visit("/preferences");
cy.url().should("include", `/preferences`);
Expand Down
4 changes: 4 additions & 0 deletions airbyte-webapp-e2e-tests/cypress/integration/source.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
describe("Source main actions", () => {
beforeEach(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done to always start fresh from the new workspace, right?

Copy link
Collaborator Author

@timroes timroes Mar 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that fakes the response of the workspaces to act like they have been through the initial setup flow. Otherwise the app would show the preference screen for those tests. This worked only so far because the onboarding test suit ran before this one and worked through that screen. But that requires those test suits to run in a specific dependent order, which we should not rely on (and recording is actually breaking that order). With faking this response slightly, we can make sure that tests won't run into the preference screen (or run into it, if needed), as we require, without being dependent on any other test suite.

cy.initialSetupCompleted();
});

it("Create new source", () => {
cy.createTestSource("Test source cypress");

Expand Down
1 change: 1 addition & 0 deletions airbyte-webapp-e2e-tests/cypress/support/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ import "./sidebar";
import "./source";
import "./destination";
import "./connection";
import "./workspaces";
10 changes: 10 additions & 0 deletions airbyte-webapp-e2e-tests/cypress/support/commands/workspaces.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Cypress.Commands.add("initialSetupCompleted", (completed = true) => {
// Modify the workspaces/list response to mark every workspace as "initialSetupComplete" to ensure we're not showing
// the setup/preference page for any workspace if this method got called.
cy.intercept("POST", "/api/v1/workspaces/list", (req) => {
req.continue(res => {
res.body.workspaces = res.body.workspaces.map(ws => ({ ...ws, initialSetupComplete: completed }));
res.send(res.body);
});
});
});
3 changes: 2 additions & 1 deletion airbyte-webapp-e2e-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "Airbyte e2e testing",
"scripts": {
"cypress:open": "cypress open",
"cypress:ci": "CYPRESS_BASE_URL=http://localhost:8000 cypress run"
"cypress:ci": "CYPRESS_BASE_URL=http://localhost:8000 cypress run",
"cypress:ci:record": "CYPRESS_BASE_URL=http://localhost:8000 cypress run --record --key $CYPRESS_KEY"
},
"eslintConfig": {
"env": {
Expand Down
14 changes: 9 additions & 5 deletions tools/bin/e2e_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ mkdir -p /tmp/airbyte_local

# Detach so we can run subsequent commands
VERSION=dev TRACKING_STRATEGY=logging docker-compose up -d
trap 'echo "docker-compose logs:" && docker-compose logs -t --tail 1000 && docker-compose down && docker rm -f $(docker ps -q --filter name=airbyte_ci_pg)' EXIT
trap 'echo "docker-compose logs:" && docker-compose logs -t --tail 1000 && docker-compose down && docker stop airbyte_ci_pg' EXIT

docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=secret_password -e POSTGRES_DB=airbyte_ci --name airbyte_ci_pg postgres
echo "Waiting for services to begin"
sleep 30 # TODO need a better way to wait
docker run --rm -d -p 5433:5432 -e POSTGRES_PASSWORD=secret_password -e POSTGRES_DB=airbyte_ci --name airbyte_ci_pg postgres
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ Using --rm here to automatically remove the container one stopped, allows to shorten the above trap command to a way simpler stop.

echo "Waiting for health API to be available..."
# Retry loading the health API of the server to check that the server is fully available
until $(curl --output /dev/null --fail --silent --max-time 5 --head localhost:8001/api/v1/health); do
echo "Health API not available yet. Retrying in 10 seconds..."
sleep 10
done

echo "Running e2e tests via gradle"
SUB_BUILD=PLATFORM ./gradlew --no-daemon :airbyte-webapp-e2e-tests:e2etest
SUB_BUILD=PLATFORM ./gradlew --no-daemon :airbyte-webapp-e2e-tests:e2etest -PcypressWebappKey=$CYPRESS_WEBAPP_KEY