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