Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**Run script as:
- casperjs meetup_casper_demo.js --app_url=http://dl.dropboxusercontent.com/u/36619447/live-demos/Get-a-fan/Sephora.html.
- **/
- /**Initialization part -- creates a Casper object with the desired options**/
- var casper = require('casper').create({ verbose:true,
- logLevel:'info',
- waitTimeout:10000,
- /**IMPORTANT:set viewport size as the defualt is too small
- and it will be detected as mobile device.**/
- viewportSize:{width: 900, height:700}
- });
- /**The app_url was passed as a command line parameter. We read this here**/
- app_url = casper.cli.get("app_url");
- casper.echo("Casper CLI passed options: %s" %app_url);
- /**This starts off the browser on the app_url page(the page on which the Shopsocially app is running in our case)**/
- casper.start(app_url, function(){
- });
- /**This is fired on document.ready() of the app_url page
- We first check if the Shopsocially App sidebar is present.Then we click on it.This will open and iframe.
- IMPORTANT :If we want to do any activity in an iframe, then we need to switch to it.
- In this case, we need to click on the 'Already Liked it' link which is inside an iframe,
- we will switch to it **/
- casper.then(function(){
- this.test.assertExists('#ssmi_getafan_sidebar_image', 'Get-a-Fan App Sidebar loaded.');
- this.click('#ssmi_getafan_sidebar_image a');
- this.page.switchToChildFrame("ssmi_getafan_iframe");
- this.test.assertResourceExists('http://d1qbqkkh49kht1.cloudfront.net/9c193b151ecfad21e78966f30a151abf.jpeg', 'Sephora model image exists');
- this.test.assertExists('#already_liked', 'Clicking on "Already Liked" of Get-a-Fan App.');
- this.click('#already_liked');
- /**All communication with remote DOM MUST be done using evaluate function. Here, I want to see the values of cookies set in remote DOM**/
- this.evaluate(function(){
- alert("Cookies are:" + document.cookie);
- });
- });
- /**Since there is some time between clicking on 'Already Liked It?' and coupon fetching, we wait for the selector to appear in DOM**/
- casper.waitForSelector('#coupon_area > span', function() {
- this.test.assertTextExists('Thank you!', 'Thank you message displayed correctly.');
- this.test.assertSelectorHasText('#coupon_area > span', 'Special-20');
- });
- casper.run(function(){
- /**We dump the test pass and failure information to the terminal**/
- require('utils').dump(casper.test.getFailures());
- require('utils').dump(casper.test.getPasses());
- /**We exit PhantomJS and print test results to a file**/
- casper.test.renderResults(true, 0, 'test-results.xml');
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement