I am trying to read an input for an operation in protractor. I'm trying to send an ajax request from within protractor. I need to send a unique value (which I'm calling groupCode
) to a part of a JSON object that I want to send to the server.
So first I tried setting up a hidden input that could be updated. I have tried:
<div style='hidden' >
<input
id="group-sendgrid-hidden-input"
ng-model='groupCode'
value='{{groupCode}}'
ng-init='groupCode=dangdangdang'
>
</div>
Also this attempt to read the model value:
<div style='hidden' >
<input
id="group-sendgrid-hidden-input"
ng-model='groupCode'
value='{{groupCode}}'
ng-init='groupCode=dangdangdang'
>
{{groupCode}}
</div>
Now, I can see in the Angular console that this value updates as I except. Meaning that $scope.groupCode
does resolve to 'dangdangdang'. So I don't thing this is the issue. From here, I'm hoping to read the groupCode string in a protractor test as followed:
Here is some of what I've tried:
var groupCodeModel = element(by.model('groupCode'));
var groupCodeBinding = element(by.binding('groupCode'));
var placeholder = groupCodeBinding.getText();
also in an attempt to get the value in a more direct way (I think)
var groupCode = element(
by.id('group-sendgrid-hidden-input')
).getAttribute('value');
// and then later I want to do this:
var sendgridData = {envelope: 'what', test: groupCode};
The problem is that no matter what I try the value of the groupCode data never seems to resolve to a string.
- I'm not able to
console.log(groupCode);
- This fails:
var sendgridDataString = JSON.stringify(sendgridData);
Every time I get something like this:
{ ptor_:
{ controlFlow: [Function],
schedule: [Function],
getSession: [Function],
getCapabilities: [Function],
quit: [Function],
actions: [Function],....
And I'm sure the data I need is here, I'm just too new to protractor to figure it out. It is dope tech, however. Thank you.
Edit:
I have now also tried:
var groupCode = element(by.id('group-sendgrid-hidden-input')).evaluate('groupCode').then(function(groupCode){
console.log('test: ' + groupCode);
return value;
});
as well as :
var groupCode = element(by.id('group-sendgrid-hidden-input')).getAttribute('value').then(function(groupCode){
console.log('test: ' + value);
return value;
});
And in this second one, groupCode returns:
{ then: [Function: then],
cancel: [Function: cancel],
isPending: [Function: isPending] }
Is still seems impossible to just get a string like groupCode = 'just some words'
. Which is what I need to hand to another function.
I know this must be possible, but it is driving me to maddness. I will continue to read the docs.