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.
```js
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'));
});
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.
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?
@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
I think we can close it.