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

Separate browser logs #2977

Merged
merged 8 commits into from
Sep 14, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
runs-on: macos-12
strategy:
matrix:
browser: ['chrome']
browser: ['chrome', 'firefox']
fail-fast: false
steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -114,15 +114,15 @@ jobs:
if: ${{ failure() }}
uses: actions/upload-artifact@v3
with:
name: testRunsData
path: ./packages/yoroi-extension/testRunsData
name: testRunsData_${{ matrix.browser }}
path: ./packages/yoroi-extension/testRunsData_${{ matrix.browser }}

Trezor_Model_T_emulator:
if: github.event.review && (github.event.review.state == 'approved' || contains(github.event.review.body, '/check') || contains(github.event.review.body, '/trezor-check'))
runs-on: ubuntu-22.04
strategy:
matrix:
browser: ['chrome']
browser: ['chrome', 'firefox']
fail-fast: false
steps:
- name: Forcefully update the Chrome browser
Expand Down Expand Up @@ -239,15 +239,15 @@ jobs:
if: ${{ failure() }}
uses: actions/upload-artifact@v3
with:
name: testRunsData
path: ./packages/yoroi-extension/testRunsData
name: testRunsData_${{ matrix.browser }}
path: ./packages/yoroi-extension/testRunsData_${{ matrix.browser }}

E2E_smoke_tests:
if: github.event.review && (contains(github.event.review.body, '/release-check'))
runs-on: ubuntu-22.04
strategy:
matrix:
browser: ['chrome']
browser: ['chrome', 'firefox']
fail-fast: false
steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -333,5 +333,5 @@ jobs:
if: ${{ failure() }}
uses: actions/upload-artifact@v3
with:
name: testRunsData
path: ./packages/yoroi-extension/testRunsData
name: testRunsData_${{ matrix.browser }}
path: ./packages/yoroi-extension/testRunsData_${{ matrix.browser }}
1 change: 1 addition & 0 deletions packages/yoroi-extension/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ production-key.pem
build/
dev/
testRunsData/
testRunsData*
storybook-static/
__screenshots__/
screenshots/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ export function getMockServer(settings: {
outputLog?: boolean,
...
}): typeof MockServer {
const dir = `${testRunsDataDir}cardanoMockServerLogs`;
fs.mkdirSync(dir);
const dir = `${testRunsDataDir}_cardanoMockServerLogs`;
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
const loggerPath = `${dir}/cardanoMockServerLog_${getLogDate()}.log`;

logger = simpleNodeLogger.createSimpleFileLogger(loggerPath);
Expand Down
37 changes: 32 additions & 5 deletions packages/yoroi-extension/features/step_definitions/common-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,13 @@ import {
walletRecoveryPhraseDisplayDialog
} from '../pages/createWalletPage';
import * as helpers from '../support/helpers/helpers';
import { MockDAppWebpage } from '../mock-dApp-webpage';
import { WindowManager } from '../support/windowManager';

const simpleNodeLogger = require('simple-node-logger');

const { promisify } = require('util');
const fs = require('fs');
const rimraf = require('rimraf');

/** We need to keep track of our progress in testing to give unique names to screenshots */
const testProgress = {
Expand All @@ -92,8 +95,6 @@ const testProgress = {
};

BeforeAll(() => {
rimraf.sync(testRunsDataDir);
fs.mkdirSync(testRunsDataDir);
setDefaultTimeout(20 * 1000);

CardanoServer.getMockServer({});
Expand All @@ -105,7 +106,8 @@ AfterAll(() => {
ErgoServer.closeMockServer();
});

Before(scenario => {
// eslint-disable-next-line prefer-arrow-callback
Before(function(scenario) {
const pathItems = scenario.sourceLocation.uri.split('/');
// eslint-disable-next-line no-console
console.log(
Expand All @@ -117,6 +119,30 @@ Before(scenario => {
testProgress.scenarioName = scenario.pickle.name.replace(/[^0-9a-z_ ]/gi, '');
testProgress.lineNum = scenario.sourceLocation.line;
testProgress.step = 0;

const logsDir = `${testRunsDataDir}_${this.getBrowser()}/${testProgress.scenarioName}/`

if (!fs.existsSync(logsDir)) {
fs.mkdirSync(logsDir, { recursive: true });
}

const mockAndWMLogPath = `${logsDir}mockAndWM.log`;
const mockAndWMLogger = simpleNodeLogger.createSimpleFileLogger(mockAndWMLogPath);
this.windowManager = new WindowManager(this.driver, mockAndWMLogger);
this.windowManager.init().then().catch();
this.addToLoggers(mockAndWMLogger);
this.mockDAppPage = new MockDAppWebpage(this.driver, mockAndWMLogger);

const webDriverLogPath = `${logsDir}webDriver.log`;
this.webDriverLogger = simpleNodeLogger.createSimpleFileLogger(webDriverLogPath);
this.addToLoggers(this.webDriverLogger);

const trezorEmuLogPath = `${logsDir}trezorEmulatorController.log`;
this.trezorEmuLogger = simpleNodeLogger.createSimpleFileLogger(trezorEmuLogPath);
this.addToLoggers(this.trezorEmuLogger);

this.sendToAllLoggers(`#### The scenario "${scenario.pickle.name}" has started ####`);

});

Before({ tags: 'not @TestAssuranceChain' }, () => {
Expand Down Expand Up @@ -238,7 +264,8 @@ setDefinitionFunctionWrapper((fn, _, pattern) => {
async function createDirInTestRunsData(driver, subdirectoryName) {
const cap = await driver.getCapabilities();
const browserName = cap.getBrowserName();
const dir = `${testRunsDataDir}/${browserName}/${testProgress.scenarioName}/${subdirectoryName}`;

const dir = `${testRunsDataDir}_${browserName}/${testProgress.scenarioName}/${subdirectoryName}`;
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
// @flow

export const testRunsDataDir = './testRunsData/';
export const testRunsDataDir = './testRunsData';
export const snapshotsDir = './features/yoroi_snapshots/';
export const testRunsLogsDir = `${testRunsDataDir}Logs/`;
export const mockDAppLogsDir = `${testRunsLogsDir}mockDApp/`;
export const windowManagerLogsDir = `${testRunsLogsDir}windowManager/`;

export const mailsacAPIKey = process.env.MAILSAC_API_KEY;
export const mailsacEmail = '[email protected]';
Expand Down
41 changes: 8 additions & 33 deletions packages/yoroi-extension/features/support/webdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@ import chrome from 'selenium-webdriver/chrome';
import firefox from 'selenium-webdriver/firefox';
import path from 'path';
import { RustModule } from '../../app/api/ada/lib/cardanoCrypto/rustLoader';
import { getMethod, getLogDate } from './helpers/helpers';
import { WindowManager } from './windowManager';
import { MockDAppWebpage } from '../mock-dApp-webpage';
import { testRunsDataDir } from './helpers/common-constants';
import { getMethod } from './helpers/helpers';
import { WebDriverError } from 'selenium-webdriver/lib/error';
import * as helpers from './helpers/helpers';

const fs = require('fs');
const simpleNodeLogger = require('simple-node-logger');

function encode(file) {
return fs.readFileSync(file, { encoding: 'base64' });
Expand Down Expand Up @@ -136,31 +132,12 @@ function CustomWorld(cmdInput: WorldInput) {

this._allLoggers = [];

const logsDir = `${testRunsDataDir}${this.getBrowser()}/Logs/`

const mockAndWMLogDir = `${logsDir}mockAndWMLogs`;
if (!fs.existsSync(mockAndWMLogDir)) {
fs.mkdirSync(mockAndWMLogDir, { recursive: true });
}
const mockAndWMLogPath = `${mockAndWMLogDir}/mockAndWMLog_${getLogDate()}.log`;
const mockAndWMLogger = simpleNodeLogger.createSimpleFileLogger(mockAndWMLogPath);
this.windowManager = new WindowManager(this.driver, mockAndWMLogger);
this.windowManager.init().then().catch();
this._allLoggers.push(mockAndWMLogger);
this.mockDAppPage = new MockDAppWebpage(this.driver, mockAndWMLogger);

const webDriverLogDir = `${logsDir}webDriverLogs`;
if (!fs.existsSync(webDriverLogDir)) {
fs.mkdirSync(webDriverLogDir, { recursive: true });
}
const webDriverLogPath = `${webDriverLogDir}/webDriverLog_${getLogDate()}.log`;
this.webDriverLogger = simpleNodeLogger.createSimpleFileLogger(webDriverLogPath);
this._allLoggers.push(this.webDriverLogger);

const trezorEmuLogPath = `${logsDir}trezorEmulatorController_${getLogDate()}.log`;
this.trezorEmuLogger = simpleNodeLogger.createSimpleFileLogger(trezorEmuLogPath);
this.trezorController = undefined;

this.addToLoggers = (logger: any) => {
this._allLoggers.push(logger);
} ;

this.sendToAllLoggers = (message: string, level: string = 'info') => {
for (const someLogger of this._allLoggers) {
someLogger[level](message);
Expand Down Expand Up @@ -202,7 +179,7 @@ function CustomWorld(cmdInput: WorldInput) {

this.getText = (locator: LocatorObject) => this.getElementBy(locator).getText();

this.getValue = this.driver.getValue = async (locator: LocatorObject) =>
this.getValue = async (locator: LocatorObject) =>
this.getElementBy(locator).getAttribute('value');

this.waitForElementLocated = async (locator: LocatorObject) => {
Expand All @@ -212,7 +189,7 @@ function CustomWorld(cmdInput: WorldInput) {
};

// Returns a promise that resolves to the element
this.waitForElement = this.driver.waitForElement = async (locator: LocatorObject) => {
this.waitForElement = async (locator: LocatorObject) => {
this.webDriverLogger.info(`Webdriver: Waiting for element "${JSON.stringify(locator)}" to be visible`);
await this.waitForElementLocated(locator);
const element = await this.getElementBy(locator);
Expand All @@ -229,9 +206,7 @@ function CustomWorld(cmdInput: WorldInput) {
return element;
};

this.waitForElementNotPresent = this.driver.waitForElementNotPresent = async (
locator: LocatorObject
) => {
this.waitForElementNotPresent = async (locator: LocatorObject) => {
this.webDriverLogger.info(`Webdriver: Waiting for element "${JSON.stringify(locator)}" not present`);
await this.driver.wait(async () => {
const elements = await this.getElementsBy(locator);
Expand Down