Rayrun
← Back to Discord Forum

How to store email generated by Maislurp and use it to log in to all my test

Hi everyone!

I created a test to register a user and use a service called Maislurp to verify my user. The problem I come across is that I cannot log in with this user as I do not the email address created.

test.describe.only('test email login with playwright', () => {

// Creating the user

let registerPage: RegisterPage
let homePage: HomePage
let verifiedUserEmail = "";
test.beforeEach(async ({ page, browser }) => {



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

    await homePage.visit()
    await homePage.pressSignUpButton()


})


test("RegisterUser", async ({ page, browser }) => {

    let ApiKey: string = ''
    expect(ApiKey).toBeDefined()

    const mailslurp = new MailSlurp({ apiKey: "e2519db83cc775184d28e071d029e3055cd74a03999296bd5ccd4e82781d1a0f" })
    const { id, emailAddress } = await mailslurp.createInbox()

    await registerPage.fillRegisterForm("Test", "Johnson", emailAddress, emailAddress, "0315220", "Test", "test", "test", "test", "test", "100", "test", "test", "Tester123#", "Tester123#")
    await registerPage.pressRegisterButton()
    await page.waitForTimeout(3000);
    const errorMessage = await page.locator(".k-notification-content").textContent()
    await expect(errorMessage).toContain(' The user Test is created. ')

    const email = await mailslurp.waitForLatestEmail(id)

    const linkResults = await mailslurp.emailController.getEmailLinks({

        emailId: email.id!!

    })

    const useURL = linkResults.links[0]
    await page.click(useURL)


    const instructorContext = await browser.newContext()
    const page1 = await instructorContext.newPage()


    await page1.goto(useURL)
    await page.pause()

I would like to do an auth globally but I cannot user this emailaddres outside of this test file. How can I approach this problem ?

This thread is trying to answer question "How can I use the email address generated by MailSlurp to log in to all my tests?"

15 replies

I will take a look at this tnx

This might not work for me because in the global file I cannot run the test to create the user

I get error that my getByTestID are not working etc

🤷 Examples have usage of getBy methods.

When I transfer my whole test to global setup file

it stops working

that is what i meant

Then fix the issues 🤷‍♂️ Anyway, for what you want to achieve you'll most likely need either global setup or project dependencies.

I will take a look

I have been playing with global setup for couple of hours so far

the problem is that I first need to register / verify and then get that user to log in and go over the tests

The possible solution i got was

Reg/Verify in the global setup file and then log in to save data in local storage and then continue the test but I got stuck on that because my

Page , browser , context were working at all

refactoreric

Probably you will want to use project dependencies instead of global setup/teardown.

It will enable you to record trace files/screenshots/videos so it becomes easier to troubleshoot failures in the mailbox creation and login.

Create 3 projects like 'mailboxcreation', 'login', 'tests'. Then make tests depend on login And make login depend on mailboxcreation https://playwright.dev/docs/test-projects#dependencies

You can use environment variables to pass information from one project to the other, like process.env.MAILBOX='[email protected]'

And then in the next dependency (the login), access this process.env.MAILBOX.

I will take a look, it seems to be hard problem for a newbie 😄

I did solve the issue by registering and logining via the global setup file.

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].