Fix: Firefox browser not launching in BeforeAll hook#20
Open
TestRoverAutomation wants to merge 1 commit into
Open
Fix: Firefox browser not launching in BeforeAll hook#20TestRoverAutomation wants to merge 1 commit into
TestRoverAutomation wants to merge 1 commit into
Conversation
Owner
|
You can run Firefox as a default browser via projects configuration. In that case, you don't need to perform any setup in BeforeAll hook. |
|
Hi Vitalets you are right but can I perform like this as we have browser instance here, so in some company we define browser setup in hooks which with switch case, so this might be for enhancement to setup the hooks |
Owner
|
Okey, understood! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request Description:
Issue Description: Currently, when using the Playwright-BDD framework with custom hooks, Firefox is not launching as expected within the BeforeAll hook. The issue arises because the browser is being initialized manually, but Chromium is still being launched by default, overriding the explicit call to Firefox.
Root Cause: The Playwright-BDD framework seems to default to Chromium if the browser is not explicitly overridden in the configuration file or in the test hook. The current behavior ignores the manual call to firefox.launch() within the BeforeAll hook.
Proposed Solution: This PR modifies the test setup to explicitly launch Firefox , webkit within the BeforeAll hook without configuring the browser in the playwright.config.ts file. The changes include:
Manually launching Firefox and Webkit with firefox.launch({ headless: false }) inside the BeforeAll hook.
Opening a new page in the Firefox browser and ensuring that the tests proceed within this context.
Ensuring that Firefox, rather than Chromium, is the browser used during the test lifecycle.
Code Changes:
`import { expect } from "@playwright/test";
import { firefox } from '@playwright/test';
import { Given, When, Then } from "./fixtures";
import { createBdd } from "playwright-bdd";
const { BeforeAll } = createBdd();
let browser, page;
BeforeAll(async function () {
try {
// Explicitly launch Firefox
browser = await firefox.launch({
headless: false, // Set to false to see the browser
});
} catch (error) {
console.log("Error launching Firefox:", error);
}
});
Given("I am on Playwright home page", async ({ page }) => {
await page.goto("https://playwright.dev");
});
When("I click link {string}", async ({ page }, name: string) => {
await page.getByRole("link", { name }).click();
});
Then("I see in title {string}", async ({ page }, text: string) => {
await expect(page).toHaveTitle(new RegExp(text));
});
`