-
Notifications
You must be signed in to change notification settings - Fork 674
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
Implement user roles #243
Comments
|
Hi Ivan, I see you're making progress with this case. Is it already in such a state that I could test with it? Or are the bits still to be implemented vital for being able to use it? |
@p-bakker |
Things that left to consider:
|
What about |
@helen-dikareva good point |
If we run test step-by-step we will continue debugging in |
@helen-dikareva We should keep debugging even in role initializer |
Great to see this case being closed. When is the next alpha expected? |
@p-bakker We plan to release it today. I'll add note here once it will be available. |
Excellent. Am already modifying my tests to start using this as soon as it's released. While at that, I realized a function to get the active role would be helpful. Is that already included/possible? |
Hello, @p-bakker! I'm happy to let you know that |
We haven't considered such scenario. What's the use case for this? |
@inikulin to answer your question above: in my domain specific classes that wrap all interaction with the browser, I expose an API for the writers of tests to use when they want to clean up server-side sessions, since every role equals a login equals a serverside session in my case. When they call my API to cleanup/exit a serverside session, they can pass in a Role. If that Role isn't the currently active Role, I must switch to the Role they want to exit first, before performing an exit in the app, after which I need to some back to my previously active Role. If the role they want to exit is the active Role, I need to do different stuff. Makes sense? |
I'm playing around with this new functionality, but I'm afraid it ain't working for me. The stuff I'm testing is a webapp with very dynamic URL, which are closely tied to serverside state. An example of the flow:
I read the following in the new docs:
The flow described here for when you switch to a role for the first time will not work in my scenario, neither will the part when you switch to an already initialized role: the reload of the current url with the credentials of another Role won't fly, because the url's are session (thus Role) specific. So it seems to me that this new feature will not work in my scenario where url's are session/role specific and where the login procedure isn't isolated under it's own url and affects the main page under testing only by just setting a cookie of some sort. Or am I missing something here? To clarify: the first thing I hoped this feature would allow me to do is just log in once per fixture and have my entire testsuite broken up in individual tests (up to now I just had one test which started with the login in order to make this work). The second thing would be being able to switch between different logged in users during tests |
@p-bakker So, if I understood you correct you just basically have URL-based session management? No cookies involved? |
No, the session is managed by a JSESSIONID cookie, but the urls of the app are also very dynamic/unique by session |
Interesting, so everything will work fine if we'll store URL in Role to which login action led and then on Role switch we redirect to this URL? |
Yes, thinking the entire flow through, as far as I can see that would indeed would make it work |
@p-bakker OK, it seems easy to implement. I'm only struggling to come up with meaningful option name for such behavior. Any suggestions? |
Pfff, good question. Something like dynamicSessionUrls? It's a bit difficult, because such setting would do multiple things:
Come to think of it, maybe the setting should be called something like persistUrl or useActiveUrl/useLastUrl, with a behavior that when switching Role, you get redirected back to the Url where that Role was last. In case it's the first time switching to the Role, the last url is the url where the test was when the login action led to. Think that such behavior is more generic and could even be useful when you don't have dynamic, session-based url's, as it allows writing tests for apps/pages where you can't just go to any Url, but where there is a sort of sequence to things. Hope that sort of makes sense |
@p-bakker Unfortunately functionality that allows to preserve URL will not make it into next release - we are closing sprint today. However, I've issued a separate ticket for it and more likely we'll implement it in the beginning of the next sprint: #1339. Meanwhile, you can use following workaround: import { t, Role, ClientFunction } from 'testcafe';
const getLocation = ClientFunction(() => location.href);
const someRole = Role('http://page', async () => {
// init steps...
someRole.preservedUrl = await getLocation();
});
async function switchToRoleAndKeepUrl(role) {
await t.useRole(role);
if (role.preservedUrl)
await t.navigateTo(role.preservedUrl);
}
fixture `Fixture`;
test('Test', async () => {
//...
await switchToRoleAndKeepUrl(someRole);
//...
}); |
@inikulin no problem, however: I tried your workaround, but for me the code after Does this workaround work for you? My code is like this:
I see the first log statement appearing in the console, but never the second |
@p-bakker I can't reproduce it on my side, this works fine for me: import { t, Role, ClientFunction } from 'testcafe';
const getLocation = ClientFunction(() => location.href);
const someRole = Role('http://google.com', async () => {
someRole.preservedUrl = await getLocation();
});
async function switchToRoleAndKeepUrl (role) {
await t.useRole(role);
console.log('session acivated', role.preservedUrl);
if (role.preservedUrl)
await t.navigateTo(role.preservedUrl);
}
fixture `Fixture`
.page `https://devexpress.github.io/testcafe/example/`;
test('Test', async () => {
await switchToRoleAndKeepUrl(someRole);
}); |
@p-bakker Did you manage to make it work on your side? |
@inikulin Yes, I did get it working according to how it should work. The entire feature however doesn't not work for my specific scenario, but that is a different story, see: #1339 (comment) |
This thread has been automatically locked since it is closed and there has not been any recent activity. Please open a new issue for related bugs or feature requests. We recommend you ask TestCafe API, usage and configuration inquiries on StackOverflow. |
…evExpress#1315) * Implement Role API, refactor server tests * Add Role id * Rename testRun.state to testRun.phase * Allow removal of native dialog handler. Save current iframe selector. * Introduce marker symbol for TestRun. Store current test run speed. * Implement test run bookmark * useRoleMachinery implemented * Implement UseRoleCommand * Implement t.useRole * Functionality implemented. Add basic test. * Test basic functionality * Add error tests * Move body-parser to dev deps * Fix tests * Run particular tests only on desktop browsers * Revert legacy api test-related page * Moved error definitions to the appropriate place * Throw appropriate message on iframe restore * iframe errors * Fix rebase issues
Roles
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
test.js
The text was updated successfully, but these errors were encountered: