Skip to content
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

[Codecept Playwright] - Not able to maximize the window. windowSize = "maximize" not working properly #4616

Open
HarikrishnanVK opened this issue Nov 26, 2024 · 3 comments

Comments

@HarikrishnanVK
Copy link

I want to maximize the window where my app fit to the entire screen perfectly

By using the option (windowSize = "maximize") in conf.js file does not work.

  • CodeceptJS version: 3.6.7
  • NodeJS Version: 20.12.2
  • Operating System: Windows 11
  • playwright
  • Configuration file:
    const { default: test } = require("playwright/test");

exports.config = {
output: './output',
tests: './other_tests/**.test.js',
helpers: {
Playwright: {
browser: 'chromium',
url: 'localhost:3000',
show: true,
getPageTimeout: 180000,
waitForTimeout: 180000,
waitForNavigation: "networkidle0",
restart: "session",
keepBrowserState: true,
keepCookies: true,
windowSize: "maximize",
chromium: {
args: ['--start-maximized'],
viewport: null
}
},
Generics: {
require: "./helpers/generics.js"
},
ExpectHelper: {}
},
include: {
I: './steps_file.js'
},
timeout: 560,
gherkin: {
features: './features/*.feature',
steps: ['./step_definitions/steps.js'],
},
plugins: {
screenshotOnFail: {
enabled: true
},
tryTo: {
enabled: true
},
allure: {
enabled: true,
require: '@codeceptjs/allure-legacy',
}
},
name: 'test_Automation'
}

I even tried to extend playwright method where I able to maximize the window but not sure how to reuse the new context as I need to close the one created by codeceptjs fixture.

const { chromium } = require('playwright');

Feature('Maximize Browser Window');

Scenario('Maximize window using Playwright', async ({ I }) => {
I.amOnPage('http://localhost'); // Replace with your URL

I.usePlaywrightTo('maximize browser window', async ({ page }) => {
// Close the existing browser context
const browser = page.context().browser();
await browser.close();

// Launch a new browser instance with the --start-maximized argument
const newBrowser = await chromium.launch({
  headless: false,
  args: ["--start-maximized"],
});

// Create a new browser context with a maximized viewport
const context = await newBrowser.newContext({ viewport: null });
const newPage = await context.newPage();

// Navigate to the specified URL
await newPage.goto('http://localhost'); // Replace with your URL

// Set the new page for further CodeceptJS steps
I._setPage(newPage);

});

// Continue with your test steps using the new page
I.see('Welcome');
});

@myrepojuly1987
Copy link

Hi .. pls import const { setWindowSize } = require ("@codeceptjs/configure") and set the width and height.

Replace windowSize: "maximize" with setWindowSize: setWindowSize(1280, 720)

@HarikrishnanVK
Copy link
Author

@myrepojuly1987 Setting the viewport size doesn't fit the application exactly to the full screen even though I provided the exact resolution (19200x1200) .

There is a option in playwright where you can set the viewport as null and maximized argument would do the needful. I am looking for a similar functionality in codecept.io.

@myrepojuly1987
Copy link

I assume you want to pass args: ["--start-maximized"]

Can you try passing as shown under Example 5 here https://codecept.io/helpers/Playwright/#properties

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants