Automate BDD Testing with logged in user

I am using the BDD Framework for testing and test automation. And I would like to write a test for a Server Action. This Server Action adds a new record to a database table. This table has a mandatory "createdBy"-Column. The Server Action uses the "GetUserId()" Build-in Function to store the current user, who calls the server action, in the new record.

During my test I get a error because there is no logged in user at that point. What is the best way to avoid this?

Is it possible to set a UserId at the beginning of my test, maybe the userId of a special test user so that the "GetUserId()" will return this test user?

I am not a big fan of modifying my Server Action and add a new input parameter "userId" which will be used during the test, instead of the "GetUserId()". And in production the "GetUserId()" will be used instead of the input parameter. Hopefully there is a better way?

Rank: #18

Hi Thorsten,

Using build-in functions like GetUserId() GetDate() inside your actions make them hard to use in test automation. Consider to refactor your logic to have these as input parameters and never as state in your action. There are some alternative ways to solve this:

  1. Create for all state functions a public action. So like MyGetUserId() and use a site property to set the UserId for testing or else use GetUserId().
  2. Use the User_Login Login function to actually login as a user in the Given action.



Hi Daniel,

thank you for your quick response. I have to think about the alternatives.

best regards,