const section = (name, testFunc) => { console.log('\x1b[44m%s\x1b[0m', name); testFunc(); }; const subSection = name => console.log('\x1b[33m%s\x1b[0m', ' - ' + name); /* global fixture:true */ /* eslint babel/new-cap: 0 */ const page = new Page(); const adminUrl = 'http://127.0.0.1:8081/neos!'; const adminUser = Role(adminUrl, async t => { await t .typeText('#username', 'admin') .typeText('#password', 'password') .click('button.neos-login-btn'); }, {preserveUrl: true}); fixture `Content Module` .beforeEach(async t => { await t.useRole(adminUser); }); test('All tests at once', async t => { section('Discarding: create a document node and then discard it', async () => { const pageTitleToCreate = 'DiscardTest'; subSection('Create a document node'); await t .click(ReactSelector('AddNode Button')) .click(ReactSelector('NodeTypeItem'))
import { noop } from 'lodash'; import { Role, t } from 'testcafe'; const roleWithInitErr = Role('http://localhost:3000/fixtures/api/es-next/roles/pages/login-page.html', () => { throw new Error('Hey!'); }); fixture `Errors` .page `http://localhost:3000/fixtures/api/es-next/roles/pages/index.html`; test('Test1', async () => { await t.useRole(roleWithInitErr); }); test('Test2', noop); test('Test3', async () => { await t.useRole(roleWithInitErr); });
import { Role, Selector, t } from 'testcafe'; const userName = Selector('#user-name'); const localStorageToken = Selector('#local-storage-token'); const someUser = Role('http://localhost:3000/fixtures/api/es-next/roles/pages/login-page.html', async () => { await t .typeText('input[name="name"]', 'SomeUser') .click('input[value="LogIn"]'); }); fixture `AnonymousRole` .page `http://localhost:3000/fixtures/api/es-next/roles/pages/index.html`; test('Test1', async () => { await t .useRole(someUser) .expect(userName.textContent).eql('SomeUser') .expect(localStorageToken.textContent).eql('123456789SomeUser') .useRole(Role.anonymous()) .expect(userName.textContent).eql('') .expect(localStorageToken.textContent).eql(''); });
import { Role } from 'testcafe'; let initialized = false; const userRole = Role('http://localhost:3000/fixtures/regression/gh-2015/pages/logon.html', async t => { if (initialized) throw new Error('Role is already initialized'); initialized = true; await t .click('#setAuthToken') .click('#redirectAfterLogin'); }, { preserveUrl: true }); export default userRole;
import { Role, Selector, t } from 'testcafe'; let role1Executions = 0; let role2Executions = 0; const userName = Selector('#user-name'); const token = Selector('#token'); const localStorageToken = Selector('#local-storage-token'); const sessionStorageToken = Selector('#session-storage-token'); const role1 = Role('http://localhost:3000/fixtures/api/es-next/roles/pages/login-page.html', async () => { await t .typeText('input[name="name"]', 'User1') .click('input[value="LogIn"]'); role1Executions++; }); const role2 = Role('http://localhost:3000/fixtures/api/es-next/roles/pages/login-page.html', async () => { await t .typeText('input[name="name"]', 'User2') .click('input[value="LogIn"]'); role2Executions++; }); async function setToken (tokenValue) { await t .typeText('input[name="token"]', tokenValue) .click('input[value="SetToken"]'); }
import { Role } from 'testcafe'; fixture `Test`; Role(123, () => {}); test('yo', () => { });