Skip to content

Commit

Permalink
Synced galenjs scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
ishubin committed Jun 1, 2014
1 parent 76193d8 commit f06ff44
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 6 deletions.
9 changes: 9 additions & 0 deletions src/main/resources/js/GalenApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ var session = {
}
};

var galenConsole = {
log: function (object) {
if (typeof object == "string") {
System.out.println(object);
}
else System.out.println(JSON.stringify(object));
}
};

(function (exports) {
exports.createDriver = createDriver;
Expand All @@ -120,4 +128,5 @@ var session = {
exports.cookie = cookie;
exports.inject = inject;
exports.readFile = readFile;
exports.console = galenConsole;
})(this);
4 changes: 2 additions & 2 deletions src/main/resources/js/GalenCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,13 +321,13 @@ function afterTest(callback) {
function retry(times, callback) {
if (times > 0) {
try {
return callback();
return callback(times);
}
catch (ex) {
return retry(times - 1, callback);
}
}
else return callback();
else return callback(times);
}

function createTestDataProvider(varName) {
Expand Down
49 changes: 45 additions & 4 deletions src/main/resources/js/GalenPages.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@

String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g, '');};

function listToArray(list) {
return GalenUtils.listToArray(list);
}

var GalenPages = {
allowReporting: true,
settings: {
cacheWebElements: true,
allowReporting: true,
},
report: function (name, details) {
if (GalenPages.allowReporting) {
if (GalenPages.settings.allowReporting) {
var testSession = TestSession.current();
if (testSession != null) {
var node = testSession.getReport().info(name);
Expand Down Expand Up @@ -108,7 +114,8 @@ var GalenPages = {
return this.parent.findChildren(locator);
}
else {
return this.driver.findElements(GalenPages.convertLocator(locator));
var list = this.driver.findElements(GalenPages.convertLocator(locator));
return listToArray(list);
}
};
this.set = function (props) {
Expand Down Expand Up @@ -205,7 +212,7 @@ var GalenPages = {
this.getWebElement().clear();
};
this.getWebElement = function () {
if (this.cachedWebElement == null) {
if (GalenPages.settings.cacheWebElements && this.cachedWebElement == null) {
this.cachedWebElement = this.parent.findChild(this.locator);
}
return this.cachedWebElement;
Expand Down Expand Up @@ -269,6 +276,40 @@ var GalenPages = {
}
return true;
};
this.findChild = function (locator) {
if (typeof locator == "string") {
locator = GalenPages.parseLocator(locator);
}

if (this.parent != undefined ) {
return this.parent.findChild(locator);
}
else {
try {
var element = this.driver.findElement(GalenPages.convertLocator(locator));
if (element == null) {
throw new Error("No such element: " + locator.type + " " + locator.value);
}
return element;
}
catch(error) {
throw new Error("No such element: " + locator.type + " " + locator.value);
}
}
};
this.findChildren = function (locator) {
if (typeof locator == "string") {
locator = GalenPages.parseLocator(locator);
}

if (this.parent != undefined ) {
return this.parent.findChildren(locator);
}
else {
var list = this.driver.findElements(GalenPages.convertLocator(locator));
return listToArray(list);
}
};
},
create: function (driver) {
return new GalenPages.Driver(driver);
Expand Down

0 comments on commit f06ff44

Please sign in to comment.