TestCafe: Generate Tests using Data from the Client?
up vote
0
down vote
favorite
Using TestCafe [1], I would like to do the following:
- Navigate to a URL.
- Execute Client-Side JavaScript to retrieve a list of other URLs.
- Generate a test for each URL.
- Execute the tests concurrently.
Working example which uses a single Test and executes serially
The reduced test case below works but is not quite what I need, it does the following:
- Execute a test.
- Navigate to a URL in the "before" hook of the test.
- Execute Client-Side JavaScript to retrieve a list of URLs in the "before" hook of the test.
- Run the assertions for each URL serially in the body of the test.
My test file run through TestCafe contains this:
import { ClientFunction, Selector } from 'testcafe';
const getSiteMapFromClientSide = ClientFunction(
() =>
new Promise(resolve => {
// this example looks like it could be synchronous, or that the data could
// be defined in the test but this data comes from an async source which
// is only reachable client side.
resolve(['https://localhost:6007/some/url1', 'https://localhost:6007/some/url2']);
})
);
fixture('Storybook').page('https://localhost:6007');
const modalError = Selector('#error-message');
test.before(async t => {
t.ctx.siteMap = await getSiteMapFromClientSide();
})('Smoke Test all Stories for Full Screen Errors or Blank Screens', async t => {
// assert we have URLs or we'll have a passing suite that looped over nothing
await t.expect(t.ctx.siteMap.length > 0).ok('Site Map is Empty');
// assert each story has no full screen error message
await Promise.all(
t.ctx.allStories.map(async url => {
await t
.navigateTo(url)
.expect(modalError.exists && modalError.visible)
.notOk(`Full Screen Error found at ${url}`);
})
);
});
Context
In the real application, I am writing smoke tests for Storybook [2]. To get a list of all URLs I need to call the result
of require('@storybook/react').getStorybook()
, which is only available in the Storybook Client Application at runtime.
I've left these details out of the reduced test case as they're nothing to with TestCafe.
[1] http://devexpress.github.io/testcafe
[2] https://storybook.js.org
automated-tests e2e-testing testcafe storybook
add a comment |
up vote
0
down vote
favorite
Using TestCafe [1], I would like to do the following:
- Navigate to a URL.
- Execute Client-Side JavaScript to retrieve a list of other URLs.
- Generate a test for each URL.
- Execute the tests concurrently.
Working example which uses a single Test and executes serially
The reduced test case below works but is not quite what I need, it does the following:
- Execute a test.
- Navigate to a URL in the "before" hook of the test.
- Execute Client-Side JavaScript to retrieve a list of URLs in the "before" hook of the test.
- Run the assertions for each URL serially in the body of the test.
My test file run through TestCafe contains this:
import { ClientFunction, Selector } from 'testcafe';
const getSiteMapFromClientSide = ClientFunction(
() =>
new Promise(resolve => {
// this example looks like it could be synchronous, or that the data could
// be defined in the test but this data comes from an async source which
// is only reachable client side.
resolve(['https://localhost:6007/some/url1', 'https://localhost:6007/some/url2']);
})
);
fixture('Storybook').page('https://localhost:6007');
const modalError = Selector('#error-message');
test.before(async t => {
t.ctx.siteMap = await getSiteMapFromClientSide();
})('Smoke Test all Stories for Full Screen Errors or Blank Screens', async t => {
// assert we have URLs or we'll have a passing suite that looped over nothing
await t.expect(t.ctx.siteMap.length > 0).ok('Site Map is Empty');
// assert each story has no full screen error message
await Promise.all(
t.ctx.allStories.map(async url => {
await t
.navigateTo(url)
.expect(modalError.exists && modalError.visible)
.notOk(`Full Screen Error found at ${url}`);
})
);
});
Context
In the real application, I am writing smoke tests for Storybook [2]. To get a list of all URLs I need to call the result
of require('@storybook/react').getStorybook()
, which is only available in the Storybook Client Application at runtime.
I've left these details out of the reduced test case as they're nothing to with TestCafe.
[1] http://devexpress.github.io/testcafe
[2] https://storybook.js.org
automated-tests e2e-testing testcafe storybook
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Using TestCafe [1], I would like to do the following:
- Navigate to a URL.
- Execute Client-Side JavaScript to retrieve a list of other URLs.
- Generate a test for each URL.
- Execute the tests concurrently.
Working example which uses a single Test and executes serially
The reduced test case below works but is not quite what I need, it does the following:
- Execute a test.
- Navigate to a URL in the "before" hook of the test.
- Execute Client-Side JavaScript to retrieve a list of URLs in the "before" hook of the test.
- Run the assertions for each URL serially in the body of the test.
My test file run through TestCafe contains this:
import { ClientFunction, Selector } from 'testcafe';
const getSiteMapFromClientSide = ClientFunction(
() =>
new Promise(resolve => {
// this example looks like it could be synchronous, or that the data could
// be defined in the test but this data comes from an async source which
// is only reachable client side.
resolve(['https://localhost:6007/some/url1', 'https://localhost:6007/some/url2']);
})
);
fixture('Storybook').page('https://localhost:6007');
const modalError = Selector('#error-message');
test.before(async t => {
t.ctx.siteMap = await getSiteMapFromClientSide();
})('Smoke Test all Stories for Full Screen Errors or Blank Screens', async t => {
// assert we have URLs or we'll have a passing suite that looped over nothing
await t.expect(t.ctx.siteMap.length > 0).ok('Site Map is Empty');
// assert each story has no full screen error message
await Promise.all(
t.ctx.allStories.map(async url => {
await t
.navigateTo(url)
.expect(modalError.exists && modalError.visible)
.notOk(`Full Screen Error found at ${url}`);
})
);
});
Context
In the real application, I am writing smoke tests for Storybook [2]. To get a list of all URLs I need to call the result
of require('@storybook/react').getStorybook()
, which is only available in the Storybook Client Application at runtime.
I've left these details out of the reduced test case as they're nothing to with TestCafe.
[1] http://devexpress.github.io/testcafe
[2] https://storybook.js.org
automated-tests e2e-testing testcafe storybook
Using TestCafe [1], I would like to do the following:
- Navigate to a URL.
- Execute Client-Side JavaScript to retrieve a list of other URLs.
- Generate a test for each URL.
- Execute the tests concurrently.
Working example which uses a single Test and executes serially
The reduced test case below works but is not quite what I need, it does the following:
- Execute a test.
- Navigate to a URL in the "before" hook of the test.
- Execute Client-Side JavaScript to retrieve a list of URLs in the "before" hook of the test.
- Run the assertions for each URL serially in the body of the test.
My test file run through TestCafe contains this:
import { ClientFunction, Selector } from 'testcafe';
const getSiteMapFromClientSide = ClientFunction(
() =>
new Promise(resolve => {
// this example looks like it could be synchronous, or that the data could
// be defined in the test but this data comes from an async source which
// is only reachable client side.
resolve(['https://localhost:6007/some/url1', 'https://localhost:6007/some/url2']);
})
);
fixture('Storybook').page('https://localhost:6007');
const modalError = Selector('#error-message');
test.before(async t => {
t.ctx.siteMap = await getSiteMapFromClientSide();
})('Smoke Test all Stories for Full Screen Errors or Blank Screens', async t => {
// assert we have URLs or we'll have a passing suite that looped over nothing
await t.expect(t.ctx.siteMap.length > 0).ok('Site Map is Empty');
// assert each story has no full screen error message
await Promise.all(
t.ctx.allStories.map(async url => {
await t
.navigateTo(url)
.expect(modalError.exists && modalError.visible)
.notOk(`Full Screen Error found at ${url}`);
})
);
});
Context
In the real application, I am writing smoke tests for Storybook [2]. To get a list of all URLs I need to call the result
of require('@storybook/react').getStorybook()
, which is only available in the Storybook Client Application at runtime.
I've left these details out of the reduced test case as they're nothing to with TestCafe.
[1] http://devexpress.github.io/testcafe
[2] https://storybook.js.org
automated-tests e2e-testing testcafe storybook
automated-tests e2e-testing testcafe storybook
edited Nov 8 at 11:17
Alex Skorkin
2,0121430
2,0121430
asked Nov 8 at 9:59
Jamie Mason
2,27411631
2,27411631
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
I think it's better to divide your task into two parts.
First, you need to get all tested URLs via ClientFunction and save these URLs somewhere (e.g., to a global variable) using the first test file.
Then start a new TestCafe task with the concurrency
option and set the src
param to your second test file.
The best way to do it is to use the createTestCafe
function. Please also read the following article http://devexpress.github.io/testcafe/documentation/using-testcafe/programming-interface/createtestcafe.html
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
I think it's better to divide your task into two parts.
First, you need to get all tested URLs via ClientFunction and save these URLs somewhere (e.g., to a global variable) using the first test file.
Then start a new TestCafe task with the concurrency
option and set the src
param to your second test file.
The best way to do it is to use the createTestCafe
function. Please also read the following article http://devexpress.github.io/testcafe/documentation/using-testcafe/programming-interface/createtestcafe.html
add a comment |
up vote
1
down vote
I think it's better to divide your task into two parts.
First, you need to get all tested URLs via ClientFunction and save these URLs somewhere (e.g., to a global variable) using the first test file.
Then start a new TestCafe task with the concurrency
option and set the src
param to your second test file.
The best way to do it is to use the createTestCafe
function. Please also read the following article http://devexpress.github.io/testcafe/documentation/using-testcafe/programming-interface/createtestcafe.html
add a comment |
up vote
1
down vote
up vote
1
down vote
I think it's better to divide your task into two parts.
First, you need to get all tested URLs via ClientFunction and save these URLs somewhere (e.g., to a global variable) using the first test file.
Then start a new TestCafe task with the concurrency
option and set the src
param to your second test file.
The best way to do it is to use the createTestCafe
function. Please also read the following article http://devexpress.github.io/testcafe/documentation/using-testcafe/programming-interface/createtestcafe.html
I think it's better to divide your task into two parts.
First, you need to get all tested URLs via ClientFunction and save these URLs somewhere (e.g., to a global variable) using the first test file.
Then start a new TestCafe task with the concurrency
option and set the src
param to your second test file.
The best way to do it is to use the createTestCafe
function. Please also read the following article http://devexpress.github.io/testcafe/documentation/using-testcafe/programming-interface/createtestcafe.html
answered yesterday
Alex Kamaev
2664
2664
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53205332%2ftestcafe-generate-tests-using-data-from-the-client%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password