Skip to content

Instantly share code, notes, and snippets.

@joelwatson
Created July 5, 2017 17:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelwatson/80de810383e0d37e5d40b18dbc796e58 to your computer and use it in GitHub Desktop.
Save joelwatson/80de810383e0d37e5d40b18dbc796e58 to your computer and use it in GitHub Desktop.
Basic iframe interactions
http://www.littlewebhut.com/articles/html_iframe_example/
it('iframe test', function (done) {
var driver = ST.defaultContext.driver;
// switch the "context" to the iframe (where iframe.id = "imgbox")
driver.frame('imgbox');
ST
.element('img') // we're in the iframe context, so get element
.get('src') // get 'src' attribute
.and(function (future) {
// first expectation, should have default image
expect(future.data.src).toBe('http://www.littlewebhut.com/images/eightball.gif');
})
.and(function (future) {
// switch context back to full page (iframe parent)
driver.frame(null).then(function () {
// find the correct link element
ST.element('.wholecontent .article a[href="\/images\/redball.gif"]')
.click() // click it to change iframe image content
.and(function () {
// once more, switch to iframe context
driver.frame('imgbox').then(function () {
// and finally, assert the same value
ST
.element('img')
.get('src')
.and(function (future) {
expect(future.data.src).toBe('http://www.littlewebhut.com/images/redball.gif');
done();
});
});
});
});
});
});
it('iframe test', function (done) {
var driver = ST.defaultContext.driver;
var IH = {
iframe: function () {
return driver.frame('imgbox');
},
defaultFrame: function () {
return driver.frame(null);
},
img: function () {
return ST.element('img');
},
clickLink: function () {
return ST.element('.wholecontent .article a[href="\/images\/redball.gif"]').click();
},
assert: function (value) {
return IH.img().get('src').and(function (future) {
expect(future.data.src).toBe(value);
});
}
};
// switch the "context" to the iframe (where iframe.id = "imgbox")
IH.iframe();
IH
// assert the initial image value
.assert('http://www.littlewebhut.com/images/eightball.gif')
.and(function (future) {
// switch to default frame context
IH.defaultFrame().then(function () {
// click the link
IH.clickLink().and(function () {
// switch back to iframe context
IH.iframe().then(function () {
// assert the image value
IH
.assert('http://www.littlewebhut.com/images/redball.gif')
.and(function () {
done();
});
});
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment