I am running the testcafe tests for a website. I want to avoid writing any browser cookies while running my testcafe tests. My website writes cookies but while running tests I want to avoid this. Is there any way to achieve this in testcafe?
To disable cookies in the Google Chrome browser, follow these steps:
Find the 'Preferences' file in the Google Chrome profile and specify 2 as the profile.default_content_settings.cookies key value.
Specify the :userProfile flag after the browser alias.
testcafe 'chrome:userProfile' /tests
If you want to have no cookies at the start of a test, note that TestCafe automatically clears cookies before each test is started.
You can use Role if you want to clear cookies at some point of your test scenario, for example, if you want to authenticate as a different user.
If your scenario is more complex, take a look at RequestMock and RequestHook - they allow you to control any aspect of all requests and responses during a test session.
Related
I just build Login Test case for a native mobile app on iOS using Appium.
On first run, when test cases logs in the user. it does not clear the cookies.
when I re-run the test, it installs the app but keeps the user logged in. I need to clear cookies after all tests run. I kept below in after class but:
driver.manage().deleteAllCookies() is not supported
how should I clear all cookies?
If you need to reset the application to it's base state, consider resetting the app at the each session start.
capabilities.setCapability("fullReset","true");
More information on fullReset can be found in https://appium.io/docs/en/writing-running-appium/other/reset-strategies/index.html
I would like to get full URLs inside emails that get triggered by my tests in CakePHP 3.2. I tried with the full-options for $this->Html->image('image.jpg', ['fullBase' => true]) and $this->Url->build('/', true) but they don't seem to work in tests.
How can I force full URLs in emails while testing?
There is no host when running an app in the CLI environment as it's not a web request. You'll have to configure the base URL on your own.
Quote from the docs:
App.fullBaseUrl
The fully qualified domain name (including protocol)
to your application’s root. This is used when generating absolute
URLs. By default this value is generated using the $_SERVER
environment. However, you should define it manually to optimize
performance or if you are concerned about people manipulating the Host
header. In a CLI context (from shells) the fullBaseUrl cannot be read
from $_SERVER, as there is no webserver involved. You do need to
specify it yourself if you do need to generate URLs from a shell (e.g.
when sending emails).
So you can either configure it via App.fullBaseUrl
Configure::write('App.fullBaseUrl', 'http://localhost');
or a little more specific so that it only applies to the router, via Router::fullBaseUrl()
Router::fullBaseUrl('http://localhost');
You can either configure it in your application configuration (config/app.php), so that even on regular web requests your app isn't building it dynamically anmore, and consequently have it available in the test environment too, or, if you just want to apply to the test suite, put it either in your tests bootstrap (tests/bootstrap.php) to have it apply globally, or set it in your individual test case files.
That's what the CakePHP core test suite is doing it too btw. Whenever you're unsure, having a look at the core tests might give you a hint.
See also
Cookbook > Configuration > General Configuration
API > \Cake\Routing\Router::fullBaseUrl()
https://github.com/cakephp/cakephp/blob/3.2.13/tests/bootstrap.php#L70
https://github.com/cakephp/.../blob/3.2.13/tests/TestCase/Routing/RouterTest.php#L74
https://github.com/cakephp/.../3.2.13/tests/TestCase/Routing/RouterTest.php#L520-L529
I am using SoapUI for automated web services testing. For me to access this particular GET endpoint, I need to get a randomly generated key by going to a website, hit generate button, and copy the key, and paste it into the Authorization header value. However, this needs to be done through automatically after a build and not manually. Is this possible?
Try to get the api or request which generate the authorization code. For that you can use a proxy monitor tool like fiddler, chrome F12 network panel or any.
Once monitored, i hope you know how to implement it on soapui.
Or,
You can use selenium jar as an external jar and use selenium code in groovy script to open the browser > get the authorization code > getText from the element, so you can store in a variable and reuse it anywhere you want.
Hope this helped.
I have a web page made with HtmlServices.
This page has a form I want to submit to a GAS web app made to behave as a web service.
When I use google app script UrlFetch to call my web service from my first GAS app, I very often get a timeout. Unfortunately we cannot set the GAS UrlFetch timeout value which I think is around 10s. 10s is not enough for a GAS app to copy a file, open/edit a spreadsheet and send an email!
So I decided to use Jquery and do an ajax post (because I can set the timeout value) within my web page built with HtmlServices. (so my page is sanitized by Google Caja). Jquery is said to be supported by Caja.
But I noticed that the Ajax URL is always rewritten to be the first web app URL (the url I want to post to is changed by Caja I assume). Seems to me that Google's Caja is preventing that Ajax call.
I could not find anything on Caja / Ajax post limitations within a GAS HtmlService.
Would you have suggestions on how to call a web service from a GAS Web App, without having the limitation of the GAS timeout?
The best suggestion I can give for right now is to use JSONP instead of Ajax to make the call. You should not see timeouts in that case, and it should work fine.
Couple of things
AJAX calls (with jQuery or vanilla JS) from a web app deployed on script.google.com to a content service deployed on script.google.com does not work. I've confirmed this and I believe this is a security restriction. I tried a few different workarounds and this looks like there is no short term options.
Regarding the server side option with UrlFetchApp. I believe the timeout is actually 30 seconds. However, that might still not be enough and it looks you are running into frequently enough.
So basically the 3rd (less optimal) option that I would recommend is a "queue" based approach. In this approach - have your HTML web app call a ScriptDb queue. Then you can have a timed trigger (every minute or every hour) that runs as you to perform the requisite operations. Just share the same script library between both scripts so you can share the script DB reference for the queue.
According to this answer from Eric Koleda, Caja was removed from Google Apps Script, but still the client-side code passed to the HtmlService is satinized some way and still there are restrictions. From https://developers.google.com/apps-script/guides/html/restrictions
HTTPS required for active content
"Active" content like scripts, external stylesheets, and XmlHttpRequests must be loaded over HTTPS, not HTTP.
I'm attempting to use qUnit to perform some unit testing that requires the screens generated by my web app to run. My idea is to put my application into an iframe embedded in my qUnit test page. However this does not seem to work (in chrome) I don't seem to be able to access the web app's iframe. If I do this in chrome's console I get undefined:
frames['myApp'].document
I think this is to do with some kind of cross domain scripting security but, both my web app and my test page are being served from localhost so I don't see why this is occurring, also I have started Chrome with the --disable-web-security parameter but this has not fixed.
Is there a better way to do unit testing that requires output from my application?
You can try publish these tests on localhost by any simple http server, for example if you have a node you can use https://github.com/nodeapps/http-server.
I have a similar situation tests are running in iframe and this work without problems.