Rayrun
โ† Back to Discord Forum

How to store and use login data generated by Mailslurp

Hello,

I am doing E2E of an application. I am generating inbox and emails via Mailslurp which I use to register and verify a user. On every register test new inbox and new email is generated for that test.

My goal is to complete the whole e2e process with that user. How can I store the data and use it across my test ?

For example:

Register & Verify user (here I take the data ) Login with the user from previous test Create a Site Create a schedule etc.

This thread is trying to answer question "How can I store the data generated by Mailslurp and use it across my tests for end-to-end testing of an application?"

40 replies

Move 'everything' from the example test to one or more fixtures with scope 'worker' https://playwright.dev/docs/test-fixtures#worker-scoped-fixtures *this will use the same user on a single worker until there has been an error

Let me read this, @hubspace thanks a lot. May I ask you few more q ?

I need to create a custom fixutre? I forgot to mention I am begginer

That would be the cleanest solution. Depending on what you need you could also just store it in a file and check if the file exists before creating a new user in every test.

here is an example code of one test

test.describe("Create credential", () => { let registerPage: RegisterPage let homePage : HomePage let CreateCredential : createCredential

test.beforeEach(async ({page}) => {

    registerPage = new RegisterPage(page)
    homePage = new HomePage(page)
    CreateCredential = new createCredential(page)

    await homePage.visit()
    await homePage.fillLogInForm('[email protected]','Tester123#')
    await homePage.pressSignInButton()

})

test('Create new credential',async ({page}) => {

await CreateCredential.createCredentialForUser('01231231', 'Tom Jones Bones')
await page.waitForTimeout(4000);

})

})

If you have no experience with fixtures they might be quite confusing at first. They are used for setup and teardown of your tests or group of tests to keep them somewhat isolated

Before every times I have a before each in which I navigate to web page and login and then the test starts

is this the correct way?

yes that is perfectly fine

so when I have a fixture

will I need to have a before each ?

it depends. You could move EVERYTHING form beforeEach to fixtures, but it doenst always make sense

for example register could be moved to fixtures. Thats what i recomment

aha with my limited experience I was thinking I could somehow store the data for username globally and then use it to log in because I only need username , password is always the same

And you could keep the login in beforeEach

hm I do not seem to understand ๐Ÿ˜ฆ

Do you create a new user ever time your run your test suit?

yes I do

the problem with the email is that I do not know what is the email it is being created by Mailslurp

Ok, this is normally done in a global setup, try if you can find anything here: https://playwright.dev/docs/test-global-setup-teardown

That might be easier than fixtures

on every test a new email is created

with this email user is verified and now can log in to app

so my problem is how to get this email to be used in all before each to log in with this user

I am not sure if I express myself correctly

do you understand me @hubspace ?

Oh, maybe you mean that you want something like beforeAll ?

I have no way of storing the email address and then using it across different tests

After my register test is done I do not know what my email si

do you want to share the same user with ALL tests or only tests that are grouped (for example with a describe block)

the setup example stores the authentification in a file. And all tests access the file to get the shared authentification

In this

I will use the same user to go over this tests

Then do the setup and store authentification in a file or store username / password in process.env.

I will take a look

@hubspace thank you a lot!

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].