How to Convert below Line in Page Object using Protractor - protractor

want to convert below line
rows.element(by.xpath(".//*[#ng-model='strategy.COMMENT']")).clear()
into page object like
rows.dataCatcherPage.strategyAUMValue.clear()
But i am getting the error
"Failed: Cannot read property 'strategyAUMValue' of undefined"
This is the Page object
strategyAUMValue: {
get: function () {
return element(by.xpath(".//*[#ng-model='strategy.AUM_VALUE']"));
}
},

How about this:
page
module.exports = new function () {
var elements : {
strategyAUMValue : element(by.xpath(".//*[#ng-model='strategy.AUM_VALUE']"))
};
this.clear = {
strategyAUMValue : elements.strategyAUMValue.clear()
};
this.getText = {
strategyAUMValue : elements.strategyAUMValue.getText()
};
};
spec
var dataCacherPage = require('./dataCacher.page.js');
describe('Data cacher', function(){
it('can clear the strategy aum value', function(){
dataCacherPage.clear.strategyAUMValue();
expect(dataCacherPage.clear.strategyAUMValue()).toEqual('', 'Strategy AUM Value should have been an empty string');
});
});
This lets your page elements be private(separating your framework layers), but gives you full access to all of the actions a test would be taking. You can expand on it by adding any other elements to the elements section, then adding to any this.clear/getText/isDisplayed type function that the element will need for testing.
Some extensibility:
module.exports = new function () {
var elements : {
strategyAUMValue : element(by.xpath(".//*[#ng-model='strategy.AUM_VALUE']")),
// Get an element where multiple exist
coolElement : $$('[name="coolElement"]')
};
this.clear = {
strategyAUMValue : elements.strategyAUMValue.clear()
};
this.getText = {
strategyAUMValue : elements.strategyAUMValue.getText(),
coolElement : elements.coolElement.getText()
};
};
.
var dataCacherPage = require('./dataCacher.page.js');
describe('Data cacher', function(){
it('can hit multiple elements', function(){
// Just add an index on coolElement to get whichever you want
expect(dataCacherPage.clear.coolElement(2)).toEqual('This is the third cool element on the page', 'Should have gotten the text from the third cool element');
});
});

Related

TinyMCE 5: Autocomplete that can be ignored so you can just type your own entry

I want to help the user author handlebars/mustache templates so when they type a { character, an autocomplete of known template values comes up to assist the user. But the user may not want to choose one of the suggested options, they might just want to continue typing a new template value and terminate it with a }. In the example in the code below, the options "Order Number" and "Delivery Date" are the known autocomplete options, but I want the user to be able to type {Invoice Number} for example.
I've succeeded in make this work in one way. As a user is typing {Invoice Number} I add it to the list of allowed options in the autocompleter fetch function. So the user can get what they want into the document if the click on the suggested option. Clicking fires the onAction function. I want onAction to fire as soon as the user types the closing handlebars character i.e. }.
Here is the code I have tried. I am using TinyMCE 5.
let template = (function () {
'use strict';
tinymce.PluginManager.add("template", function (editor, url) {
const properties = [
{value: "Order Number", text: "Order Number"},
{value: "Delivery Date", text: "Delivery Date"}
];
const insertNewProperty = function(value) {
let property = {value: value, text: value};
properties.push(property);
return property;
};
editor.ui.registry.addAutocompleter('autocompleter-template', {
ch: '{',
minChars: 0,
columns: 1,
fetch: function (pattern) {
return new tinymce.util.Promise(function (resolve) {
let filteredProperties = pattern ? properties.filter(p => p.text.indexOf(pattern) > -1) : properties;
if (filteredProperties.length > 0) {
resolve(filteredProperties);
} else {
resolve([{value: pattern, text: pattern}]);
}
});
},
onAction: function (autocompleteApi, rng, value) {
let property = properties.find(p => p.value === value);
if (!property) {
property = insertNewProperty(value)
}
let content = `{${property.text}}`;
editor.selection.setRng(rng);
editor.insertContent(content);
autocompleteApi.hide();
}
});
return {
getMetadata: function () {
return {
name: "Learning",
url: "https://stackoverflow.com"
};
}
};
});
}());
})();```
You can add a matches function to your callbacks, along with your onAction, this help you do it.
matches: function (rng, text, pattern) {
if(pattern.endsWith('}')){
pattern = pattern.replace('}', '');
/**
* Check if pattern does not match an existing
* variable and do what you want
*/
return true;
}
},
And make sure the function always returns true.

How to give configurable URL in tableau WDC

I am trying to build a tabeau WDC.
this is my code
(function () {
var myConnector = tableau.makeConnector();
myConnector.getSchema = function (schemaCallback) {
var cols = [{
id: "month",
dataType: tableau.dataTypeEnum.string
}, {
id: "value1",
alias: "value1",
dataType: tableau.dataTypeEnum.float
}, {
id: "value2",
alias: "value2",
dataType: tableau.dataTypeEnum.float
}];
var tableSchema = {
id: "testfeed",
alias: "test Feed",
columns: cols
};
schemaCallback([tableSchema]);
};
myConnector.getData = function (table, doneCallback) {
$.getJSON('http://test.com/view?name=test&filters=[{"type":"number","id_equals":["123"]}]', function (resp) {
var feat = resp.DATA,
tableData = [];
// Iterate over the JSON object
for (var i = 0, len = feat.length; i < len; i++) {
tableData.push({
"MONTH": feat[I].month,
"ChargeEntryLag_NUMERATOR": feat[i]. value1,
"ChargeEntryLag_DENOMINATOR": feat[i]. value2
});
}
table.appendRows(tableData);
doneCallback();
});
};
tableau.registerConnector(myConnector);
$(document).ready(function () {
$("#submitButton").click(function () {
tableau.connectionName = "testFeed";
tableau.submit();
});
});
})();
my URL contains some filters as shown in the above code, so if U want to get data for a particular filter I have to hardcode it in URL and the use it.
In other word my URL is static , Is there a way to make it dynamic.
suppose I want the value of 'id' to be 10in my filter, for that I have to go the the WDC code and change it. can it be made configurable.
use tableau.connectionData to pass data. There is an example in this tutorial:
https://tableau.github.io/webdataconnector/docs/wdc_multi_table_tutorial
Typically you'd create a form. When you connect with the WDC in tableau desktop, you put in the URL of your form. The form will store the form vars in tableau.connectData. Your getData can then take those and create a custom Data Source inside tableau desktop for you.
- Mike

Why my filter is not working in v2.ODataModel "read"?

I am using the OData model to read data. But it doesn't work. Check the code below:
getGuid: function(pernr) {
var self = this;
var url = "/PersonalDetailSet?$filter=Pernr eq '00000001'";
self.setBusy(true);
this.oModel.read(url, {
success: function(res) {
// ...
},
error: function() {
// ...
}
});
}
I don't know why the filter in url is not working now?
Check if your OData service supports the $filter query in the first place.
Use the read method correctly:myV2ODataModel.read("/PersonalDetailSet"/* No $filter queries here! */, {
filters: [ // <-- Should be an array, not a Filter instance!
new Filter({ // required from "sap/ui/model/Filter"
path: "myField",
operator: FilterOperator.EQ, // required from "sap/ui/model/FilterOperator"
value1: "..."
})
],
// ...
});
API reference: sap.ui.model.odata.v2.ODataModel#read
API reference: sap.ui.model.Filter
First you check whether you are getting model in the scope or not. As i can see this.oModel which is not proper way of getting model. Better use this.getModel() or this.getView().getModel() and then check the call. Passing filter is not the right way but still it should work.
If you want to apply additional URL Parameters in the read function you have to do this via the "urlParameters" parameter:
getGuid: function(pernr){
var self = this;
var url = "/PersonalDetailSet";
self.setBusy(true);
this.oModel.read(url, {
urlParameters: {
"$filter" : "Pernr eq '00000001'"
},
success: function(res){
self.setBusy(false);
self.guid = res.results[0].Guid;
},
error: function() {
self.setBusy(false);
}
});
}

Can't mongoDB insert in promises function js

I'm actually building a simple application in meteor that's taking a weapon's skin thought my steam inventory, parse the weapon's market hash name, and finally return the median price of the skin according to the steam market. My problem is about storing the price of the skin, I use this npm package that I have included in Meteor (I followed the asynchronous way) and I can easily get the skin's price. I put this code into a Meteor method on the server-side, like this :
Meteor.methods({
getPrice:function(weapon,skin,state,loteryRef)
{
var csgomarket = Meteor.npmRequire('csgo-market');
var Q = Meteor.npmRequire('q');
var wears = [state];
var data = {
prices : [{
weapon : weapon,
cached : false,
skins : [skin],
skinData : {},
price : '',
}]
}
var getPrice = function(theData) {
var promises = [];
theData.skins.forEach(function(skin) {
theData.skinData[skin] = {};
wears.forEach(function(wear) {
promises.push(csgomarket.getSinglePriceAsync(theData.weapon, skin, wear, false).then(function(data) {
theData.price = data.median_price;
}));
});
});
return Q.allSettled(promises).then(function() {
return theData;
});
}
getPrice(data.prices[0]).then(function(results) {
console.log(results.price);
});
}
});
The result of the promise's function getPrice(data.prices[0]).then(function(results) {}); can only be console.logged and I can't save results outside of this function. When I try to perform an insert in this function for saving this value, it doesn't work too. What I'm doing wrong ?
Please forgive me for my quite good English

How to pass model name to angularJS restful api

I am new to AngularJS, but have used Backbone for a while now.
I want to create a reusable restful api that I can pass the model name to so that I can use it for different models.
At the moment I have:
angular.module('healthplanApiServices', ['ngResource'])
.factory('Api', function($resource) {
return $resource(base_url + 'api/:object/:id', {
id : '#id', object : 'actions'
}, {
query : {
method : 'GET',
isArray : true,
callback : "JSON_CALLBACK"
},
save : {
method : '#id' ? 'PUT' : 'POST',
isArray : true,
callback : "JSON_CALLBACK"
}
});
});
... which sets the model as 'actions'. Then in my controller I use:
// get the collection
Api.query(function(r) {
$scope.actions = r;
});
$scope.toggleDone = function(a) {
a.done = !a.done;
//save an item
Api.save(a);
}
That's all fine, but how do I pass the model name ('actions' in this case) for each model type: e.g., instead of putting it in the factory function like so:
id : '#id', object : 'actions'
... but rather something more like:
var ActionApi = Api.setObject('actions');
ActionApi.query(function(r) {
$scope.actions = r;
});
UPDATE:
I just figured out a way. It may not be the best, but it does work. Any other suggestions would be welcome!
Just add the 'object' attribute to the model:
Api.query({object: 'actions'}, function(r) {
$scope.actions = r;
angular.forEach($scope.actions, function(a) {
a.object = 'actions' });
});
Api.save(a);// also works
You may want to try https://github.com/klederson/ModelCore ( ModelCore )
Its easy to model and structure and of course ... to use.
model.$find({ filter : "John" },{},true); //to find all with query parameters
model.$get(1); //to retreive the user with id 1
model.$save()
model.$deelte();
And so on.. checkout the documentation