Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
///
import { Role, Selector, t } from 'testcafe';
const userName = Selector('#user-name');
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"]');
}, { preserveUrl: false });
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')
.useRole(Role.anonymous())
.expect(userName.textContent).eql('');
});
import { Role, Selector, t } from 'testcafe';
// $ExpectError - string as Selector
Selector(123)
const userName = Selector('#user-name');
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')
.useRole(Role.anonymous())
.expect(userName.textContent).eql('');
})
import { Role } from 'testcafe';
import setup from './setup';
const user = 'normal';
const pass = 'zhu88jie';
const normalRole = Role(setup.getPageUrl('login'), async t => {
await t
.typeText('input[name=username]', user)
.typeText('input[name=password]', pass)
.click('button[type=submit]');
});
// workaround
// https://testcafe-discuss.devexpress.com/t/running-multiple-tests-on-already-authenticated-session-browser-app/160/7
const fixCookie = () => {
let role = 'normal',
now = Date.now(),
domain = 'localhost'; // fix domain when in docker env
document.cookie = `user=${user}; path=/; domain=${domain}`;
document.cookie = `role=${role}; path=/; domain=${domain}`;
document.cookie = `last_login=${now}; path=/; domain=${domain}`;
export const createRegularUser = (login = 'a@a', password = 'a') => {
return Role(resolveUrl('/signin'), async() => {
await t.eval(() => window.localStorage.clear());
// Disable "Getting started" modal.
await t.eval(() => window.localStorage.showGettingStarted = 'false');
await page.login(login, password);
});
};
import {Selector, Role} from 'testcafe';
import {ReactSelector} from 'testcafe-react-selectors';
import checkPropTypes from '../checkPropTypes';
import Page from './pageModel';
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});
async function waitForIframeLoading(t) {
await t.expect(ReactSelector('Provider').getReact(({props}) => {
const reduxState = props.store.getState();
return !reduxState.ui.contentCanvas.isLoading;
})).ok('Loading stopped');
}
async function discardAll(t) {
await t
.click(ReactSelector('PublishDropDown ContextDropDownHeader'))
import { Role } from 'testcafe'
require('dotenv').config()
export const baseURL = process.env.E2E_TESTING_URL
export const admin = Role(`${baseURL}/wp-login.php`, async t => {
await t
.wait(100)
.typeText('#user_login', 'admin', { paste: true })
.typeText('#user_pass', 'password', { paste: true })
.click('#wp-submit')
})
import { Selector, Role } from 'testcafe'
const testTime = Math.floor(new Date() / 1000)
const testUser = Role('http://localhost:8080/#/login', async t => {
const mailField = Selector('div').withText('E-mail').child('input')
const passwordField = Selector('div').withText('Password').child('input')
await t
.selectText(mailField)
.typeText(mailField, `user${testTime}@example.com`)
.selectText(passwordField)
.typeText(passwordField, 'user')
.pressKey('enter')
})
fixture('homepage')
.page('http://localhost:8080/')
test('create user', async t => {
await t
.click(Selector('button').withText('SIGN UP!'))
await testController.navigateTo(githubPage.github.url());
});
When(/^I am typing my search request "([^"]*)" on GitHub$/, async function(text) {
await testController.typeText(githubPage.github.searchButton(), text);
});
Then(/^I am pressing (.*) key on GitHub$/, async function(text) {
await testController.pressKey(text);
});
Then(/^I should see that the first GitHub\'s result is (.*)$/, async function(text) {
await testController.expect(githubPage.github.firstSearchResult().innerText).contains(text);
});
const gitHubRoleForExample = Role(githubPage.github.url() + 'login', async function(t) {
await t
.click(githubPage.github.loginButton())
.expect(githubPage.github.loginErrorMessage().innerText).contains('Incorrect username or password.');
});
Then(/^I am trying to use (.*)$/, async function(text) {
await testController.useRole(gitHubRoleForExample);
});
import { Role } from 'testcafe';
import { api } from './api';
import { containerContents } from './page-object/editor/container-contents';
import { login } from './page-object/login';
export const Admin = Role(
`${api.baseUrl()}/#/login`,
async t => {
await login('admin', 'admin');
await containerContents.expectVisible();
},
{
preserveUrl: false
}
);