From d1b819652731b4b1e2b67040fbc7e4b0920a8811 Mon Sep 17 00:00:00 2001 From: miherlosev Date: Thu, 26 Sep 2019 15:21:35 +0300 Subject: [PATCH] add examples --- .editorconfig | 15 +++++++++++++++ .gitattributes | 10 ++++++++++ .gitignore | 6 ++++++ package.json | 17 +++++++++++++++++ ...nject-node-module-as-custom-client-script.js | 10 ++++++++++ tests/inspect-element-markup.js | 14 ++++++++++++++ tests/reload-page.js | 14 ++++++++++++++ 7 files changed, 86 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 package.json create mode 100644 tests/inject-node-module-as-custom-client-script.js create mode 100644 tests/inspect-element-markup.js create mode 100644 tests/reload-page.js diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..de6b8b3 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +# This file is for unifying the coding style for different editors and IDEs +# editorconfig.org + +root = true + +[*] +end_of_line = lf +charset = utf-8 +insert_final_newline = true +trim_trailing_whitespace = true +indent_style = space +indent_size = 4 + +[{package.json,.eslintrc,.babelrc,.travis.yml}] +indent_size = 2 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..8901f67 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,10 @@ +* text=auto +*.sh text eol=lf +*.js text eol=lf +*.ts text eol=lf +*.css text eol=lf +*.html text eol=lf +*.md text eol=lf + +*.png binary +*.ico binary diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d22f009 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +/node_modules +.idea +.vscode +yarn.lock +package-lock.json +.npmrc diff --git a/package.json b/package.json new file mode 100644 index 0000000..a262c16 --- /dev/null +++ b/package.json @@ -0,0 +1,17 @@ +{ + "name": "testcafe-examples", + "version": "0.0.1", + "author": { + "name": "Developer Express Inc.", + "url": "https://www.devexpress.com/" + }, + "description": "This repository contains sample test files that help you learn how to use TestCafe.", + "license": "MIT", + "dependencies": { + "lodash": "^4.17.15", + "testcafe": "^1.5.0" + }, + "scripts": { + "test": "testcafe chrome tests" + } +} diff --git a/tests/inject-node-module-as-custom-client-script.js b/tests/inject-node-module-as-custom-client-script.js new file mode 100644 index 0000000..bc30f7c --- /dev/null +++ b/tests/inject-node-module-as-custom-client-script.js @@ -0,0 +1,10 @@ +import { ClientFunction } from 'testcafe'; + +fixture `Fixture` + .clientScripts({ module: 'lodash'}); + +test('Inject module as a custom client script', async t => { + const result = await t.eval(() => _.defaults({ 'a': 1 }, { 'a': 3, 'b': 2 })); + + await t.expect(result).eql({ a: 1, b: 2 }); +}); diff --git a/tests/inspect-element-markup.js b/tests/inspect-element-markup.js new file mode 100644 index 0000000..bc8ccda --- /dev/null +++ b/tests/inspect-element-markup.js @@ -0,0 +1,14 @@ +import { Selector } from 'testcafe'; + +fixture `Fixture` + .page('https://devexpress.github.io/testcafe/example/'); + +test('How to inspect an element markup', async t => { + const selector = Selector('label[for]').addCustomDOMProperties({ + outerHTML: el => el.outerHTML + }); + + const elementOuterHTML = await selector().outerHTML; + + await t.expect(elementOuterHTML).eql(''); +}); diff --git a/tests/reload-page.js b/tests/reload-page.js new file mode 100644 index 0000000..dbf758e --- /dev/null +++ b/tests/reload-page.js @@ -0,0 +1,14 @@ +import { Selector } from 'testcafe'; + +fixture `Fixture` + .page('https://devexpress.github.io/testcafe/example/'); + +test('How to reload the tested page', async t => { + await t.typeText('#developer-name', 'Peter Parker'); + + await t.eval(() => location.reload(true)); + + await t + .wait(3000) + .expect(Selector('#developer-name').value).eql(''); +});