Open mxschmitt opened 3 years ago
It is a great feature
IT would be great to have this !
Voting this up. It would "obviously" include a full screen trigger too which brings us to https://github.com/microsoft/playwright/issues/1086.
Voting this up!
+1 for this solution
+1 for this solution
in Selenium we have .maximize(), so de we have any such in playwright?
Would really be great to have this
Solution for Java:
Upvote
Upvote.
Upvote
Upvote
Upvote
Upvoting this as well. Use cases:
Solution for Java:
Unfortunately, this is not working!
@azad-derakhshani-GS
allowing multiple people with different screens to work on testautomation without any problems (fixed viewport would be problematic because everyone has different monitors and resolutions)
This looks backwards to me: maximize would make pages behave differently, while fixed viewport guarantees consistent behavior. What do I miss?
Upvoting!
Upvoting
@azad-derakhshani-GS This looks backwards to me: maximize would make pages behave differently, while fixed viewport guarantees consistent behavior. What do I miss?
A well-designed page behaves consistently across different viewports, so this is nothing for the testautomation framework to worry about. Trust me, in several years of TA experience, maximizing the browser window never caused any such issues, not even once. It's also closer to the way a real user would behave. But Playwright artificially shrinks the viewport so the pages aren't even displayed in full, which (despite it scrolling into elements) leads to page elements not being fully displayed while PW interacts with them.
Also to elaborate a bit further on the second point from my previous post:
Not having a flexible (= maximized) resolution means I have to define a specific screen resolution (even null
does mean 1280x720). But a static resolution could be incompatible with other people's screens.
Sizing the browser window flexibly via maximize eliminates that problem.
Solution in Java:
try (Playwright playwright = Playwright.create()) { Browser browser = playwright.chromium().launch(new BrowserType.LaunchOptions().setHeadless(false));
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); int width = (int)screenSize.getWidth(); int height = (int)screenSize.getHeight();
BrowserContext context = browser.newContext(new Browser.NewContextOptions().setViewportSize(width,height) Page page = context.newPage();
Upvote
Upvote
Upvote
does anyone have solution in .net(c#) for maximizing the browser window?
does anyone have solution in .net(c#) for maximizing the browser window?
The following worked for me at last.
using var playwright = await Playwright.CreateAsync();
await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions
{
Headless = false,
Args = new [] { "--start-maximized" },
SlowMo = 100
});
var context = await browser.NewContextAsync(new BrowserNewContextOptions {
ViewportSize = ViewportSize.NoViewport
});
var page = await context.NewPageAsync();
await page.GotoAsync("https://playwright.dev/dotnet/docs/intro");
does anyone have solution in .net(c#) for maximizing the browser window?
The following worked for me at last.
using var playwright = await Playwright.CreateAsync(); await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions { Headless = false, Args = new [] { "--start-maximized" }, SlowMo = 100 }); var context = await browser.NewContextAsync(new BrowserNewContextOptions { ViewportSize = ViewportSize.NoViewport }); var page = await context.NewPageAsync(); await page.GotoAsync("https://playwright.dev/dotnet/docs/intro");
Thanks Mamoorkhan,
At least the above now changes the browser size. But It is not maximizing to the full screen. Like only half - as if split screen with another app.
Any idea?
@pavelfeldman mamoorkhan
does anyone have solution in .net(c#) for maximizing the browser window?
The following worked for me at last.
using var playwright = await Playwright.CreateAsync(); await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions { Headless = false, Args = new [] { "--start-maximized" }, SlowMo = 100 }); var context = await browser.NewContextAsync(new BrowserNewContextOptions { ViewportSize = ViewportSize.NoViewport }); var page = await context.NewPageAsync(); await page.GotoAsync("https://playwright.dev/dotnet/docs/intro");
@mamoorkhan Thanks, but still I am not seeing the maximized browser by using the above code
@NitishJoggessur and @dbhimar I was getting the same half screen maximised window when I was using only the --start-maximized flag, but when I added the viewport settings and created a new context for the page, it worked. I am using windows 10 x64 Enterprise. I am not sure if that helps.
@NitishJoggessur and @dbhimar I was getting the same half screen maximised window when I was using only the --start-maximized flag, but when I added the viewport settings and created a new context for the page, it worked. I am using windows 10 x64 Enterprise. I am not sure if that helps. @mamoorkhan
I am also using the windows 10 x64
_playwright = await Playwright.CreateAsync();
_browser = await _playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions
{
Headless = false,
Channel = "msedge",
Args = new[]
{
"--start-maximized"
},
});
_browserContext = await _browser.NewContextAsync();
await _browserContext.Tracing.StartAsync(new()
{
Screenshots = true,
Snapshots = true,
Sources = true
});
_page = await _browserContext.NewPageAsync();
await _browser.NewContextAsync(new BrowserNewContextOptions()
{
RecordVideoDir = "videos/",
ViewportSize = ViewportSize.NoViewport
});
above is the code which I am trying to maximize the browser window
@dbhimar you are recreating the context in the last line. try the following code
_browser = await _playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions
{
Headless = false,
Channel = "msedge",
Args = new[]
{
"--start-maximized"
},
});
_browserContext = await _browser.NewContextAsync(new BrowserNewContextOptions()
{
RecordVideoDir = "videos/",
ViewportSize = ViewportSize.NoViewport
});
await _browserContext.Tracing.StartAsync(new()
{
Screenshots = true,
Snapshots = true,
Sources = true
});
_page = await _browserContext.NewPageAsync();
Upvote
Upvote!
You can maximize the window by knowing which launch options each browser type has:
For Chromium, you need: --start-maximized For Firefox, you need: --kiosk
Currently trying to find out what to use for webkit. Knowing this, you can set up launch options like this, when you are launching the browser: (written in Playwright Java)
List<String> launchOptions = new ArrayList<>();
Playwright playwright = Playwright.create();
// Change browser type
BrowserType type = playwright.firefox();
switch (type.name()) {
case "chromium": {
launchOptions.add("--start-maximized");
launchOptions.add("--incognito");
// Can be "msedge", "chrome-beta", "msedge-beta", "msedge-dev", etc.
String browserChannel = "chrome";
browser = type.launch(new BrowserType.LaunchOptions()
.setChannel(browserChannel)
.setArgs(launchOptions);
break;
}
case "firefox": {
launchOptions.add("--kiosk");
launchOptions.add("--private-window");
browser = type.launch(new BrowserType.LaunchOptions()
.setArgs(launchOptions);
break;
}
}
Hello,
We also need this. We cannot get it to work. We need to maximize chrome because setting the viewport has downfalls - cannot really see the popup's in our up.
Thnaks!
We too need the maximized browser window. Viewport option splits the browser on my laptop and extended monitor desktop screen. Its funny to watch, half of the elements being interacted on laptop screen and other half on desktop :D
How can I maximize the chromium window in js?
How we can maximize the browser as per screen size in playwright Java
Hi, I would be perfect if we have .maximize like selenium. Meanwhile, this works for me (version 1.29 java)
Does anyone have any idea about JavaScript?
Does anyone find the solution to maximize the window using C#.net ? @mamoorkhan its working for you?
Have tried all the possible ways but the maximize function isn't accurate. Also, when I launch browser browser in my extended screen I had to maximise manually, the inner page remains cropped and doesn't adopt the screen size. I am getting the feeling the maximise function is not accurate as Selenium.
Have tried all the possible ways but the maximize function isn't accurate. Also, when I launch browser browser in my extended screen I had to maximise manually, the inner page remains cropped and doesn't adopt the screen size. I am getting the feeling the maximise function is not accurate as Selenium.
Yes, The same is occurring to me as well. It would be great If they address it ASAP!
Hello. Following worked for me!
{
name: "chromium",
use: {
...devices["Desktop Chromium"],
viewport: null,
launchOptions: {
args: ["--start-maximized"]
}
},
},
Thanks,
Does anyone find the solution to maximize the window using C#.net ? @mamoorkhan its working for you?
hey sorry for missing this, but yes, this worked for me.
Upvote!
@mxschmitt , is there any workaround for it in .net when using PageTest class?
Following code worked for me.
Proposed solution for .NET doesn't work for me as well. The page is still cropped and in case of dynamic UI interface with react controls and stuff PW works weird time to time which leads to flakiness for some tests. What frustrates the most the glitches often happen at nightly run on TeamCity agent and almost never when you run the same test from you laptop browser. When I inspect the trace I don't even see some web elements. When I open the trace viewport in a new page at fullsize - I see the missing web elements. So the feature is anticipated. At least as a workaround maybe there is a way to launch Chrome in some mode when it fits all the content on one viewport (zooming out the page maybe?) like it is possible in Chrome inspector.
HEY PLAYWIGHT TEAM !!!! Pleaease implement this feature ASAP. Do you see, how many of us have a problem with it? This feature reequest is from more than 3 years ago, and no improvement since then.... This is number 1 feature request you should work on, or if you don't want to solve it, then please go to remove Firefox from list of supported browsers.... Because without it, Firefox cannot be used reliably (of course I managed to run chromium based browsers maximized, that is not so hard to achieve) but why can't we run Firefox maximized?
PLEASE WORK ON THIS FEATURE ASAP... MANY PEOPLE FIND IT VERY IMPORTANT TO BE ABLE TO RUN RELIABLE TESTS !!!
Selenium feature: https://www.selenium.dev/selenium/docs/api/py/webdriver_remote/selenium.webdriver.remote.webdriver.html#selenium.webdriver.remote.webdriver.WebDriver.maximize_window
Requested via Slack.
Scenario: Automate a website and then let the user complete something. Its great if the max possible width/height could be determined so the user has "maximum available viewport".
But not sure how or if its easy implementable since we in CR e.g. emulate the viewport independent from the window size.
For Chromium it works already like that: