mirror of
https://github.com/BorysLevytskyi/BitwiseCmd.git
synced 2025-12-10 06:52:05 +01:00
and present it as list of plain js objects. Updated page object assertion method to be simpler.
93 lines
2.6 KiB
JavaScript
93 lines
2.6 KiB
JavaScript
var Key = protractor.Key;
|
|
var By = protractor.By;
|
|
var resultTableReader = require('./resultTableReader');
|
|
|
|
function BitwiseCmdPage(driver, appUrl) {
|
|
this.driver = driver;
|
|
this.appUrl = appUrl;
|
|
}
|
|
|
|
BitwiseCmdPage.prototype.goToApp = function (hashValue) {
|
|
var url = this.appUrl;
|
|
var hash = hashValue || '-notrack';
|
|
|
|
if(hash.indexOf('-notrack') < 0) {
|
|
hash += "||-notrack";
|
|
}
|
|
|
|
if(url.indexOf("#") < 0) {
|
|
url += "#" + hash;
|
|
} else {
|
|
url += "||" + hash;
|
|
}
|
|
|
|
return this.driver.get(url);
|
|
};
|
|
|
|
BitwiseCmdPage.prototype.sendCommand = function(cmd) {
|
|
return this.driver.findElement(By.id('in')).then(function (el) {
|
|
return el.sendKeys(cmd + Key.ENTER);
|
|
});
|
|
};
|
|
|
|
BitwiseCmdPage.prototype.clearResults = function () {
|
|
return this.sendCommand("clear");
|
|
};
|
|
|
|
BitwiseCmdPage.prototype.executeExpression = function(expr) {
|
|
var self = this;
|
|
return this.clearResults().then(function() {
|
|
return self.sendCommand(expr);
|
|
})
|
|
};
|
|
|
|
BitwiseCmdPage.prototype.getLasExpressionResult = function() {
|
|
return this.driver.findElement(By.css('.expression')).then(function(resultElement) {
|
|
return new ExpressionResultObject(resultElement);
|
|
});
|
|
};
|
|
|
|
BitwiseCmdPage.prototype.getAllResults = function() {
|
|
return this.driver.findElements(By.css('.result')).then(function(resultElements) {
|
|
var results = [], i= 0, len = resultElements.length;
|
|
|
|
// TODO: Use _.map
|
|
for(;i<len;i++) {
|
|
results.push(new ExpressionResultObject(resultElements[i]));
|
|
}
|
|
return results;
|
|
});
|
|
};
|
|
|
|
BitwiseCmdPage.prototype.shouldHaveNoErrors = function () {
|
|
return this.driver.findElements(By.css('.result .error')).then(function(els) {
|
|
expect(els.length).toBe(0, "There should be no errors");
|
|
});
|
|
};
|
|
|
|
function ExpressionResultObject(resultElement) {
|
|
this.resultElement = resultElement;
|
|
}
|
|
|
|
ExpressionResultObject.prototype.readResult = function () {
|
|
return resultTableReader.read(this.resultElement);
|
|
};
|
|
|
|
ExpressionResultObject.prototype.shouldBe = function(expectedResult) {
|
|
this.readResult().then(function(actualResult) {
|
|
expect(actualResult.length).toEqual(expectedResult.length, "Unexpected result length");
|
|
var expected, actual;
|
|
for(var i=0;i<expectedResult.length; i++) {
|
|
var actual = actualResult[i],
|
|
expected = expectedResult[i];
|
|
|
|
expect(actual).toEqual(jasmine.objectContaining(expected));
|
|
}
|
|
});
|
|
|
|
};
|
|
|
|
module.exports = {
|
|
BitwiseCmdPage : BitwiseCmdPage,
|
|
ExpressionResultObject: ExpressionResultObject
|
|
}; |