Skip to content

Commit

Permalink
Port the login e2e test to cypress
Browse files Browse the repository at this point in the history
  • Loading branch information
ocket8888 committed Dec 27, 2023
1 parent c0ebe87 commit dd57f35
Show file tree
Hide file tree
Showing 13 changed files with 2,197 additions and 263 deletions.
472 changes: 254 additions & 218 deletions experimental/traffic-portal/angular.json

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions experimental/traffic-portal/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { defineConfig } from "cypress";

export default defineConfig({
component: {
devServer: {
bundler: "webpack",
framework: "angular",
},
specPattern: "**/*.cy.ts"
},
e2e: {
baseUrl: "http://localhost:4200"
},

});
52 changes: 52 additions & 0 deletions experimental/traffic-portal/cypress/e2e/login.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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.
*/

describe("Login Page", () => {
beforeEach(() => {
cy.visit("/login");
// cy.contains("dismiss").click();
});
it("Clears the form when the 'Clear' button is clicked", () => {
const usernameInput = cy.get("input").first();
usernameInput.type("test");

const passwordInput = cy.get("input").last();
passwordInput.type("asdf");

cy.contains("button", "Clear").click();

usernameInput.should("have.value", "");
passwordInput.should("have.value", "");
});

it("Rejects incorrect passwords", () => {
cy.get("input").first().type("test");
cy.get("input").last().type("asdf");

cy.contains("button", "Login").click();

cy.contains("Invalid username or password");
});

it("Logs in", () => {
cy.fixture("login").then(
({username, password}: {username: string; password: string}) => {
cy.get("input").first().type(username);
cy.get("input").last().type(password);
cy.contains("button", "Login").click();
cy.window().its("location.pathname").should("eq", "/core");
}
);
});
});
5 changes: 5 additions & 0 deletions experimental/traffic-portal/cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io"
}

4 changes: 4 additions & 0 deletions experimental/traffic-portal/cypress/fixtures/login.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"username": "admin",
"password": "twelve12"
}
57 changes: 57 additions & 0 deletions experimental/traffic-portal/cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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.
*/

// ***********************************************
// This example namespace declaration will help
// with Intellisense and code completion in your
// IDE or Text Editor.
// ***********************************************
// declare namespace Cypress {
// interface Chainable<Subject = any> {
// customCommand(param: any): typeof customCommand;
// }
// }
//
// function customCommand(param: any): void {
// console.warn(param);
// }
//
// NOTE: You can use it like so:
// Cypress.Commands.add('customCommand', customCommand);
//
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add("login", (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
12 changes: 12 additions & 0 deletions experimental/traffic-portal/cypress/support/component-index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Components App</title>
</head>
<body>
<div data-cy-root></div>
</body>
</html>
53 changes: 53 additions & 0 deletions experimental/traffic-portal/cypress/support/component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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.
*/

// ***********************************************************
// This example support/component.ts is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
// import "./commands";

// Alternatively you can use CommonJS syntax:
// require('./commands')

// import { mount } from "cypress/angular";

// Augment the Cypress namespace to include type definitions for
// your custom command.
// Alternatively, can be defined in cypress/support/component.d.ts
// with a <reference path="./component" /> at the top of your spec.
// declare global {
// namespace Cypress {
// interface Chainable {
// mount: typeof mount;
// }
// }
// }

// Cypress.Commands.add("mount", mount);

// Example use:
// cy.mount(MyComponent)
31 changes: 31 additions & 0 deletions experimental/traffic-portal/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.
*/

// ***********************************************************
// This example support/e2e.ts is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// When a command from ./commands is ready to use, import with `import './commands'` syntax
// import './commands';
8 changes: 8 additions & 0 deletions experimental/traffic-portal/cypress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../tsconfig.json",
"include": ["**/*.ts"],
"compilerOptions": {
"sourceMap": false,
"types": ["cypress"]
}
}
40 changes: 0 additions & 40 deletions experimental/traffic-portal/nightwatch/tests/login/login.spec.ts

This file was deleted.

Loading

0 comments on commit dd57f35

Please sign in to comment.