Angular Tour of Heroes Application with Cypress Testing Framework
npm install
In one terminal run the following command from the root directory for the repo:
npm run server
In another terminal run the following command:
npm start
then browse to localhost:4200 and make sure that the website is running. Finally double check your cypress installation by running the following command in a 3rd terminal
npx cypress open
A cypress window should open. If it does you are good.
Add "types": ["cypress"],
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "es2015",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"types": ["cypress"],
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2018",
"dom"
]
}
}
Under the cyrpess folder create the directory integration and then create the file initial-page.spec.ts
describe('dashboard', () => {
it(`true is true`, () => {
})
})
describe('dashboard', () => {
it(`has title 'Tour of Heroes'`, () => {
cy.visit("localhost:4200/dashboard");
})
})
describe('dashboard', () => {
it(`has title 'Tour of Heroes'`, () => {
cy.visit("localhost:4200/dashboard");
cy.get('h1').should('contain', 'Tour of Heroes');
})
})
describe('dashboard', () => {
it(`has title 'Tour of Heroes'`, () => {
cy.visit("localhost:4200/dashboard");
cy.get('h1').should('contain', 'Tour of Heroes');
cy.title().should('eq', 'Tour of Heroes');
})
})
describe('dashboard', () => {
it(`has title 'Tour of Heroes'`, () => {
cy.visit("localhost:4200/dashboard");
cy.contains('Tour of Heroes')
cy.get('h1').should('contain', 'Tour of Heroes');
cy.title().should('eq', 'Tour of Heroes');
})
})
describe('dashboard', () => {
it(`has title 'Tour of Heroes'`, () => {
cy.visit("localhost:4200/dashboard");
cy.contains('Tour of Heroes');
cy.get('.hero');
cy.get('h1').should('contain', 'Tour of Heroes');
cy.title().should('eq', 'Tour of Heroes');
})
})
describe('dashboard', () => {
it(`has title 'Tour of Heroes'`, () => {
cy.visit("localhost:4200/dashboard");
cy.contains('Tour of Heroes');
cy.get('h1').then(h1 => {
// Get access to the raw DOM node
})
})
})
describe('dashboard', () => {
it(`has title 'Tour of Heroes'`, () => {
cy.visit("localhost:4200/dashboard");
cy.contains('Tour of Heroes');
cy.get('.hero');
cy.get('h1').should('contain', 'Tour of Heroes');
cy.title().should('eq', 'Tour of Heroes');
})
it (`has the correct header`, () => {
cy.visit("localhost:4200/dashboard");
cy.contains('Dashboard');
cy.get('nav a').eq(1).should('contain', 'Heroes');
cy.contains('Top Heroes');
})
})
describe('dashboard', () => {
it(`has title 'Tour of Heroes'`, () => {
cy.visit("localhost:4200/dashboard");
cy.contains('Tour of Heroes');
cy.get('.hero');
cy.get('h1').should('contain', 'Tour of Heroes');
cy.title().should('eq', 'Tour of Heroes');
})
it (`has the correct header`, () => {
cy.visit("localhost:4200/dashboard");
cy.contains('Dashboard');
cy.get('nav a').eq(1).should('contain', 'Heroes');
cy.contains('Top Heroes');
})
it (`has the correct search header`, () =>{
cy.visit("localhost:4200/dashboard");
cy.contains("Hero Search");
})
})
describe('dashboard', () => {
beforeEach(() => {
cy.visit("localhost:4200/dashboard");
})
it(`has title 'Tour of Heroes'`, () => {
cy.contains('Tour of Heroes');
cy.get('.hero');
cy.get('h1').should('contain', 'Tour of Heroes');
cy.title().should('eq', 'Tour of Heroes');
})
it (`has the correct header`, () => {
cy.contains('Dashboard');
cy.get('nav a').eq(1).should('contain', 'Heroes');
cy.contains('Top Heroes');
})
it (`has the correct search header`, () =>{
cy.contains("Hero Search");
cy.get('app-hero-search h4').should('contain', 'Hero Search');
})
})
describe('dashboard', () => {
beforeEach(() => {
cy.visit("localhost:4200/dashboard");
})
it(`has title 'Tour of Heroes'`, () => {
cy.contains('Tour of Heroes');
cy.get('.hero');
cy.get('h1').should('contain', 'Tour of Heroes');
cy.title().should('eq', 'Tour of Heroes');
})
it (`has the correct header`, () => {
cy.contains('Dashboard');
cy.get('nav a').eq(1).should('contain', 'Heroes');
cy.contains('Top Heroes');
})
it (`has the correct search header`, () =>{
cy.contains("Hero Search");
cy.get('app-hero-search h4').should('contain', 'Hero Search');
})
it ('can search', () => {
cy.get('#search-box').type('Mr. Nice');
cy.get('.search-result li').contains('Mr. Nice').click();
cy.url().should('include', '/detail/11');
})
})