How to call window object method in Cypress? - cookies

I'm trying to call this method "window._e2e_cookie_popup_actions.acceptAll()" which basically sets the cookie policy in local storage.
When I call this method on browser console, it works perfectly.
However, when I try this on Cypress, it says "TypeError: Cannot read properties of undefined (reading 'acceptAll')"
This is how I tried on Cypress
cy.window().then((window)=>{
window._e2e_cookie_popup_actions.acceptAll()
})
Expection: If this method is called, the cookie should be set.
Thank you in advance!

Related

Postman variables are undefined

I've just created an account and am using web.postman.co. The online version. I didn't actually notice if the desktop client is still available
In my Postman workspace I've created an environment and there I've created a bunch of variables to match my vendor API auth request (Wialon). The values are pasted below:
[{"key":"hostname","value":"some.address","enabled":true,"sessionValue":"some.address","sessionIndex":0},
{"key":"auth_username","value":"wialon","enabled":true,"sessionValue":"wialon","sessionIndex":1},
{"key":"auth_password","value":"abc123!","enabled":true,"sessionValue":"abc123","sessionIndex":2},
{"key":"auth_token_duration","value":"2592000","enabled":true,"sessionValue":"2592000","sessionIndex":3},
{"key":"auth_client_id","value":"wialon","enabled":true,"sessionValue":"wialon","sessionIndex":4},
{"key":"auth_redirect_uri","value":"login.html","enabled":true,"sessionValue":"login.html","sessionIndex":5},
{"key":"auth_response_type","value":"token","enabled":true,"sessionValue":"token","sessionIndex":6},
{"key":"auth_access_type","value":"0x200","enabled":true,"sessionValue":"0x200","sessionIndex":7},
{"key":"auth_activation_time","value":"0","enabled":true,"sessionValue":"0","sessionIndex":8},
{"key":"auth_flags","value":"0x2","enabled":true,"sessionValue":"0x2","sessionIndex":9}]
I've then added a collection which currently has one action Get - Login. This action is pointing at the Environment created earlier. I can see it in the left of the document bar. The URL is as follows:
http://{{hostname}}/login.html?client_id={{auth_client_id}}&access_type={{auth_access_type}}&activation_time={{auth_activation_time}}&duration={{auth_token_duration}}&lang=en&flags={{auth_flags}}&user={{auth_username}}&redirect_uri={{auth_redirect_uri}}&response_type={{auth_response_type}}&css_url
The first error I get, and the most confusing for a new user is
GET https://undefined/get?client_id=undefined&access_type=0x200&activation_time=0&duration=undefined&lang=en&flags=0x1&user=wialon&redirect_uri=login.html&response_type=token
Error: DNSLookup: ENOTFOUND undefined
Most of the variables are undefined. This causes the DNS error, but there's no explanation of why they are not defined. They're clearly set in the environment pane and when hovering over in the action parameters.
The second error, and probably related is:
JSONError: Unexpected token u in JSON at position 0
Error: DNSLookup: ENOTFOUND undefined
This is probably due to the word undefined starting with a 'u'
Why are my variables undefined? How do I fix it?
edit: Requested screenshots
Action page
Environment Page
Post run errors
Edit: Additional testing
I cloned the action and removed all variable references, hardcoding values in the properties page. Running this gave back the same undefined errors.
After that I tried copying the URL and placing it in the browser address bar. This worked. There was a manual prompt to enter a password, but the url after that returned the access_token as described. Here is the API ref

findRecord() returns error but record is returned properly

I have a strange error when calling data store's findRecord() function. Below is the function call inside of a route,
return this.get('store').findRecord('restaurant', params.restaurant_id);
And here are the errors I get,
vendor-6605726….js:10 Error while processing route: admin.restaurants.show e.getRecord is not a function TypeError: e.getRecord is not a function
vendor-6605726….js:8 TypeError: e.getRecord is not a function
The strangest thing is that the function works as it should since I can see using ember inspector that the query executes properly and returns the correct record. I have an index route that calls findAll() that does not throw any errors. I am formatting my json correctly I believe so I am out of ideas on what this could me.
Here is the json,
{"data":[{"type":"restaurants","id":1,"attributes":{"user_id":1,"name":"###########","address":"","phone":"##########","website":"##########","created_at":"2017-03-19 20:42:02","updated_at":"2017-03-19 20:42:02","description":"###########"}}]}
I recently had the same issue. It is highly likely that the JSON payload returned by your API isn't formatted correctly. Remember that findRecord() expects a single object to be returned, not an array:
{"data": {}}
not
{"data": []}
Double-check DevTools to see what your API returns to the client - make sure it's not an array.

Ember.js - Function finished before store is done

I'm building an ember app, and I keep running into the same problem where I make a call to the store, but the function keeps compiling before the store has retrieved the data from the backend. Specifically I'm having the problem with a findRecord. I've implemented it both ways:
var admin = this.store.findRecord('admin', 1);
console.log(admin.get('season'));
console.log('Are we here?');
and
this.store.findRecord('admin', 1).then(function(admin) {
console.log(admin.get('season'));
});
console.log('Are we here?');
In both cases, the Are we here? is logged BEFORE the season. Obviously the console logs are just for the example, and it creates an actual problem with what I'm trying to get done. Does anybody know a simple fix for this delay?
Thanks.
Of course it is. It's an asynchronous behavior. It takes some time to solve promise which is returned from findRecord(), thus the consequence is:
this.store.findRecord(); //synchronous
console.log('we are here'); //synchronous
in the meantime a promise returned from findRecord() gets resolved (asynchronous behavior)
console.log(admin.get('season'));
An asynchronous call will not stop your code from progressing, that´s the purpose of it. Else it would block UI updates and user interaction while loading data.

Laravel 5.1 PhpUnit Delete method not working

I am writing a simple test to create an element, see if it is there and then delete it to verify the integrity of my web app every time I build it.
I have a test:
$this->visit('admin/menu/samples')
->seePageIs('admin/menu/samples')
->click('New Sample')
->seePageIs('admin/menu/samples/new/create')
->type('test1', 'name')
->type('test2','description')
->type('test2','introduction')
->select(1, 'scenario_id')
->type('test','slug')
->press('Add')
->seePageIs('admin/menu/samples')
->delete('admin/menu/samples/'. \App\Sample::whereSlug('test')->first()->id )
->visit('admin/menu/samples')
->dontSee('test1');
it creates the Sample element fine, but as I have several Delete buttons ( for every Sample element in index, as they are in a list) I can't use the method click/press('Delete'). So I thought I'd just use the delete method, which I have already set up. The problem is that it will not delete the element that I have created. The delete request will not work.
I assure you that the route is there and the if I just press the Delete button my Sample element will be deleted.
Why can't I mimic this with PHPUnit, is there another way to delete?
I just had this same exact issue. Turns out its the CSRF token issue. Anytime you do a request other than the "GET" request, you will need to verify your CSRF token. Now Laravel does a good job already doing this when you are on the website itself, which is why submitting forms via "press" will work: http://laravel.com/docs/5.1/routing#csrf-protection. In my specific case, it seems my token is generated via an XSRF-Token cookie, which can be done via a simple check of the Request Headers.
However, if you use the url, you will need to generate a CSRF token manually. To do this, simply call csrf_token() and inject it into your call:
$this->visit('admin/menu/samples')
...
->delete('admin/menu/samples/'. \App\Sample::whereSlug('test')->first()->id,
['_token'=>csrf_token()],[] )
...;
Here was the article that helped me figure out how to inject the token, though dont confuse the method signatures of $this->call and $this->delete:
http://davejustdave.com/2015/02/08/laravel-5-unit-testing-with-csrf-protection/

Handlebars.SafeString() issue in Meteor?

I have did a sample example of dynamic loading templates using the Handlebars.SafeString(). Everything works fine expect Refresh the browser URL. When ever refresh the browser url i get an error i.e "Uncaught TypeError: Property 'undefined' of object # is not a function".And this error get only this line i.e return new Handlebars.SafeString(Template[Session.get('currentTemplate')]({dataKey: 'somevalue'}));. With out this line Works fine everything even Refresh also.I am using this Handlebars.SafeString() is to load templates dynamically. I didn't have any idea about this So please help me how to?.
And What is the use of dataKey in above Handlebars.SafeString()?
It looks like the Session dict is not populated when the call is made, and therefore Session.get('currentTemplate') is undefined. A simple safeguard should fix the problem, assuming you're in a reactive context:
if(! Session.get('currentTemplate')) return '';
return new Handlebars.SafeString(Template[Session.get('currentTemplate')]({dataKey: 'somevalue'}));