Gunaseelan Ramalingam
Gunaseelan Ramalingam

Reputation: 61

Unable to use the storageState.json inside my tests, received the below error

I am trying to use the StorageState.json to share the authentication details, so that my test case does not have to login to the github everytime when my test case is executed.

Error: tests\githubtests\github.spec.ts:26:8: Playwright Test did not expect test.use() to be called here. Most common reasons include: - You are calling test.use() in a configuration file. - You are calling test.use() in a file that is imported by the configuration file. - You have two different versions of @playwright/test. This usually happens when one of the dependenices in your package.json depends on @playwright/test.

  24 | test("test2", async ({ page }) => {
  25 |
> 26 |   test.use({storageState: 'storageState.json'});
     |        ^
  27 |   const githubpo = new GithubLandingPage(page);
  28 |   await githubpo.gotoPage();
  29 |   await githubpo.gotoIssues();

    at C:\frameworks\Playwrightv2\Playwright-Framework\tests\githubtests\github.spec.ts:26:8

Upvotes: 3

Views: 3992

Answers (1)

Zakaria Ahmed
Zakaria Ahmed

Reputation: 72

You have to call the use method before the test method in line 24.

test.use({storageState: 'storageState.json'});

test("test2", async ({ page }) => {
    const githubpo = new GithubLandingPage(page);
    await githubpo.gotoPage();
    await githubpo.gotoIssues();
    ....
})

Upvotes: 2

Related Questions