Last active
August 29, 2015 14:01
-
-
Save bitdivision/3fd36ce263c48757eafa to your computer and use it in GitHub Desktop.
This file contains hidden or 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
//Click and drag can either be done using dragAndDrop() | |
browser.actions().dragAndDrop(element.find(), { x: 50, y: 50 }).perform(); |
This file contains hidden or 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
// The following runs it's internal tasks by adding them to the control flow | |
// and fulfilling a promise on completion | |
function runTasks(arg1, arg2) { | |
var flow = protractor.promise.controlFlow(); | |
var defer = new protractor.promise.Deferred(); | |
var someVal; | |
//Add a few functions to the queue of tasks to run in controlFlow | |
flow.execute( function () { | |
return someFunction(arg1, arg2); | |
}).then(function(res) { | |
//Control flow tasks can return values. | |
someVal = res; | |
}); | |
flow.execute(function () { | |
return anotherFunction(arg1)); | |
}).then(function() { | |
defer.fulfill(someVal); | |
}); | |
return defer.promise; | |
} | |
describe('some suite', function() { | |
it('some test', function() { | |
//We can use a function returning a promise within expect | |
expect(runTasks(arg1, arg2)).toBe(true); | |
}); | |
}); |
This file contains hidden or 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
//This script is a slightly modified version of http://ynot408.wordpress.com/category/selenium/ | |
clickAndDragScript = "function simulate(f,c,d,e){var b,a=null;for(b in eventMatchers)if(eventMatchers[b].test(c)){a=b;break}if(!a)return!1;document.createEvent?(b=document.createEvent(a),a==\"HTMLEvents\"?b.initEvent(c,!0,!0):b.initMouseEvent(c,!0,!0,document.defaultView,0,d,e,d,e,!1,!1,!1,!1,0,null),f.dispatchEvent(b)):(a=document.createEventObject(),a.detail=0,a.screenX=d,a.screenY=e,a.clientX=d,a.clientY=e,a.ctrlKey=!1,a.altKey=!1,a.shiftKey=!1,a.metaKey=!1,a.button=1,f.fireEvent(\"on\"+c,a));return!0} var eventMatchers={HTMLEvents:/^(?:load|unload|abort|error|select|change|submit|reset|focus|blur|resize|scroll)$/,MouseEvents:/^(?:click|dblclick|mouse(?:down|up|over|move|out))$/}; " + "simulate(arguments[0],\"mousedown\",arguments[3],arguments[4]); simulate(arguments[0],\"mousemove\",arguments[1],arguments[2]); simulate(arguments[0],\"mouseup\",arguments[1],arguments[2]); "; | |
//Execute the script in the browser | |
browser.executeScript(clickAndDragScript,toDrag.find(),xto,yto, res.x, res.y) |
This file contains hidden or 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
var testPage = require('./testPage.js'); | |
var protractor = require('protractor'); | |
describe('Desktop testing', function() { | |
it('should display the widget when a zBoxElement is tapped', function() { | |
testPage.navigate(); | |
testPage.openWidget(); | |
expect(testPage.widgetColorbox.isDisplayed()).toBe(true); | |
}); | |
}); |
This file contains hidden or 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
var testPage = function () { | |
this.widgetTrigger = element(by.css('a.zoe-engage-trigger.zboxElement>p>img')); | |
this.widgetColorbox = element(by.css('#zoe_colorbox')); | |
var settings = { | |
pageLoadTimeout : 1000, | |
loadTimeout : 1000, | |
pageURL : 'http://www.zoetrope.io', | |
} | |
this.navigate = function() { | |
browser.get(settings.pageURL); | |
browser.sleep(settings.pageLoadTimeout); | |
}; | |
this.openWidget = function() { | |
this.widgetTrigger.click(); | |
browser.sleep(settings.loadTimeout); | |
}; | |
}; | |
module.exports = new testPage(); |
This file contains hidden or 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
onPrepare: function() { | |
browser.ignoreSynchronization = true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment