I'm building Protractor tests and am seeking to refactor some code.
This line of code works fine:
element.all(by.css('div.modal-content ly-input input')).first().sendKeys("Workflow 1");
Then I tried doing this:
var name = element(by.css('div.modal-content ly-input'));
element(name).all(by.css('input')).sendKeys("Workflow 1")
There is something wrong with this last line of code, as I'm getting a "Failed: Invalid locator" error.
Might anyone know how I can introduce the name variable and use it in the last line of code?
Robert
My apologies, I finally figured it out:
name.all(by.css('input')).sendKeys("Workflow 1")
I see you figured it out. Here is how I write my sendKeys in order to have more clarity when I read my code:
var name = 'Workflow 1';
var input = element.all(by.css('div.modal-content ly-input'));
input.first().sendKeys(name);
// or if you have multiple inputs in that element above
var workflowData = {
name: 'Workflow 1',
description: 'a workflow',
type: 'simple'
}
var input = element.all(by.css('div.modal-content ly-input'));
input.get(0).sendKeys(workflowData.name);
input.get(1).sendKeys(workflowData.description);
input.get(2).sendKeys(workflowData.type);
Related
hi below my code example. Is there a way to reduce the number of lines of code and save time?
example.. using function.. i need any other method. please help
enter image description here
Yes. You can get the list by name from globals(). See the example below:
list1 = []
list2 = []
msg = {
'type': 2
}
def addToList(listNumber, msg):
globals()["list" + str(listNumber)].append(msg)
for key, val in msg.items():
if key == 'type':
addToList(val, msg)
print(list1) #[]
print(list2) #[{'type': 2}]
I can't understand the difference. What is wrong here? Whenever I write it like this in pug—
-const users =[
{
"key":"Property",
"key":"Property",
}];
—it throws an error. And when I write it like this—
-
const users =[
{
"key":"Property",
"key":"Property",
}];
—it does not throw errors and gives the right result.
Please help me if you know the difference.
Unbuffered code in Pug must either all be on one line, or it must all be indented beneath a hyphen (-), with the hyphen on a line by itself.
// this is ok
- let users = ['foo', 'bar']
// this is also ok
-
let users = [
'foo',
'bar'
]
// this isn't ok
- let users = [
'foo',
'bar'
]
Placing content beside the hyphen signals to Pug that the code is all on one line, and it doesn't treat the next line as code, even if it's indented.
I have the following result from database (using sequelize), the result:
JSON from the database:
[{"codSparePart":"SP001","name":"NAME","description":"DESCRIPTION","codProject":1,"available":1,"codManufacturer":1,"stock":4,"manufacturer.name":"MAN1","manufacturer.description":"DES1","manufacturer.codManufacturer":1}]
In the controller I do the next:
vm.spareParts = data.data;
console.log('-------- ' + JSON.stringify(vm.spareParts));
for (var i = 0; i < vm.spareParts.length; i++) {
vm.items.push({
codSparePart: vm.spareParts[i].codSparePart,
name: vm.spareParts[i].name,
description: vm.spareParts[i].description,
available: vm.spareParts[i].available,
codManufacturer: vm.spareParts[i].codManufacturer,
nameManufacturer: vm.sparePart[i]['manufacturer.description'],
stock: vm.spareParts[i].stock,
codProject: vm.spareParts[i].codProject
});
All is working perfectly except in reading the variables with dot.
nameManufacturer: vm.sparePart[i]['manufacturer.description']
nameManufacturer: vm.sparePart[i]['manufacturer.name']
How can I read these variables, I'm looking for the solution but I think is too simple and there is not any information about it.
Thanks in advance for your help.
You have a typo, change vm.sparePart to vm.spareParts
This line: nameManufacturer: vm.sparePart[i]['manufacturer.description'],
Your code seems to be working perfectly:
const array =[{"codSparePart":"SP001","name":"NAME","description":"DESCRIPTION","codProject":1,"available":1,"codManufacturer":1,"stock":4,"manufacturer.name":"MAN1","manufacturer.description":"DES1","manufacturer.codManufacturer":1}]
console.log(array[0]['manufacturer.description']);
More information: How to get JSON objects value if its name contains dots?
Can anyone tell me why this bit of code doesn't create an entry into localstorage?
myLocalStore.load();
var now = new Date();
var cardId = (now.getTime()).toString() + (this.getRandomInt(0, 100)).toString();
var entry1 = { id: cardId, dateCreated: now, title: 'The Title', narrative: 'the Text' };
var newRecord = new PinYin.model.Default(entry1);
myLocalStore.add(newRecord);
myLocalStore.sync();
console.log(entry1);
The console outputs
Object{id: "136575772251069", dateCreated: Fri Apr 12 2013 17:08:42 GMT+0800 (Taipei Standard Time), title: "The Title", narrative: "the Text"}
which is the correct format so im not sure what I'm doing wrong...
if I replace myLocalStore.add(entry1); with myLocalStore.add('value');
then i'll get the following inputted into the local storage
{"id":"ext-record-1","dateCreated":null,"title":null,"narrative":null}
I faced the same situation and found the solution like that,
First of all, if you set "idProperty" field of model, remove it.
After that, use the following convention.
myOfflineStore.add([{ listItemId: record.data.listItemId,
listItemTitle: record.data.listItemTitle,
listItemImageCode: record.data.listItemImageCode,
listItemNewPostCount: record.data.listItemNewPostCount }]);
Using [, ] is the key point.
EDIT: If you want to use idProperty, then you need to set the newly added record as "phantom" with setting phantom = true
Try like this...
var airline_name = res[i].AirLineName;
localStorage.setItem("AirlineCode3two",record.get('AirlineCode32'));
var stored_locally2 = {'ID2': i,'AirLineName2': res[i].AirLineName,};
//Adding our array to LocalStore(localStorage)
var localstore2 = Ext.getStore('TwowayStorage');
var twowayc1=localstore2.getCount();
localstore2.add(stored_locally2);
localstore2.sync();
localstore2.load();
since a few hours i'm trying to implement the twitchAPI in my cake projet. a long time ago i made this little script in basic php.
$channelName = "gamespot";
$json_file = #file_get_contents("http://api.justin.tv/api/stream/list.json?channel={$channelName}", 0, null, null);
$json_array = json_decode($json_file, true);
#$json_array[0] && $json_array[0]['name'] == "live_user_{$channelName}";
#$title = $json_array[0]['channel']['status'];
#$game = $json_array[0]['meta_game'];
#$chanel_view = $json_array[0]['channel_count'];
#$totalchanelview = $json_array[0]['channel_view_count'];
but i don't know how to add this lines on my controller
For know i've just find this
public function twitch() {
$json = file_get_contents('http://api.justin.tv/api/stream/list.json?channel=manvsgame');
$twitch = json_decode($json);
$totalchanelview = $twitch[0]['channel_view_count'];
$this->set('twitch', 'totalchanelview');
}
but of course i've this error
Fatal error: Cannot use object of type stdClass as array in /Users/*/Desktop/Websites/**/app/Controller/UsersController.php on line 29
anyone can explain to me how i can use this API?
thanks in advance and have a nice day/night :)
okey first thanks to help me. i still have a little "logic problem"
my function is something like that:
public function twitch() {
$json = file_get_contents('http://api.justin.tv/api/stream/list.json?channel=gamespot');
$twitch = json_decode($json, true);
$this->set('json', $twitch);
}
but know, what can I write to my view to see my informations (like the title of my stream for exemple.
I test with
echo $twitch[0]['title']; (it's my line 1)
bit i've this error
Notice (8): Undefined variable: twitch [APP/View/Users/admin_dashboard.ctp, line 1]
$twitch = json_decode($json, true); // add true param
$twitch[0]['channel_view_count'];
adding true returns the data as an associated array instead