Protractor: Extracting URL value from an element and using URL to open new browser instance - protractor

I am trying to do following:
get element(div in this case) containing a URL for eg.
`ele = "www.xyz.com".
Use getAttribute('value') or getText() to
grep URL
Use this URL to fork new instance of browser and GET the
URL
newBrowser = browser.forkNewDriverInstance();
ele.getAttribute('value').then(function(val){
newBrowser.get(val);
});
and I am getting following error:
RangeError: Maximum call stack size exceeded
Second method I tried was without promise and got the error saying that url should be string and not object.
As in:
var url = ele.getText();
newBrowser.get(url);
Is there a way to convert the object returned by getText() into a string and store into variable so that it can be used in some other place.

In your second appraoch, ele.getText() will give you a promise that needs to be resolved. You can resolve the promise on the second approach by using something like this-
ele.getText().then(function(url){
newBrowser.get(url);
})
If this does not work, try printing url with console.log(url). I think it is an object array and you need to get the item you need by referring to the index like url[0] or url[1]. try using console log to print all these values.

Related

How can I use the return from a axios http request in nest js

this return an Observable, and i want to iterate over the result
how can I do that?
I used firstDataValue instead of PiPe.
So the error was that the API was sending me back the data as a string, and I wanted the iterate over the result and I couldn't. So I use JSON.parse(data).
The result was:
let data=firstValueFrom(await this.httpService.get("url")).data;
let dataParsed=JSON.Parse(data);//this was the error cause the api was sending strign
return dataParsed[0]

How to pass a map as query parameter

I'm using labstack Echo (v4.1.11) go framework to create a REST API.
How do we/can we pass map query param in the URL? I tried adding the following struct for the request body
PaginationRequest struct {
Page int64 `query:"page"`
Limit int64 `query:"limit"`
Filter map[string]string `query:"filter"`
}
and hoping I could got this url http://host/endpoint?page=1&limit=10&filter[status]=1&filter[user_id]=12 to work (read the filter["status"] and filter["user_id"]
But when I tried binding the incoming request to PaginationRequest it only read the page and limit parameter and filter = nil
I tried debug it into the echo/bind.go the Bind function in reading the QueryParam actually read filter[status] as plain string "filter[status]" as key.
Is there anyway we can pass the map to the url query param? or we really have to be specific in here?

play framework - redirecting with querystring

I am Using the play Framework 2.7.x
I have a Formular on my controller.list() with a view, let's call it "index". After you click "send" it open's controller.add() where it dos some stuff and then redirects back to controller.list(). If there was an error in the formular (a requiered field was empty) I need the queryString, which was send to controller.add() also redirected to controller.list()
The problem ist that if I do stuff like just passing the request, i get an error that it's not possible to add arguments.
public Result list(Http.Request request)
{
// .... stuff with foo, while foo is an Form<foo> Object
// ... foo.bindFromRequest(request)
ok(views.html.index.render(foo))
}
public Result add(Http.Request request)
{
// not allowed to add request as an argument. only empty is allowed.
return Results.redirect(controllers.routes.Controller.list(request));
}
I would like to just redirect the Form object, so I can handle the error in the controller.list() and not have to generate an extra view for the controller.add(). If I do everything inside controller.list() there is no problem with this code, but I like to use the controller.add() method instead.
Is the an option? except passing every querystring key and value by hand.
After I searched yesterday the half the day, I found something interessting today.
you are not allowed to use a default parameter with =. You have to use an optional default parameter with ?= inside the routes!!!!!
you can implement QueryStringBindable so it's a bit easier to bind the query String. But you still have to bind them "by hand".

How to access invoke response object variable in following steps of assembly

the assembly of my API Connect API contains two invokes. The first is calling an internal routing API to get some routing information. The response of this routing API should not be passed to the second invoke.
If I do not configure a 'response object variable' in the invoke of the routing API, the original request body is overwritten and the second API gets the result from the routing API as request body. And if I specify a 'response object variable' in the routing invoke, I can not access the content (json) of this variable in the following steps.
How can I solve this issue?
Thx 4 help.
Rather than relying on reading the request object, you can read from your configured 'response object variable' later on in the flow. For instance, if your first invoke has a response object variable set to 'resp1', you can access the JSON payload using '$(resp1.body)' later on in the flow. Using this technique will allow you to store the response of each invoke in a separate object, avoiding the overwriting issue. These response object variables can be read just like any other context variable in the flow.
For more info, check out these links in the Knowledge Center:
Invoke Policy: https://www.ibm.com/support/knowledgecenter/en/SSMNED_5.0.0/com.ibm.apic.toolkit.doc/rapim_ref_ootb_policyinvoke.html
Context Variables:
https://www.ibm.com/support/knowledgecenter/SSMNED_5.0.0/com.ibm.apic.toolkit.doc/capim_context_references.html
I don't understand this part:
[...] "And if I specify a 'response object variable' in the routing
invoke, I can not access the content (json) of this variable in the
following steps." [...]
Why can't you access the content of this variable in the following steps?
Save copy of the request...
... that you received. What I'd do is always save a copy of the data received in the invoke to a processed variable instead of the (raw) original request.
In your GatewayScript try something like this:
let objRequest = apim.getvariable("request");
let body = null;
Here I recommend you to change the body (if json) to a standard js object
if(objRequest && objRequest.hasOwnProperty("body")){
try{
body = JSON.parse(objRequest.body);
}catch(e){
body = objRequest.body;
}
}
Remember to stringify the complete object before saving it as global variable. Is the only way to store it (because you can only store a string value in this kind of variables)
apim.setvariable("objRequest", JSON.stringify(objRequest));
Retrieve copy of the request...
...that you have saved in global variables you can get it from any other GatewayScript that you want this way:
let objRequest = JSON.parse(apim.getvariable("objRequest"));
Be careful not to assign an existent name to the apim.setvariable(name, value) because if you use "request" as name instead of "objRequest" (or other), you'll be replacing the original request element, and we don't want that to happen.
If you need to set or retrieve the status.code...
...you can do it with:
let statusCode = objRequest.body.status.code;

Using save or put with Restangular results in "undefined" being included in URL

I am using Restangular to download an object, update it and then attempt to save back to the server using the save method. Here is the code that retrieves the object:
Restangular.one("survey", surveyID).getList().then (
function (response) {
$scope.survey = response[0];
}
);
This sets $scope.survey to a properly "restangularized" object, with the fields that come back from the GET request, along with the methods like save, put, etc.
If I then invoke the following function after making some edits to the $scope.survey object:
$scope.saveChanges = function () {
$scope.survey.save();
};
restangular tries to use the URL /survey/1/undefined for the PUT request (1 is the correct ID for the object).
My survey object doesn't have an id field (it's surveyID instead), and so I suspected this might be the problem. However, replacing the surveyID field with an id field changed the URL to be /survey/1/undefined/1
I have stripped down the object returned by the GET request to be just primitives, and this does not change the situation.
Why is the incorrect route being generated?
II discovered the problem was actually with the REST service; when called with GET /surveys/1, it was returning an array with a single object in it, rather than returning the object itself.
I think this caused restangular to think that a collection was being accessed (note that I was having to call getList rather than get in order to get a properly restangularized object).