Closed alexduhanov closed 4 years ago
Which operating system / Linux distribution are you using?
Sorry - meant macOS 10.15.4
I am having a somewhat related (?) error after upgrading from 0.13.0
to 0.15.0
.
Using chromium for testing on Ubuntu 18.04.4 LTS.
The tests which were working well earlier, have started having this error now:
Error: Protocol error (Target.createBrowserContext): Target closed.
before
, after
hooks are as under:
beforeAll(async () => {
browser = await chromium.launch({ headless: false });
// custom function
teamMembers = await getTeamMembersDataFromMdFiles();
});
beforeEach(async () => {
browserContext = await browser.newContext();
page = await browserContext.newPage();
await page.goto(`${appUrl}/`);
});
afterEach(async () => {
await page.close();
await browserContext.close();
});
afterAll(async () => {
await browser.close();
});
If this error is not related, apologies; please let me know. I will create another ticket.
Edit: Working fine for firefox
.
Your code snippets look good, so there is something wrong with either the test harness or with Playwright. Our tests do the same thing and they pass. Could you share an end-to-end snippet or a repo where this would reproduce? That would help a lot.
Here's an example. Following example works for:
Breaks on Chromium, trying to run both tests together. Error (before second test):
Protocol error (Target.createBrowserContext): Target closed.
12 |
13 | beforeEach(async () => {
> 14 | browserContext = await browser.newContext();
| ^
15 | page = await browserContext.newPage();
16 |
17 | await page.goto(`${appUrl}/`);
at node_modules/playwright-core/lib/chromium/crConnection.js:130:63
Playwright: 0.15.0 jest: 25.3.0 OS: Ubuntu 18.04.4 LTS
const { chromium } = require('playwright');
const appUrl = 'http://example.com/';
let page;
let browserContext;
let browser;
beforeAll(async () => {
browser = await chromium.launch({ headless: false });
});
beforeEach(async () => {
browserContext = await browser.newContext();
page = await browserContext.newPage();
await page.goto(`${appUrl}/`);
});
afterEach(async () => {
if (!page.isClosed()) {
await page.close();
await browserContext.close();
}
});
afterAll(async () => {
await browser.close();
});
describe('Home Page', () => {
it('should have the correct title', async () => {
await page.waitForSelector('text=Example Domain');
const pageTitle = await page.title();
expect(pageTitle).toBe('Example Domain');
});
it('should have the correct text in link', async () => {
const tagEl = await page.waitForSelector('a');
const tagText = await tagEl.evaluate((el) => el.innerText);
expect(tagText).toBe('More information...');
});
});
Edit: Just checked, this works good for 0.13.0
and 0.14.0
.
@pavelfeldman I've created a minimal standalone project you can check out that incorporates my snippet:
https://github.com/alexduhanov/playwright-test
Both tests in the suite pass individually but running the suite results in the Target closed
error mentioned above.
Out of curiosity I ran my example snippet in headless mode, and the tests succeeded. It seems like the problem may be tied to disabling chromium headless mode, which is also consistent with the example @sagrawal-idrc posted.
Thanks for the great example, I managed to reproduce it locally in headful mode (headless seems to be fine). In headful mode the browser crashes:
pw:browser:err Received signal 11 SEGV_MAPERR ffffd2fb3eb2afdf +301ms pw:browser:err #0 0x55cedd8ae919 base::debug::CollectStackTrace() +10ms pw:browser:err #1 0x55cedd813723 base::debug::StackTrace::StackTrace() +8ms pw:browser:err #2 0x55cedd8ae4b5 base::debug::(anonymous namespace)::StackDumpSignalHandler() +7ms pw:browser:err #3 0x7f097decf890 (/lib/x86_64-linux-gnu/libpthread-2.27.so+0x1288f) +0ms pw:browser:err #4 0x55cedd6130ff SharingServiceFactory::GetBrowserContextToUse() +5ms pw:browser:err #5 0x55cede832d00 KeyedServiceFactory::GetServiceForContext() +8ms pw:browser:err #6 0x55cedd7fbde6 SessionServiceFactory::GetForProfile() +5ms pw:browser:err #7 0x55cedff1facc Browser::~Browser() +11ms pw:browser:err #8 0x55cedff201be Browser::~Browser() +10ms pw:browser:err #9 0x55cee00ccaba BrowserView::~BrowserView() +12ms pw:browser:err #10 0x55cee00ccd95 BrowserView::~BrowserView() +11ms pw:browser:err #11 0x55cedf6edbaf views::View::~View() +9ms pw:browser:err #12 0x55cedf71accd views::NonClientView::~NonClientView() +10ms pw:browser:err #13 0x55cedf6ee9b7 views::View::DoRemoveChildView() +9ms pw:browser:err #14 0x55cedf6eea05 views::View::RemoveAllChildViews() +9ms pw:browser:err #15 0x55cedf705cbf views::Widget::~Widget() +10ms pw:browser:err #16 0x55cee00da13c BrowserFrame::~BrowserFrame() +11ms pw:browser:err #17 0x55cee00da1ae BrowserFrame::~BrowserFrame() +11ms pw:browser:err #18 0x55cedf736717 views::DesktopNativeWidgetAura::~DesktopNativeWidgetAura() +10ms pw:browser:err #19 0x55cee0119aeb DesktopBrowserFrameAuraLinux::~DesktopBrowserFrameAuraLinux() +11ms pw:browser:err #20 0x55cedf743b3f views::DesktopWindowTreeHostPlatform::OnClosed() +10ms pw:browser:err #21 0x55cedf72acd5 views::DesktopWindowTreeHostLinux::OnClosed() +9ms pw:browser:err #22 0x55cedf741cf8 views::DesktopWindowTreeHostPlatform::CloseNow() +10ms pw:browser:err #23 0x55cedd85b5ab base::TaskAnnotator::RunTask() +5ms pw:browser:err #24 0x55cedd86b648 base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWorkImpl() +6ms pw:browser:err #25 0x55cedd86b3e8 base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWork() +5ms pw:browser:err #26 0x55cedd827eca base::MessagePumpGlib::Run() +6ms pw:browser:err #27 0x55cedd86bbf5 base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::Run() +5ms pw:browser:err #28 0x55cedd844fbe base::RunLoop::Run() +6ms pw:browser:err #29 0x55cedd486d93 ChromeBrowserMainParts::MainMessageLoopRun() +5ms pw:browser:err #30 0x55cedbb72bab content::BrowserMainLoop::RunMainMessageLoopParts() +2ms pw:browser:err #31 0x55cedbb74a72 content::BrowserMainRunnerImpl::Run() +1ms pw:browser:err #32 0x55cedbb6fcad content::BrowserMain() +2ms pw:browser:err #33 0x55cedd4080d6 content::ContentMainRunnerImpl::RunServiceManager() +5ms pw:browser:err #34 0x55cedd407d07 content::ContentMainRunnerImpl::Run() +5ms pw:browser:err #35 0x55cedd467c29 service_manager::Main() +5ms pw:browser:err #36 0x55cedd405f51 content::ContentMain() +4ms pw:browser:err #37 0x55cedae5266e ChromeMain +16ms pw:browser:err #38 0x7f097783ab97 __libc_start_main +0ms pw:browser:err #39 0x55cedae524aa _start +16ms
I'll look at what's going on there.
Minimal repro case:
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch({
headless: false,
});
const context = await browser.newContext();
await context.newPage();
await context.close();
})();
Fixing upstream in https://chromium-review.googlesource.com/c/chromium/src/+/2168515
Context:
Code Snippet
Describe the bug
Error output:
This does seems to work for webkit and firefox.
Not sure if I'm doing something wrong -- I did see this note in the docs:
the default browser context cannot be closed.
but it wasn't clear to me if this meant "you cannot close the first new context you create via invoking newContext()" or "you cannot close a context if you do not invoke newContext() at all".Thanks!