Implement user roles
See original GitHub issueRoles
Use roles to observe results or perform actions from different user perspectives. Also, it’s a solution for the forms authentication problem. Role initialization will be executed once per task on first demand and can be shared among tests and fixtures. Technically role saves created cookies and storages state. When we switch role in tests and if it’s not initialized yet then initializations steps run and we return back to the page on which we stopped execution. If it’s already initialized then page will be just reloaded with the new credentials.
helpers.js
import { Role } from 'testcafe';
export var registeredUser = Role(t => {
await t
.navigateTo('http://example.org')
.typeText('#login', 'TonyStark')
.typeText('#password', 'swordFish');
.click('#login');
});;
test.js
import { registeredUser } from '../helpers';
import { Role } from 'testcafe';
fixture `example.org tests`;
test('Anonymous users can see newly created comments', async t => {
await t
.switchRole(registeredUser)
.navigateTo('http://example.org')
.typeText('#comment', 'Hey ya!')
.click('#submit')
.switchRole(Role.anonymous());
var comment = await t.select('#comment-data');
expect(comment.innerText).eql('Hey ya!');
});
Issue Analytics
- State:
- Created 8 years ago
- Reactions:12
- Comments:27 (13 by maintainers)
Top Results From Across the Web
Implementing Role Based Security in a Web App - Medium
Implementing role based security can be a large development effort with a significant amount of risk (denying access to users or opening up ......
Read more >Role-Based Access Control - Auth0
You can also use roles to collect permissions defined for various APIs. For example, say you have a marketing module that allows users...
Read more >Implementing Role Based Access Control in a Web Application
Define permissions based on resources and actions (i.e. users:create ). This leads to well-defined permissions that never need to change even if ...
Read more >Introducing User Roles Authorization with SuperTokens
Part 2 - Implement SuperTokens User Roles · Step 1) Creating the roles and permissions · Step 2) Assigning roles to users on...
Read more >What is Role-Based Access Control (RBAC)? - Varonis
5 Steps to Implement Role-Based Access Control ; Define the resources and services you provide to your users (e.g., email, CRM, file shares, ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
What about
t.ctx
: it’ll be shared between test and role or not?@p-bakker I can’t reproduce it on my side, this works fine for me: