Skip to content

Commit

Permalink
Using test and group in importDescriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
Pranav Parikh committed Mar 17, 2014
1 parent 0f231d1 commit f49340b
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 25 deletions.
4 changes: 2 additions & 2 deletions config/descriptor-schema.json
Expand Up @@ -21,11 +21,11 @@
"required":true
},
{
"importGroup":"Group of tests to import",
"group":"Group of tests to import",
"type":"string"
},
{
"importTest":"test names to import",
"test":"test names to import",
"type":"array"
}
]
Expand Down
20 changes: 9 additions & 11 deletions lib/driver/selenium.js
Expand Up @@ -213,7 +213,6 @@ SeleniumDriver.prototype.start = function (callback) {
*/
SeleniumDriver.prototype.stop = function (callback, error) {
var self = this;
self.logger.debug('Stopping webdriver');

if (self.sessionId) {
self.logger.debug('Stopping webdriver ' + self.sessionId);
Expand All @@ -222,18 +221,17 @@ SeleniumDriver.prototype.stop = function (callback, error) {
}
} else {
// // we were not given a session id
if (self.webdriver) {
if (self.webdriver) {

self.logger.debug('Stopping webdriver.Invoking webdriver quit');
self.logger.debug('Stopping webdriver.Invoking webdriver quit');

self.webdriver.quit().then(function () {
self.logger.debug('Stopped webdriver ');
if (callback) {
callback(error);
}
});
}
else {
self.webdriver.quit().then(function () {
self.logger.debug('Stopped webdriver ');
if (callback) {
callback(error);
}
});
} else {
if (callback) {
callback(error);
}
Expand Down
10 changes: 6 additions & 4 deletions lib/util/dataprovider.js
Expand Up @@ -58,15 +58,17 @@ DataProvider.prototype.getTestData = function () {
relativePath = path.dirname(self.testDataPath);
importDescriptor = descriptorJson[0].importDescriptor;

// read context into object
contextObj = qs.parse(this.context, ",", ":");

// Importing descriptor
if (importDescriptor) {
// We can read the descriptorJson from processImportDescriptor method too instead of passing from here
// In future, if we need to manipulate the descriptorJson before we import, this will help
//TODO - Remove cwd
descriptorJson = importManager.processImportDescriptor(self.testDataPath, cwd, self.args.group, descriptorJson);
}

// read context into object
contextObj = qs.parse(this.context, ",", ":");

baseUrl = self.config["baseUrl"];

// inject baseUrl into the settings
Expand All @@ -83,7 +85,7 @@ DataProvider.prototype.getTestData = function () {
if (descriptorJson[0].extends) {

// Resolve path
descriptorJson[0].extends = path.resolve(cwd,relativePath, descriptorJson[0].extends);
descriptorJson[0].extends = path.resolve(cwd, relativePath, descriptorJson[0].extends);

baseJson = JSON.parse(fs.readFileSync(descriptorJson[0].extends));
descriptorJson = descriptorJson.concat(baseJson);
Expand Down
15 changes: 9 additions & 6 deletions lib/util/importmanager.js
Expand Up @@ -32,7 +32,7 @@ function ImportManager() {
"importDescriptor":[
{
"path" : "tests/func/descriptor.json",
"importTest":["test_to_import_1","test_to_import_2"]
"test":["test_to_import_1","test_to_import_2"]
}
]
Expand All @@ -43,7 +43,7 @@ function ImportManager() {
"importDescriptor":[
{
"path" : "tests/func/descriptor.json",
"importGroup":["smoke"]
"group":["smoke"]
}
To import ALL the tests "tests/func/descriptor.json
Expand Down Expand Up @@ -99,9 +99,11 @@ ImportManager.prototype.processImportDescriptor = function(testDataPath, cwd, gr
importedDescPath = path.dirname(path.join(importingDescRelPath, importDescriptorArr[i].path));
self.logger.debug('Importing from :' + importedDescPath);


// Get tests from imported descriptor
importedDescriptorJsonStr = fs.readFileSync(path.join(cwd, importingDescRelPath, importDescriptorArr[i].path), "utf-8");
importTest = importDescriptorArr[i].importTest;
importGroup = importDescriptorArr[i].importGroup;
importTest = importDescriptorArr[i].test;
importGroup = importDescriptorArr[i].group;

importedDescriptorJson = JSON.parse(importedDescriptorJsonStr);

Expand All @@ -117,9 +119,10 @@ ImportManager.prototype.processImportDescriptor = function(testDataPath, cwd, gr

for (testName in importJson.dataprovider) {

if (self.addTest(importTest, importGroup, importJson, testName)) {
if (self.isImportable(importTest, importGroup, importJson, testName)) {
testObj[testName] = importJson.dataprovider[testName];
testObj[testName].group = group;
//TODO - Compute relativePath from SessionFactory
testObj[testName].relativePath = importedDescPath; // Set relative path for imported descriptor
}
}
Expand Down Expand Up @@ -151,7 +154,7 @@ ImportManager.prototype.processImportDescriptor = function(testDataPath, cwd, gr
* @param testName
* @returns {boolean}
*/
ImportManager.prototype.addTest = function(importTest, importGroup, importJson, testName) {
ImportManager.prototype.isImportable = function(importTest, importGroup, importJson, testName) {

if (importTest && importTest.length > 0) { // Tests take precedence over group
if (importTest.indexOf(testName) > -1) {
Expand Down
Expand Up @@ -11,7 +11,7 @@
"importDescriptor":[
{
"path" : "./importDescriptor.json",
"importGroup":"smoke"
"group":"smoke"
}
],

Expand Down
Expand Up @@ -11,7 +11,7 @@
"importDescriptor":[
{
"path" : "./importDescriptor.json",
"importTest":["imported test 1"]
"test":["imported test 1"]
}

],
Expand Down

0 comments on commit f49340b

Please sign in to comment.