-
-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
POC: E2E test with Playwright #291
Comments
I just got stuck on this and did not know what to do, when I googled it I could not move forward. |
I gave up on playwright, Selenium might have a better option for end to end test, https://www.selenium.dev/selenium/docs/api/py/webdriver_chrome/selenium.webdriver.chrome.options.html#selenium.webdriver.chrome.options.Options.add_extension |
Selenium is too slow and older. We're already using Playwright in the app repo and we're keeping things uniform for tooling. Cypress was an option, but as mentioned, it doesn't work with popups in an extension. What specific issues are you running into? |
The main issue is that Playwright show the extension popup as HTML page rather than an extension, this limits the access to extension-related tools like: https://developer.chrome.com/docs/extensions/reference/storage/ which we use for signup etc. I thought about either going to selenium, or testing the extension components and functions without having the E2E test. |
Hi all! thank you @a0m0rajab and @nickytonline for your last live stream. I was able to proceed further with testing:
I share also the code snippet for that but it still buggy, notice I have added dotenv package to be able to avoid hardcoding the password and username
import { test } from "./popupFixture";
import dotenv from "dotenv";
import path from "path";
import { expect } from "playwright/test";
dotenv.config({ path: path.resolve(__dirname, "..", "env.test.local") });
test("popup page", async ({ page, extensionId, context }) => {
await page.goto(`chrome-extension://${extensionId}/index.html`);
await page.getByRole("button", { name: "Login" }).click();
// wait for popup to open
const authPage = await context.waitForEvent("page");
// await authPage.waitForLoadState("domcontentloaded");
await authPage
.locator("#login_field")
.fill(process.env.GITHUB_USERNAME ?? "username");
await authPage
.locator("#password")
.fill(process.env.GITHUB_PASSWORD ?? "password");
await authPage.locator('input[type="submit"]').click();
// await authPage.getByRole("button", { name: "Authorize" }).click();
// await authPage.getByAltText("User Avatar").focus();
await Promise.all([
authPage.getByRole("button", { name: "Authorize" }).click(),
authPage.getByAltText("User Avatar"),
]);
await authPage.close();
await page.getByRole("button", { name: "Login" }).click();
await expect(page.getByAltText("Open Sauced logo")).toBeVisible();
}); |
@JabSYsEmb thanks! that solves the problem I faced, I was expecting this to behave like the dev mode and not allow us to open pages! just adding extra context from the DMs, playwright provides different screenshots for every page it opens in the time line: the next code is made to consider two situations: if we logged in before to opensauced and if we did not. await Promise.all([
authPage.getByRole("button", { name: "Authorize" }).click(),
authPage.getByAltText("User Avatar"),
]); I did a quick check right now, it works, thank you for unblocking me. I think the next step would be setting the auth up for the whole tests: https://playwright.dev/docs/auth |
Update from the last stream, At the same time, I created a test account to login to Github and opensauced. As for the next step, I feel to run the logic that @JabSYsEmb provided, get it to work then play around the cookies file and dependencies. |
I ran the test after applying the requested changes in the #292 PR I did play around with the tests and tried to check if we could find the injected code in the browser with the tests that we have. For that reason, I wrote an extra test block: test('Test GitHub Page', async ({ page, extensionId, context }) => {
const newPage = page;
await newPage.goto(`https://github.com/open-sauced/ai/pull/292`);
await newPage.waitForTimeout(10000);
await newPage.getByText('Reviewers');
await expect(newPage.locator('#add-pr-to-highlights-button')).toBeVisible()
}); I am not sure why when I used the next code it did not work, test('Test GitHub Page', async ({ page, extensionId, context }) => {
await page.goto(`https://github.com/open-sauced/ai/pull/292`);
await page.waitForTimeout(10000);
// wait for an item with id:add-pr-to-highlights-button
// wait for this getByText('Reviewers')
await page.getByText('Reviewers');
await expect(page.locator('#add-pr-to-highlights-button')).toBeVisible()
}); |
A worth to check link for the cookies is this one: https://playwright.dev/docs/test-fixtures#overriding-fixtures which adds the cookies directly to the fixture. |
Type of feature
🍕 Feature
Current behavior
This is related to the latest stream I had with @nickytonline we could test the popup index page through the code below.
When I tried to work on the tests and login to the extension I could not do that due the inability to open a new tab and get the authentication from it, the playwright is testing the popups as HTML pages and not allowing to have the browser features that we need.
Here is an example from playwright:
This page is pretty similar to http://localhost:3000/ when you run the dev server, and that page does not allow you to login or open new window, I am not sure if this is possible to do not.
Related issue: #238
A solution to have is:
The downside for this would be:
Another thing we could try:
A good thing in playwright is that we could use the authentication feautre to login to github and opensauced, then we could use the cookies/auth information from that.
I think this is a feature request in the playwright but it's not implemented yet, related issues:
support for Chrome extension popup testing
Ability to click browser action buttons
Can I use playwright to test chrome extension?
Resources:
End-to-end testing Chrome extension, google docs
Suggested solution
No response
Additional context
No response
Code of Conduct
Contributing Docs
The text was updated successfully, but these errors were encountered: