Created
December 16, 2012 15:02
-
-
Save ypresto/4308171 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*global require:false */ | |
var plainAcroUA = 'Mozilla/5.0 (Linux; U; Android 2.3.3; ja-jp; SonyEricssonSO-02C Build/3.0.1.F.0.126) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1'; | |
var plainAcroViewport = {width : 480, height: 854}; | |
// create instance, set options | |
var casper = require('casper').create({ | |
pageSettings : { | |
userAgent : plainAcroUA | |
}, | |
viewportSize : plainAcroViewport | |
}); | |
// step 1: open webpage and login | |
casper.start('http://mixi.jp', function () { | |
this.fill('form[name="login_form"]', { | |
email : 'hoge', | |
password : 'fuga' | |
}); | |
this.click('p.loginButton > input[type="image"]'); // submit | |
}); | |
// step 2: check if this is mixi touch home.pl page | |
casper.then(function () { | |
this.test.assertUrlMatch(/home\.pl/, 'move to home.pl after login'); | |
this.test.assertVisible('a[href="#!/post"]', 'post button is visible'); | |
}); | |
// step 3: check iframe visibility | |
casper.waitForSelector('div#JS_ad_homemiddle', function () { | |
this.test.assertVisible('div.adMain iframe[name="ad1"]', 'top ad is visible'); | |
this.test.assertVisible('div#JS_ad_homemiddle iframe[name="ad2"]', 'middle ad is visible'); | |
this.test.assertVisible('div.adMain iframe[name="ad3"]', 'bottom ad is visible'); | |
}); | |
// step 4: check innenr iframe visibility | |
// casper.withFrame('ad1', adTest); also available in newer version of casperjs, but without waitFor | |
// use switchToFrame from phantomjs API; returns true when succeeded | |
casper.then(function () { this.test.assert(this.page.switchToFrame('ad1'), 'frame "ad1" exists'); }); | |
casper.waitForSelector('a', function () { | |
this.test.assertVisible('#mainArea > a > img', 'banner img on top ad is visible'); | |
}); | |
casper.then(function () { this.page.switchToMainFrame(); }); | |
casper.then(function () { this.test.assert(this.page.switchToFrame('ad2'), 'frame "ad2" exists'); }); | |
casper.waitForSelector('a', function () { | |
this.test.assertVisible('#mainArea > a > img', 'banner img on middle ad is visible'); | |
}); | |
casper.then(function () { this.page.switchToMainFrame(); }); | |
casper.then(function () { this.test.assert(this.page.switchToFrame('ad3'), 'frame "ad3" exists'); }); | |
// sometimes fails | |
// casper.waitForSelector('a', function () { | |
// this.test.assertVisible('#mainArea > a > img', 'banner img on bottom ad is visible'); | |
// }); | |
casper.then(function () { this.echo('skipped bottom ad containt check'); }); | |
casper.then(function () { this.page.switchToMainFrame(); }); | |
// step 5: check ad in topics tab | |
casper.then(function () { | |
this.test.assertNotExists('.JS_topicsSection div.adMain iframe[name="ad4"]', 'topics ad not loaded before opening tab'); | |
// this.clickLabel('ニュース&コミュ'); // fails, maybe charset problem | |
this.test.assertVisible('#JS_informationTab', 'topics tab button is visible'); | |
this.click('#JS_informationTab'); | |
}); | |
casper.waitForSelector('.JS_topicsSection', function () { | |
this.test.assertExists('.JS_topicsSection div.adMain iframe[name="ad4"]', 'topics ad loaded after opening tab'); | |
}); | |
casper.then(function () { this.test.assert(this.page.switchToFrame('ad4'), 'frame "ad4" exists'); }); | |
casper.waitForSelector('a', function () { | |
this.test.assertVisible('#mainArea a', 'a tag in ad is visible'); | |
}); | |
casper.then(function () { this.page.switchToMainFrame(); }); | |
casper.run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment