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

feat(@schematics/angular): generate E2E tests with native promise support #18951

Merged
merged 3 commits into from Oct 5, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -16,6 +16,7 @@ exports.config = {
browserName: 'chrome'
},
directConnect: true,
SELENIUM_PROMISE_MANAGER: false,
baseUrl: 'http://localhost:4200/',
framework: 'jasmine',
jasmineNodeOpts: {
Expand Down
Expand Up @@ -8,9 +8,9 @@ describe('workspace-project App', () => {
page = new AppPage();
});

it('should display welcome message', () => {
page.navigateTo();
expect(page.getTitleText()).toEqual('<%= relatedAppName %> app is running!');
it('should display welcome message', async () => {
await page.navigateTo();
expect(await page.getTitleText()).toEqual('<%= relatedAppName %> app is running!');
});

afterEach(async () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/schematics/angular/e2e/files/src/app.po.ts.template
@@ -1,11 +1,11 @@
import { browser, by, element } from 'protractor';

export class AppPage {
navigateTo(): Promise<unknown> {
return browser.get(browser.baseUrl) as Promise<unknown>;
async navigateTo(): Promise<unknown> {
return browser.get(browser.baseUrl);
}

getTitleText(): Promise<string> {
return element(by.css('<%= rootSelector %> .content span')).getText() as Promise<string>;
async getTitleText(): Promise<string> {
return element(by.css('<%= rootSelector %> .content span')).getText();
}
}
Expand Up @@ -7,7 +7,6 @@
"target": "es2018",
"types": [
"jasmine",
"jasminewd2",
"node"
]
}
Expand Down
Expand Up @@ -25,8 +25,7 @@
"devDependencies": {
"@angular/cli": "<%= '~' + version %>",
"@angular/compiler-cli": "<%= latestVersions.Angular %>",<% if (!minimal) { %>
"@types/jasmine": "~3.5.0",
"@types/jasminewd2": "~2.0.3",<% } %>
"@types/jasmine": "~3.5.0",<% } %>
"@types/node": "^12.11.1",<% if (!minimal) { %>
"codelyzer": "^6.0.0",
"jasmine-core": "~3.6.0",
Expand Down
1 change: 1 addition & 0 deletions tests/legacy-cli/e2e/assets/protractor-saucelabs.conf.js
Expand Up @@ -67,6 +67,7 @@ exports.config = {
// Only allow one session at a time to prevent over saturation of Saucelabs sessions.
maxSessions: 1,

SELENIUM_PROMISE_MANAGER: false,
baseUrl: 'http://localhost:2000/',
framework: 'jasmine',
jasmineNodeOpts: {
Expand Down
6 changes: 3 additions & 3 deletions tests/legacy-cli/e2e/tests/build/lazy-load-syntax.ts
Expand Up @@ -56,9 +56,9 @@ export default async function () {
import { browser, logging, element, by } from 'protractor';

describe('workspace-project App', () => {
it('should display lazy route', () => {
browser.get(browser.baseUrl + '/lazy');
expect(element(by.css('app-lazy-comp p')).getText()).toEqual('lazy-comp works!');
it('should display lazy route', async () => {
await browser.get(browser.baseUrl + '/lazy');
expect(await element(by.css('app-lazy-comp p')).getText()).toEqual('lazy-comp works!');
});

afterEach(async () => {
Expand Down
6 changes: 3 additions & 3 deletions tests/legacy-cli/e2e/tests/build/rollup.ts
Expand Up @@ -35,9 +35,9 @@ export default async function () {
import { browser, logging, element, by } from 'protractor';

describe('workspace-project App', () => {
it('should display lazy route', () => {
browser.get(browser.baseUrl + '/lazy');
expect(element(by.css('app-lazy p')).getText()).toEqual('lazy works!');
it('should display lazy route', async () => {
await browser.get(browser.baseUrl + '/lazy');
expect(await element(by.css('app-lazy p')).getText()).toEqual('lazy works!');
});

afterEach(async () => {
Expand Down
Expand Up @@ -52,9 +52,9 @@ export default async function () {
page = new AppPage();
});

it('should display text from library component', () => {
page.navigateTo();
expect(element(by.css('lib-my-lib p')).getText()).toEqual('my-lib works!');
it('should display text from library component', async () => {
await page.navigateTo();
expect(await element(by.css('lib-my-lib p')).getText()).toEqual('my-lib works!');
});

afterEach(async () => {
Expand Down
18 changes: 9 additions & 9 deletions tests/legacy-cli/e2e/tests/i18n/legacy.ts
Expand Up @@ -125,7 +125,7 @@ export async function setupI18nConfig(useLocalize = true, format: keyof typeof f
import { browser, logging, element, by } from 'protractor';

describe('workspace-project App', () => {
const getParagraph = (name: string) => element(by.css('app-root p#' + name)).getText();
const getParagraph = async (name: string) => element(by.css('app-root p#' + name)).getText();
beforeEach(() => browser.get(browser.baseUrl));
afterEach(async () => {
// Assert that there are no errors emitted from the browser
Expand All @@ -135,17 +135,17 @@ export async function setupI18nConfig(useLocalize = true, format: keyof typeof f
} as logging.Entry));
});

it('should display welcome message', () =>
expect(getParagraph('hello')).toEqual('${translation.hello}'));
it('should display welcome message', async () =>
expect(await getParagraph('hello')).toEqual('${translation.hello}'));

it('should display locale', () =>
expect(getParagraph('locale')).toEqual('${lang}'));
it('should display locale', async () =>
expect(await getParagraph('locale')).toEqual('${lang}'));

it('should display localized date', () =>
expect(getParagraph('date')).toEqual('${translation.date}'));
it('should display localized date', async () =>
expect(await getParagraph('date')).toEqual('${translation.date}'));

it('should display pluralized message', () =>
expect(getParagraph('plural')).toEqual('${translation.plural}'));
it('should display pluralized message', async () =>
expect(await getParagraph('plural')).toEqual('${translation.plural}'));
});
`);
}
Expand Down
12 changes: 1 addition & 11 deletions tests/legacy-cli/e2e/tests/misc/browsers.ts
Expand Up @@ -46,17 +46,7 @@ export default async function () {
// Leading and trailing space is not removed
await replaceInFile(
'e2e/src/app.e2e-spec.ts',
'\'should display welcome message\',',
'\'should display welcome message\', async',
);
await replaceInFile(
'e2e/src/app.e2e-spec.ts',
'page.navigateTo();',
'await page.navigateTo();',
);
await replaceInFile(
'e2e/src/app.e2e-spec.ts',
'page.getTitleText()',
'await page.getTitleText()',
'(await page.getTitleText()).trim()',
);

Expand Down
22 changes: 11 additions & 11 deletions tests/legacy-cli/e2e/tests/misc/third-party-decorators.ts
Expand Up @@ -16,11 +16,11 @@ export default function () {
'./e2e/src/app.po.ts': `
import { browser, by, element } from 'protractor';
export class AppPage {
navigateTo() { return browser.get('/'); }
async navigateTo() { return browser.get('/'); }
getIncrementButton() { return element(by.buttonText('Increment')); }
getDecrementButton() { return element(by.buttonText('Decrement')); }
getResetButton() { return element(by.buttonText('Reset Counter')); }
getCounter() { return element(by.xpath('/html/body/app-root/div/span')).getText(); }
async getCounter() { return element(by.xpath('/html/body/app-root/div/span')).getText(); }
}
`,
'./e2e/src/app.e2e-spec.ts': `
Expand All @@ -33,15 +33,15 @@ export default function () {
page = new AppPage();
});

it('should operate counter', () => {
page.navigateTo();
page.getIncrementButton().click();
page.getIncrementButton().click();
expect(page.getCounter()).toEqual('2');
page.getDecrementButton().click();
expect(page.getCounter()).toEqual('1');
page.getResetButton().click();
expect(page.getCounter()).toEqual('0');
it('should operate counter', async () => {
await page.navigateTo();
await page.getIncrementButton().click();
await page.getIncrementButton().click();
expect(await page.getCounter()).toEqual('2');
await page.getDecrementButton().click();
expect(await page.getCounter()).toEqual('1');
await page.getResetButton().click();
expect(await page.getCounter()).toEqual('0');
});
});
`,
Expand Down