Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
better ci
Browse files Browse the repository at this point in the history
  • Loading branch information
mpetrunic committed Sep 26, 2022
1 parent f698b13 commit 4bc7281
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/helpers/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ElementHandle, Page } from 'puppeteer';

// TODO: change text() with '.';
export const getElementByContent = (page: Page, text: string, type = '*'): Promise<ElementHandle | null> =>
page.waitForXPath(`//${type}[contains(text(), '${text}') and not(@disabled)]`);
page.waitForXPath(`//${type}[contains(text(), '${text}') and not(@disabled)]`, { timeout: 15000 });

export const getInputByLabel = (
page: Page,
Expand Down
26 changes: 19 additions & 7 deletions test/basic.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { writeFileSync } from 'fs';
import path from 'path';

import { expect, use } from 'chai';
import chaiAsPromised from 'chai-as-promised';
import { Page } from 'puppeteer';
Expand All @@ -16,10 +19,14 @@ describe('basic interactions', async function () {

before(async function (this: TestContext) {
testPage = await this.browser.newPage();
await testPage.goto('http://localhost:8080/');
await clickElement(testPage, '.connect-button');
await testPage.goto('http://localhost:8080/', { waitUntil: 'load' });
metamask = this.metamask;
await metamask.approve();
try {
await clickElement(testPage, '.connect-button');
await metamask.approve();
} catch (e) {
//ignored
}
});

after(async function () {
Expand All @@ -36,10 +43,15 @@ describe('basic interactions', async function () {
});

it('should be able to sign', async () => {
await clickElement(testPage, '.sign-button');
await metamask.sign();

await testPage.waitForSelector('#signed');
try {
await clickElement(testPage, '.sign-button');
await metamask.sign();

await testPage.waitForSelector('#signed');
} catch (e) {
writeFileSync(path.resolve(__dirname, '../sign.png'), await metamask.page.screenshot({ encoding: 'binary' }));
expect.fail(e);
}
});

it('should return eth balance', async () => {
Expand Down
46 changes: 29 additions & 17 deletions test/contract.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { writeFileSync } from 'fs';
import path from 'path';

import { expect } from 'chai';
import { Page } from 'puppeteer';

Expand All @@ -16,31 +19,40 @@ describe('contract interactions', async function () {
before(async function (this: TestContext) {
contract = await deployContract(this.provider);
testPage = await this.browser.newPage();
await testPage.goto('http://localhost:8080/');
await testPage.goto('http://localhost:8080/', { waitUntil: 'load' });
metamask = this.metamask;
await clickElement(testPage, '.connect-button');
// await metamask.approve();
try {
await clickElement(testPage, '.connect-button');
await metamask.approve();
} catch (e) {
//ignored
}
});

after(async function (this: TestContext) {
await testPage.close();
});

it('should have increased count', async () => {
await metamask.switchNetwork('local');
const counterBefore = await getCounterNumber(contract);
// click increase button
await clickElement(testPage, '.increase-button');
await pause(1);
// submit tx
await metamask.confirmTransaction();
await testPage.waitForSelector('#txSent');
await pause(1);

const counterAfter = await getCounterNumber(contract);

expect(counterAfter).to.be.equal(counterBefore + 1);
await metamask.switchNetwork('main');
try {
await metamask.switchNetwork('local');
const counterBefore = await getCounterNumber(contract);
// click increase button
await clickElement(testPage, '.increase-button');
await pause(1);
// submit tx
await metamask.confirmTransaction();
await testPage.waitForSelector('#txSent');
await pause(1);

const counterAfter = await getCounterNumber(contract);

expect(counterAfter).to.be.equal(counterBefore + 1);
await metamask.switchNetwork('main');
} catch (e) {
writeFileSync(path.resolve(__dirname, '../sign.png'), await metamask.page.screenshot({ encoding: 'binary' }));
expect.fail(e);
}
});
});

Expand Down

0 comments on commit 4bc7281

Please sign in to comment.