-
Notifications
You must be signed in to change notification settings - Fork 677
[docs] GS added #534
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
[docs] GS added #534
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| --- | ||
| layout: docs | ||
| title: Getting Started | ||
| permalink: /documentation/getting-started/ | ||
| --- | ||
| # Getting Started | ||
|
|
||
| This guide provides step-by-step instructions on how to create a functional web test with TestCafe and contains the following sections. | ||
|
|
||
| * [Installing TestCafe](#installing-testcafe) | ||
| * [Creating a Test](#creating-a-test) | ||
| * [Running the Test](#running-the-test) | ||
| * [Viewing the Test Results](#viewing-the-test-results) | ||
| * [Writing Test Code](#writing-test-code) | ||
| * [Performing Actions on the Page](#performing-actions-on-the-page) | ||
| * [Observing the Page State](#observing-the-page-state) | ||
| * [Assertions](#assertions) | ||
|
|
||
| ## Installing TestCafe | ||
|
|
||
| Make sure that [Node.js](https://nodejs.org/) and [npm](https://www.npmjs.com/) are installed on your computer, then run a single command: | ||
|
|
||
| ```bash | ||
| npm install -g testcafe | ||
| ``` | ||
|
|
||
| ## Creating a Test | ||
|
|
||
| To create a test, create a new .js file anywhere on your computer. | ||
| This file must have the special structure: tests must be organized into fixtures. So, first you need to declare a fixture by using the [fixture](../test-api/test-code-structure.md#fixtures) function. | ||
|
|
||
| ```js | ||
| fixture `Getting Started` | ||
| ``` | ||
|
|
||
| In this tutorial, you will create a test for the [http://testcafe.devexpress.com/example](http://testcafe.devexpress.com/example) sample page. | ||
| Specify this page as a start page for the fixture by using the [page](../test-api/test-code-structure.md#specifying-the-start-webpage) function. | ||
|
|
||
| ```js | ||
| fixture `Getting Started` | ||
| .page('http://testcafe.devexpress.com/example'); | ||
| ``` | ||
|
|
||
| Then create the [test](/test-api/test-code-structure.md#tests) function where you will further place test code. | ||
|
|
||
| ```js | ||
| fixture `Getting Started` | ||
| .page('http://testcafe.devexpress.com/example'); | ||
|
|
||
| test('Test1', async t => { | ||
| // Test code | ||
| }); | ||
| ``` | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's always a little bit weird when we describe several steps of writing code in words with no examples in the middle.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a third option: describe code structure using comments in code
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have used the first way - growing step-by-step
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For this particular example I don't think that growing step-by-step is a good approach. It's quite minimal and describes code organzation for tests, so it preferable to be observed all at once.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think any other way will look better and more clear than step-by-step
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can I have a look at step-by-step version?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also like the current variant (with growing step-by-step). I don't want to use comments to describe this code, because comments will litter the test's clear structure. Also, it's not good idea to describe all the test elements below the code - too much info at once.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Step-by-step version is already commited
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, got it. Let's keep it as is. |
||
|
|
||
| ## Running the Test | ||
|
|
||
| You can simply run the test from a command shell, by calling a single command where you specify the [target browser](../using-testcafe/command-line-interface.md#browser-list) and [file path](../using-testcafe/command-line-interface.md#file-pathglob-pattern). | ||
|
|
||
| ```bash | ||
| testcafe safari test1.js | ||
| ``` | ||
|
|
||
| TestCafe will automatically open the chosen browser and start the test execution within it. | ||
|
|
||
| For more information on how to configure the test run, see [Command Line Interface](../using-testcafe/command-line-interface.md). | ||
|
|
||
| ## Viewing the Test Results | ||
|
|
||
| While the test is running, TestCafe is gathering information about the test run and outputing the report right into a command shell. | ||
|
|
||
|  | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it OK that we have @MargaritaLoseva credentials in example or it's better create
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For some time, we consider it ok to show our names on screenshots... But this particular image... Oh, there's too much of MargaritaLoseva in it. I feel like it grabs attention.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, I would create a TestUser |
||
|
|
||
| For more information, see [Reporters](../using-testcafe/common-concepts/reporters.md). | ||
|
|
||
| ## Writing Test Code | ||
|
|
||
| ### Performing Actions on the Page | ||
|
|
||
| Every test should be capable of interacting with a page content. To perform user actions, TestCafe provides a number of [actions](../test-api/actions.md): `click`, `hover`, `typeText`, `setFilesToUpload`, etc. | ||
| They can be called in a chain. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| The following fixture contains a simple test that types a developer name into a text editor and then clicks the Submit button. | ||
|
|
||
| ```js | ||
| fixture `Getting Started` | ||
| .page('http://testcafe.devexpress.com/example'); | ||
|
|
||
| test('Test1', async t => { | ||
| await t | ||
| .typeText('#developer-name', 'John Smith') | ||
| .click('#submit-button'); | ||
| }); | ||
| ``` | ||
|
|
||
| All test actions are implemented as async functions of the [test controller object](../test-api/test-code-structure.md#test-controller) `t`. This object is used to access test run API. | ||
| To wait for actions to be complete, use the `await` keyword when calling these actions or action chains. | ||
|
|
||
| ### Observing Page State | ||
|
|
||
| TestCafe allows you to observe the page state. | ||
| For this purpose, it offers special kinds of functions that will execute your code on the client: [Selector](../test-api/executing-client-code/index.md#selector-functions) used to get direct access to DOM elements | ||
| and [ClientFunction](test-api/executing-client-code/index.md#client-functions) used to obtain arbitrary data from the client side. | ||
| You call these functions as regular async functions, that is you can obtain their results and use parameters to pass data to them. | ||
|
|
||
| For example, clicking the Submit button on the sample web page opens a "Thank you" page. | ||
| To get access to DOM elements on the opened page, the `Selector` function can be used. | ||
| The following example demonstrates how to access the article header element and obtain its actual text. | ||
|
|
||
| ```js | ||
| import { Selector } from 'testcafe'; | ||
|
|
||
| // Declare the parameterized Selector function | ||
| // to get access to a DOM element identified by the `id` attribute | ||
| const getElementById = Selector(id => document.querySelector(`#${id}`)); | ||
|
|
||
| fixture `Getting Started` | ||
| .page('http://testcafe.devexpress.com/example'); | ||
|
|
||
| test('Test1', async t => { | ||
| await t | ||
| .typeText('#developer-name', 'John Smith') | ||
| .click('#submit-button'); | ||
|
|
||
| // Use the Selector function to get access to the article header | ||
| const articleHeader = await getElementById('article-header'); | ||
|
|
||
| // Obtain the text of the article header | ||
| const headerText = articleHeader.innerText; | ||
| }); | ||
| ``` | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to show how declared hybrid function is used in this example |
||
|
|
||
| For more information, see [Executing Client Code](../test-api/executing-client-code.md). | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BTW, I think we should rename
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| ### Assertions | ||
|
|
||
| A functional test also should check the result of actions performed. | ||
| For example, the article header on the "Thank you" page should address a user by the entered name. | ||
| To check if the header is correct, you have to add an assertion to the test. | ||
|
|
||
| You can use assertions from Node's built-in [assert](https://nodejs.org/api/assert.html) module or from any third-party assertion library. | ||
| Before calling assertions, make sure an assertion library is installed into your project. | ||
|
|
||
| The following test demonstrates how to use an assertion from [Chai Assertion Library](http://chaijs.com/api/bdd/). | ||
| Before running the test, install the assertion library by calling the `npm install -g chai` command. | ||
|
|
||
| ```js | ||
| import { expect } from 'chai'; | ||
| import { Selector } from 'testcafe'; | ||
|
|
||
| // Declare the parameterized hybrid function | ||
| // to obtain text content of an element identified by the `id` attribute | ||
| const getElementById = Selector(id => document.querySelector(`#${id}`)); | ||
|
|
||
| fixture `Getting Started` | ||
| .page('http://testcafe.devexpress.com/example'); | ||
|
|
||
| test('Test1', async t => { | ||
| await t | ||
| .typeText('#developer-name', 'John Smith') | ||
| .click('#submit-button'); | ||
|
|
||
| // Use the Selector function to get access to the article header | ||
| const articleHeader = await getElementById('article-header'); | ||
|
|
||
| // Use the assertion to check if the actual header text is equal to the expected one | ||
| expect(articleHeader.innerText).to.equal('Thank you, John Smith!'); | ||
| }); | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| - item: GETTING STARTED | ||
| url: . | ||
| url: /testcafe/documentation/getting-started/ | ||
| - folder: TEST API | ||
| url: . | ||
| content: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Get rid of
website projecttermThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also it's worth mention that you can put test file anywhere and pass their path to testcafe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't understand this comment. worth or worse mention??