Repository: microsoft/playwright
File: tests/page/frame-frame-element.spec.ts (TypeScript)

Code before:
});

it('should throw when detached', async ({ page, server }) => {
  await page.goto(server.EMPTY_PAGE);
  const frame1 = await attachFrame(page, 'frame1', server.EMPTY_PAGE);
  await page.$eval('#frame1', e => e.remove());
  const error = await frame1.frameElement().catch(e => e);
  expect(error.message).toContain('Frame has been detached.');
});

it('should work inside closed shadow root', async ({ page, server, browserName }) => {
  await page.goto(server.EMPTY_PAGE);
  await page.setContent(`
    <div id=framecontainer>
    </div>
    <script>
      const iframe = document.createElement('iframe');
      iframe.setAttribute('name', 'myframe');
      iframe.setAttribute('srcdoc', 'find me');
      const div = document.getElementById('framecontainer');
      const host = div.attachShadow({ mode: 'closed' });
      host.appendChild(iframe);
    </script>
  `);

  const frame = await findFrameByName(page, 'myframe');
  const element = await frame.frameElement();
  expect(await element.getAttribute('name')).toBe('myframe');
});

it('should work inside declarative shadow root', async ({ page, server, browserName }) => {
  await page.goto(server.EMPTY_PAGE);
  await page.setContent(`
    <div>
      <template shadowrootmode="open">
        <iframe name="myframe" srcdoc="<h1>Hi!</h1>"></iframe>
        <slot></slot>
      </template>
      <span>footer</span>
    </div>
  `);
  const frame = await findFrameByName(page, 'myframe');
  const element = await frame.frameElement();
  expect(await element.getAttribute('name')).toBe('myframe');
});


Review comment (suggestion):
```suggestion
  const frame = page.frames()[1];
```
Otherwise the expects just repeat what the function does.

Code after:
});

it('should throw when detached', async ({ page, server }) => {
  await page.goto(server.EMPTY_PAGE);
  const frame1 = await attachFrame(page, 'frame1', server.EMPTY_PAGE);
  await page.$eval('#frame1', e => e.remove());
  const error = await frame1.frameElement().catch(e => e);
  expect(error.message).toContain('Frame has been detached.');
});

it('should work inside closed shadow root', async ({ page, server, browserName }) => {
  await page.goto(server.EMPTY_PAGE);
  await page.setContent(`
    <div id=framecontainer>
    </div>
    <script>
      const iframe = document.createElement('iframe');
      iframe.setAttribute('name', 'myframe');
      iframe.setAttribute('srcdoc', 'find me');
      const div = document.getElementById('framecontainer');
      const host = div.attachShadow({ mode: 'closed' });
      host.appendChild(iframe);
    </script>
  `);

  const frame = page.frames()[1];
  const element = await frame.frameElement();
  expect(await element.getAttribute('name')).toBe('myframe');
});

it('should work inside declarative shadow root', async ({ page, server, browserName }) => {
  await page.goto(server.EMPTY_PAGE);
  await page.setContent(`
    <div>
      <template shadowrootmode="open">
        <iframe name="myframe" srcdoc="<h1>Hi!</h1>"></iframe>
        <slot></slot>
      </template>
      <span>footer</span>
    </div>
  `);
  const frame = page.frames()[1];
  const element = await frame.frameElement();
  expect(await element.getAttribute('name')).toBe('myframe');
});