Created
September 1, 2014 01:41
-
-
Save LeiZeng/1be24824d7955b680901 to your computer and use it in GitHub Desktop.
Viff, new structure of config file
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
var Testcases = require('./viff-testcases'); | |
function size (width) { | |
return function(driver) { | |
return driver.setWindowSize(width, 600 /* any height*/); | |
}; | |
} | |
var testcases = new Testcases({ | |
// seleniumHost: 'http://localhost:4444/wd/hub', | |
browsers: ['firefox'], | |
envHosts: { | |
author: 'http://localhost:8001', | |
build: 'http://localhost:8002' | |
}, | |
maxInstance: 3 | |
}); | |
testcases | |
.createGroup('NO-RESPONSIVE') | |
.config({ | |
// path: '/', | |
// partial: null, | |
handler: size(1200), | |
}) | |
.addCase({ | |
name: 'blog: side bar', | |
path: '/blog', | |
partial: '.sidebar' | |
}) | |
// create a new group and config as defaults | |
.createGroup('PC') | |
.config({ | |
path: '/', | |
// partial: null, | |
handler: size(1200), | |
}) | |
.addCase({ | |
name: 'home: whole page' | |
}) | |
// clone the PC group and reset some of the config | |
.cloneGroup('TABLET') | |
.config({ | |
handler: size(799) | |
}) | |
// clone the TABLET group and reset some of the config | |
.cloneGroup('PHONE') | |
.config({ | |
handler: size(479) | |
}) | |
.done(); | |
module.exports = testcases.config; |
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
var _ = require('lodash'); | |
var config = { | |
seleniumHost: 'http://localhost:4444/wd/hub', | |
browsers: ['phantomjs'], | |
envHosts: { | |
author: 'http://sunbkauthor.int.corp.sun', | |
build: 'http://sunbkbuild.int.corp.sun' | |
}, | |
maxInstance: 4 | |
}; | |
function Case (opts) { | |
if (Object.prototype.toString.call(opts) === "[object Object]") { | |
this.name = opts.name || 'unnamed case'; | |
this.path = opts.path || null; | |
this.partial = opts.partial || null; | |
this.handler = opts.handler || null; | |
} else { | |
throw new TypeError | |
} | |
} | |
Case.prototype.getPath = function() { | |
var key = '[' + this.group.name + ']' + this.name || '[Ungrouped]' + this.name | |
var conf = this.group.configuration; | |
var testcase = {}; | |
testcase[key] = []; | |
if (this.path || conf.path) testcase[key].push(this.path || conf.path); | |
if (this.partial || conf.partial) testcase[key].push(this.partial || conf.partial); | |
if (this.handler || conf.handler) testcase[key].push(this.handler || conf.handler); | |
return testcase | |
}; | |
Case.prototype.setGroup = function(group) { | |
this.group = group; | |
}; | |
function Group (opts) { | |
this.ins = opts.ins; | |
this.name = opts.name; | |
this.configuration = {}; | |
this.cases = []; | |
} | |
Group.prototype.config = function(opts) { | |
var _self = this; | |
for (var key in opts) { | |
this.configuration[key] = opts[key] | |
} | |
if (this.clone && this.new) { | |
_.map(this.clone.cases, function(testcase) { | |
_self.addCase(testcase); | |
}); | |
this.new = null; | |
} | |
return this | |
}; | |
Group.prototype.addCase = function(testcase) { | |
var _testcase = new Case(testcase); | |
_testcase.setGroup(this); | |
this.cases.push(testcase); | |
this.ins.addCase(_testcase); | |
return this | |
}; | |
Group.prototype.cloneGroup = function(newGroupName) { | |
var newGroup = new Group({ | |
name: newGroupName, | |
ins: this.ins | |
}) | |
.config(this.configuration) | |
// mark this as new one | |
newGroup.clone = this; | |
newGroup.new = true; | |
return this.ins.addGroup(newGroup); | |
}; | |
Group.prototype.done = function() { | |
// pass a chain object of testcases | |
this.ins.done(); | |
}; | |
Group.prototype.createGroup = function(groupname) { | |
// pass a chain object of testcases | |
return this.ins.createGroup(groupname); | |
}; | |
Group.prototype.size = function(width) { | |
return function(driver) { | |
return driver.setWindowSize(width, 600 /* any height*/); | |
}; | |
}; | |
function Testcases (opts) { | |
this.config = _.merge(config, opts); | |
this.paths = []; | |
} | |
Testcases.prototype.createGroup = function(groupname) { | |
var group; | |
groupname = groupname || 'Ungrouped'; | |
this.groups = this.groups || {}; | |
group = this.groups[groupname] | |
|| (this.groups[groupname] = new Group({ | |
name: groupname, | |
ins: this | |
})); | |
return group | |
}; | |
Testcases.prototype.group = function(groupname) { | |
groupname = groupname || 'Ungrouped' | |
return this.groups[groupname] | |
|| (this.groups[groupname] = new Group({ | |
name: groupname, | |
ins: this | |
})); | |
}; | |
Testcases.prototype.addGroup = function(group) { | |
if (group.constructor !== Group) { | |
throw new TypeError('Should be a Case!') | |
return | |
} | |
this.groups[group.name] = group; | |
return group | |
}; | |
Testcases.prototype.addCase = function(testcase) { | |
if (testcase.constructor !== Case) { | |
throw new TypeError('Should be a Case!') | |
return | |
} | |
this.paths.push(testcase.getPath()); | |
}; | |
Testcases.prototype.done = function() { | |
this.config.paths = this.paths; | |
}; | |
module.exports = Testcases |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment