Skip to content

Instantly share code, notes, and snippets.

@web-dave
Created March 30, 2020 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save web-dave/6e8fd925d85d92c744d9ea4e89ea39f8 to your computer and use it in GitHub Desktop.
Save web-dave/6e8fd925d85d92c744d9ea4e89ea39f8 to your computer and use it in GitHub Desktop.
<span>{{ title }} app is running!</span>
it("loads examples", () => {
cy.visit("http://localhost:4200");
cy.contains("Replace me with something relevant");
});
describe('Cypress Test', () => {
beforeEach(() => {
cy.visit('http://localhost:4200');
cy.get('span').as('spans');
cy.get('div.terminal').as('terminal');
});
...
});
cy.get('@spans')
.contains(step)
.click();
cy.get('@terminal').should('contain', commands[step]);
it('create User', () => {
cy.get('button.new-user').click();
cy.get('.headline').contains('Nutzer anlegen');
cy.get('input[formcontrolname="name"]').type('Hannes');
cy.get('button.save').should('be.enabled').click();
});
cy.server();
cy.route(url)
cy.route(url, response)
cy.route(method, url)
cy.route(method, url, response)
cy.route('http://my.api.com', { name: 'Hannes' });
cy.route('http://my.api.com', 'fixture:example.json');
cy.route('POST', 'http://my.api.com/users', '123456789').as(
'new-user'
);
cy.get('@new-user')
.its('request.body')
.should('deep.equal', {
name: 'Hannes',
kundennummer: '1597',
});
describe('Next Steps', () => {...})
describe("Hooks", () => {
before(() => {
/* Wird einmalig VOR allen Tests ausgeführt */
});
after(() => {
/* Wird einmalig NACH allen Tests ausgeführt */
});
beforeEach(() => {
/* Wird VOR JEDEM Test ausgeführt */
});
afterEach(() => {
/* Wird NACH JEDEM Test ausgeführt */
});
});
it(`Beim besuche der Seite soll der Nutzer mit dem Namen das Projekts begrüsst werden, in form von: ProjektName app is running`, () => {
cy.visit('http://localhost:4200');
cy.get('span').contains('cypress-test app is running!');
});
it(`Beim Klick auf eine der Next Steps soll in der Anzeige eine Bestimmte Ausgabe angezeigt werden.`, () => {
cy.visit('http://localhost:4200');
});
const commands = {
'New Component': 'ng generate component xyz',
'Angular Material': 'ng add @angular/material',
'Add PWA support': 'ng add @angular/pwa',
'Add Dependency': 'ng add _____',
'Run and Watch Tests': 'ng test',
'Build for Production': 'ng build --prod'
};
it(`Beim Klick auf eine der Next Steps soll in der Anzeige eine Bestimmte Ausgabe angezeigt werden.`, () => {
cy.visit('http://localhost:4200');
for (const step in commands) {
cy.get('span')
.contains(step)
.click();
}
});
cy.get('div.terminal').should('contain', commands[step]);
it(`Beim Klick auf eine der Next Steps soll in der Anzeige eine Bestimmte Ausgabe angezeigt werden.`, () => {
cy.visit('http://localhost:4200');
// tslint:disable-next-line:forin
for (const step in commands) {
cy.get('span')
.contains(step)
.click();
cy.get('div.terminal').should('contain', commands[step]);
}
});
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "my-project:serve"
},
"configurations": {
"production": {
"devServerTarget": "my-project:serve:production"
}
}
}
"e2e": {
"builder": "@briebug/cypress-schematic:cypress",
"options": {
"devServerTarget": "cypress-test:serve",
"watch": true,
"headless": false
},
"configurations": {
"production": {
"devServerTarget": "cypress-test:serve:production"
}
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment