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

Selenium testing in storybook IFrame #3803

Closed
blackswanny opened this issue Jun 27, 2018 · 4 comments
Closed

Selenium testing in storybook IFrame #3803

blackswanny opened this issue Jun 27, 2018 · 4 comments

Comments

@blackswanny
Copy link

Good day. I am trying to setup selenium (javascript) to access storybook. But it's run in nested IFRame. Seems like I can't get to tested DOM in IFRame, cause selenium has no way to wait for it.
So when I try to access them I see StaleElementReferenceError: stale element reference: element is not attached to the page document. Did anyone try? Webdriver is Chrome. I use Mocha for test suites.

import 'babel-polyfill';
import 'chromedriver';
import webdriver from 'selenium-webdriver';
import until from 'selenium-webdriver/lib/until';
import {assert} from 'chai';

const {By} = webdriver;
const storyBookUrl = 'http://localhost:6006/?selectedKind=Checkbox&selectedStory=Checkbox%20example';
const storyBookFrameId = 'storybook-preview-iframe';
  before(async function() {
    const caps = webdriver.Capabilities['chrome']();
    driver = new webdriver.Builder()
      .forBrowser('chrome').withCapabilities(caps).build();
    await driver.get(storyBookUrl);
  });

  after(async function() {
    await driver.quit();
  });

  beforeEach(async function() {
    const frame = await driver.findElement(By.id(storyBookFrameId));
    driver.switchTo().frame(frame);
    checkmark = driver.wait(until.elementLocated(By.css('input')));
    let type = await checkmark.getAttribute('type');
    //checkbox = await driver.findElement(By.css('label'));
  });
@patthiel
Copy link

Instead of attempting to switch focus to the iframe, you can navigate directly to the iframe via:

http://localhost:6006/iframe.html?selectedKind=SOME_EXAMPLE_KIND&selectedStory=SOME_EXAMPLE_STORY

This made our selenium tests much faster and more reliable.

@blackswanny
Copy link
Author

yes. This works. However, I will have to go to other URL\page each time I need to switch to another story. Is it slower than if I had it embedded in IFRame?

@patthiel
Copy link

@blackswanny i've actually experienced it's much quicker than navigating via storybook's UI to the stories. I would give it a shot and see how it works for you

@igor-dv
Copy link
Member

igor-dv commented Jul 3, 2018

I think we can close it.

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

No branches or pull requests

3 participants