Skip to content

Commit

Permalink
test: use github actions to test safari (closes #7322)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreyBelym committed Nov 17, 2022
1 parent d230569 commit a927d30
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/deploy-to-artifacts.yml
Expand Up @@ -173,6 +173,8 @@ jobs:
tasks.push('test-functional-local-proxyless.yml');
tasks.push('test-functional-local-legacy.yml');
tasks.push('test-functional-local-safari.yml');
tasks.push('test-functional-remote-macos.yml');
tasks.push('test-functional-remote-mobile.yml');
Expand Down
103 changes: 103 additions & 0 deletions .github/workflows/test-functional-local-safari.yml
@@ -0,0 +1,103 @@
name: Test Functional (Local Safari)

on:
workflow_dispatch:
inputs:
sha:
description: 'The test commit SHA or ref'
required: true
default: 'master'
merged_sha:
description: 'The merge commit SHA'
deploy_run_id:
description: 'The ID of a deployment workspace run with artifacts'
jobs:
test:
runs-on: macos-12
environment: test-functional
env:
RETRY_FAILED_TESTS: true
steps:
- run: sudo safaridriver --enable
- uses: actions/github-script@v3
with:
script: |
await github.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: context.payload.inputs.sha,
context: context.workflow,
state: 'pending',
target_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`
});
- uses: actions/checkout@v2
with:
ref: ${{github.event.inputs.merged_sha || github.event.inputs.sha}}

- uses: actions/setup-node@v2
with:
node-version: 14

- uses: actions/github-script@v3
with:
script: |
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
let artifacts = {};
for(let i = 0;i<36&&!artifacts.total_count;i++,await delay(5000)) {
try {
({ data: artifacts } = await github.actions.listWorkflowRunArtifacts({
repo: context.repo.repo,
owner: context.repo.owner,
run_id: context.payload.inputs.deploy_run_id
}));
}
catch (e) {
console.log(e);
}
}
const { data: artifact } = await github.request(artifacts.artifacts.find(artifact=> artifact.name === 'npm').archive_download_url);
require('fs').writeFileSync(require('path').join(process.env.GITHUB_WORKSPACE, 'package.zip'), Buffer.from(artifact))
- run: |
unzip package.zip
tar --strip-components=1 -xzf testcafe-*.tgz
- name: Get npm cache directory
id: npm-cache-dir
run: |
echo "::set-output name=dir::$(npm config get cache)"
- uses: actions/cache@v2
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- run: npm ci
- run: npx gulp test-functional-local-safari-run --steps-as-tasks
timeout-minutes: 60
- uses: actions/github-script@v3
with:
script: |
await github.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: context.payload.inputs.sha,
context: context.workflow,
state: 'success',
target_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`
});
- uses: actions/github-script@v3
if: failure() || cancelled()
with:
script: |
await github.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: context.payload.inputs.sha,
context: context.workflow,
state: 'failure',
target_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`
});
6 changes: 6 additions & 0 deletions Gulpfile.js
Expand Up @@ -388,6 +388,12 @@ gulp.step('test-functional-local-headless-firefox-run', () => {

gulp.task('test-functional-local-headless-firefox', gulp.series('prepare-tests', 'test-functional-local-headless-firefox-run'));

gulp.step('test-functional-local-safari-run', () => {
return testFunctional(TESTS_GLOB, functionalTestConfig.testingEnvironmentNames.localSafari);
});

gulp.task('test-functional-local-safari', gulp.series('prepare-tests', 'test-functional-local-safari-run'));

gulp.step('test-functional-remote-run', () => {
if (QR_CODE)
process.env.QR_CODE = 'true';
Expand Down
21 changes: 17 additions & 4 deletions test/functional/config.js
Expand Up @@ -4,6 +4,7 @@ const browserProviderNames = {
sauceLabs: 'sauceLabs',
browserstack: 'browserstack',
remote: 'remote',
safari: 'safari',
};

const testingEnvironmentNames = {
Expand All @@ -13,6 +14,7 @@ const testingEnvironmentNames = {
localBrowsersChromeFirefox: 'local-browsers-chrome-firefox',
localBrowsers: 'local-browsers',
localChrome: 'local-chrome',
localSafari: 'local-safari',
localHeadlessChrome: 'local-headless-chrome',
localHeadlessFirefox: 'local-headless-firefox',
remote: 'remote',
Expand All @@ -31,10 +33,6 @@ testingEnvironments[testingEnvironmentNames.osXDesktopAndMSEdgeBrowsers] = {
},

browsers: [
{
browserName: 'browserstack:safari',
alias: 'safari',
},
{
browserName: 'browserstack:edge:OS X Monterey',
alias: 'edge',
Expand Down Expand Up @@ -144,6 +142,21 @@ testingEnvironments[testingEnvironmentNames.localHeadlessChrome] = {
],
};

testingEnvironments[testingEnvironmentNames.localSafari] = {
remote: true,
provider: browserProviderNames.safari,

safari: {},

browsers: [
{
browserName: 'safari',
userAgent: 'safari',
alias: 'safari',
},
],
};

testingEnvironments[testingEnvironmentNames.localHeadlessFirefox] = {
isLocalBrowsers: true,
isHeadlessBrowsers: true,
Expand Down
2 changes: 1 addition & 1 deletion test/functional/fixtures/regression/gh-845/test.js
@@ -1,7 +1,7 @@
// NOTE: we skip 'iphone,ipad' because no way to download file by link on these devices
describe('[Regression](GH-845) Should execute click on a download link', function () {
it('gh-845', function () {
return runTests('testcafe-fixtures/index-test.js', 'Click on a download link', { skip: ['iphone', 'ipad', 'android'] });
return runTests('testcafe-fixtures/index-test.js', 'Click on a download link', { skip: ['iphone', 'ipad', 'android', 'safari'] });
});

it('gh-845 in iframe', function () {
Expand Down
5 changes: 3 additions & 2 deletions test/functional/fixtures/reporter/test.js
Expand Up @@ -18,7 +18,7 @@ const del = require('del');

const experimentalDebug = !!process.env.EXPERIMENTAL_DEBUG;

describe('Reporter', () => {
(config.hasBrowser('chrome') ? describe : describe.skip)('Reporter', () => {
const stdoutWrite = process.stdout.write;
const stderrWrite = process.stderr.write;

Expand Down Expand Up @@ -1198,7 +1198,8 @@ describe('Reporter', () => {
}
});

it('Should work with option from configuration file', () => {
it('Should work with option from configuration file', function () {

return runTestsWithConfig('Simple test', './test/functional/fixtures/reporter/configs/xunit-config.js')
.then(() => {
const pathReport = path.resolve(__dirname, 'report.xml');
Expand Down
2 changes: 1 addition & 1 deletion test/functional/fixtures/ui/test.js
Expand Up @@ -4,6 +4,6 @@ describe('TestCafe UI', () => {
});

it('Hide elements when resizing the window', () => {
return runTests('./testcafe-fixtures/status-bar-test.js', 'Hide elements when resizing the window', { skip: ['android', 'ipad', 'iphone', 'edge'] });
return runTests('./testcafe-fixtures/status-bar-test.js', 'Hide elements when resizing the window', { skip: ['android', 'ipad', 'iphone', 'edge', 'safari'] });
});
});
29 changes: 29 additions & 0 deletions test/functional/safari-connector.js
@@ -0,0 +1,29 @@
const { exec } = require('child_process');
const debug = require('debug');


const DEBUG = debug('testcafe:test:functional:safari-connector');

module.exports = class SafariConnector {
connect () {
return Promise.resolve();
}

waitForFreeMachines () {
return Promise.resolve();
}

startBrowser (settings, url) {
exec(`open -a /Applications/Safari.app ${url}`, (...args) => DEBUG(args));

return Promise.resolve();
}

stopBrowser () {
return Promise.resolve();
}

disconnect () {
return Promise.resolve();
}
};
2 changes: 2 additions & 0 deletions test/functional/setup.js
Expand Up @@ -9,6 +9,7 @@ const BrowserConnection = require('../../lib/browser/connection');
const config = require('./config.js');
const site = require('./site');
const RemoteConnector = require('./remote-connector');
const SafariConnector = require('./safari-connector');
const getTestError = require('./get-test-error.js');
const { createSimpleTestStream } = require('./utils/stream');
const BrowserConnectionStatus = require('../../lib/browser/connection/status');
Expand Down Expand Up @@ -40,6 +41,7 @@ const REMOTE_CONNECTORS_MAP = {
[config.browserProviderNames.browserstack]: BsConnector,
[config.browserProviderNames.sauceLabs]: SlConnector,
[config.browserProviderNames.remote]: RemoteConnector,
[config.browserProviderNames.safari]: SafariConnector,
};

const USE_PROVIDER_POOL = config.useLocalBrowsers || isBrowserStack;
Expand Down

0 comments on commit a927d30

Please sign in to comment.