My goal is to fetch an input value for a specific operation in protractor. I am attempting to make an ajax request using protractor and need to assign a unique value (referred to as groupCode
) to a JSON object that will be sent to the server.
Initially, I tried setting up a hidden input field that could be manipulated. Here are my attempts:
<div style='hidden' >
<input
id="group-sendgrid-hidden-input"
ng-model='groupCode'
value='{{groupCode}}'
ng-init='groupCode=dangdangdang'
>
</div>
I also attempted to display the model value:
<div style='hidden' >
<input
id="group-sendgrid-hidden-input"
ng-model='groupCode'
value='{{groupCode}}'
ng-init='groupCode=dangdangdang'
>
{{groupCode}}
</div>
I can confirm that the value updates correctly in the Angular console. This means that $scope.groupCode
resolves to 'dangdangdang'. Therefore, the issue lies elsewhere. I aim to retrieve the groupCode string in a protractor test using the following methods:
Here are some of the approaches I've taken:
var groupCodeModel = element(by.model('groupCode'));
var groupCodeBinding = element(by.binding('groupCode'));
var placeholder = groupCodeBinding.getText();
Additionally, I tried getting the value directly like this:
var groupCode = element(
by.id('group-sendgrid-hidden-input')
).getAttribute('value');
// Later on, use it like:
var sendgridData = {envelope: 'what', test: groupCode};
The problem arises as the value of groupCode never seems to become a string no matter what strategy I utilize.
- I'm unable to
console.log(groupCode);
- This fails:
var sendgridDataString = JSON.stringify(sendgridData);
Each attempt results in something like this:
{ ptor_:
{ controlFlow: [Function],
schedule: [Function],
getSession: [Function],
getCapabilities: [Function],
quit: [Function],
actions: [Function],....
Although the desired data is present, I struggle with extracting it as I am relatively new to protractor. Despite the challenges, I find protractor technology fascinating. Thank you for any assistance.
Edit:
I have experimented with the following solutions too:
var groupCode = element(by.id('group-sendgrid-hidden-input')).evaluate('groupCode').then(function(groupCode){
console.log('test: ' + groupCode);
return value;
});
and also:
var groupCode = element(by.id('group-sendgrid-hidden-input')).getAttribute('value').then(function(groupCode){
console.log('test: ' + value);
return value;
});
In the latter approach, groupCode returns:
{ then: [Function: then],
cancel: [Function: cancel],
isPending: [Function: isPending] }
It still proves challenging to obtain a simple string like groupCode = 'just some words'
, which is necessary for passing to another function.
While I believe achieving this is possible, the process is becoming frustrating. I will persevere and continue studying the documentation.