Created
June 16, 2014 12:54
-
-
Save piecyk/64e2871646437be9d79e 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
| 'use strict'; | |
| var _ = require('lodash'); | |
| var q = require('q'); | |
| var PageObj = function(cfg, flow, expect) { | |
| this.cfg = cfg; | |
| this.flow = flow; | |
| this.expect = expect; | |
| this.ptor = protractor.getInstance(); | |
| this.savedViewPathOfElements = []; | |
| }; | |
| PageObj.prototype.goToUrl = function(url) { | |
| browser.get("#/"+ url || "workspace"); | |
| return this; | |
| }; | |
| //TODO: make this to classes SearchPageObj etc... | |
| //TODO: or name con prefix function about the functionality | |
| PageObj.prototype.setGlobalSearchInput = function(key, clear) { | |
| if (!clear) { | |
| element(by.id('search-field')).clear().sendKeys(key); | |
| } else { | |
| element(by.id('search-field')).sendKeys(key); | |
| } | |
| return this; | |
| }; | |
| PageObj.prototype.makeGlobalSearch = function() { | |
| element(by.id('search-button')).click(); | |
| return this; | |
| }; | |
| PageObj.prototype.checkTheNumberOfResultInListView = function(results) { | |
| this.expect(element(by.id('options-panel-result-count')).getText()).to.eventually.equal('Total '+ results); | |
| return this; | |
| }; | |
| //saved view list | |
| PageObj.prototype.findInTree = function(selector, label, last) { | |
| var deferred = protractor.promise.defer(); | |
| var self = this; | |
| var node = _.find(self.savedViewPathOfElements, function(el) { | |
| return el.label === label; | |
| }); | |
| if (node && last) { | |
| deferred.fulfill(node); | |
| } | |
| if (!node) { | |
| element(by.css(selector)).all(by.css('li a')).map(function(el) { | |
| return { label: el.getText(), obj: _.cloneDeep(el.element(by.css('.form-inline'))) }; | |
| }).then(function (result) { | |
| var node = _.find(result, function(el) { | |
| return el.label === label; | |
| }); | |
| if (last) { | |
| _.extend(node, {last: true}); | |
| } | |
| self.savedViewPathOfElements.push(node); | |
| deferred.fulfill(node); | |
| }); | |
| } | |
| return deferred.promise; | |
| }; | |
| PageObj.prototype.findSavedViewInWs = function(savedView) { | |
| this.flow.execute(function() { | |
| savedView.forEach(function(element, index) { | |
| var last = savedView.length-1===index; | |
| this.findInTree('.column-content .efecte-nav-tree', element, last).then(function(el) { | |
| el.obj.click(); | |
| }.bind(this)); | |
| }.bind(this)); | |
| }.bind(this)); | |
| return this; | |
| }; | |
| PageObj.prototype.closeSavedView = function() { | |
| this.flow.execute(function() { | |
| if (this.savedViewPathOfElements) { | |
| while(this.savedViewPathOfElements.length > 0) { | |
| var el = this.savedViewPathOfElements.pop(); | |
| if (!el.last) { | |
| el.obj.click(); | |
| } | |
| } | |
| } | |
| }.bind(this)); | |
| return this; | |
| }; | |
| module.exports = PageObj; | |
| // https://github.com/mcandre/node-quickcheck/blob/master/quickcheck.js | |
| function forAll(property) { | |
| var generators = Array.prototype.slice.call(arguments, 1), | |
| fn = function (f) { return f(); }, | |
| i, | |
| values; | |
| for (i = 0; i < 100; i ++) { | |
| values = generators.map(fn); | |
| if (!property.apply(null, values)) { | |
| return values; | |
| } | |
| } | |
| return true; | |
| } | |
| exports.forAll = forAll; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment