TestCafe does not load the base URL - testcafe

TestCafe does not load the base URL (login page). A blank page is loaded when the base URL is accessed.
fixture('Getting Started')
.page('https://base_url/RRApp/auth/login');
test('My first test', async t => {
await t
.debug()
.typeText('#developer-name', 'John Smith')
.click('#submit-button');
});
The following error was noted in the console.

:51582/HeWNWihUP*hTz…d054cfa21e2582.js:1 Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
:51582/HeWNWihUP*hTz…ac00f42bc3886e.js:1 Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
:51582/HeWNWihUP*hTz…08841904c1a9ce.js:1 Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
scripts.84ac6b0981f52dfb.js:1 Uncaught SyntaxError: Unexpected token '<'
Note
It was possible to access the login page with a normal browser instance
This issue was reproducible with TestCafe Studio recording too
There was no issue in both scenario when different URL was used. e.g. 'https://devexpress.github.io/testcafe/example'

fixture('Getting Started')
.page('https://base_url/RRApp/auth/login');
You do not need to add base_url here. It works automatically.
Take a look at the following test code:
fixture `f`
.page `./RRApp/auth/login`
test(`test`, async t => {
await t.debug();
});
Then, you can run TestCafe using the following command:
npx testcafe chrome test.js --base-url http://example.com
See the following articles for more information:
https://testcafe.io/documentation/402639/reference/command-line-interface#--base-url
https://testcafe.io/documentation/402638/reference/configuration-file#baseurl

Related

Problem downloading package from git actions, results in mangled URL

In our git actions output for testing our custom R package (hosted on github), we're experiencing an error during execution:
Error in utils::download.file(url, path, method = method, quiet = quiet, :
cannot open URL 'https://api.github.com/repos/***/CirceR/contents/DESCRIPTION?ref=HEAD'
Calls: saveRDS ... github_DESCRIPTION -> download -> base_download -> base_download_headers
Execution halted
Error: Process completed with exit code 1.
The main repo is here: https://github.com/OHDSI/CohortGenerator
The github actions report is here: https://github.com/OHDSI/CohortGenerator/runs/3294257207?check_suite_focus=true
The referenced package CirceR is found here: https://github.com/ohdsi/circer
Our main question is: is it normal for the requested URL for the DESCRITPION file to be masked with the *** as in: cannot open URL 'https://api.github.com/repos/***/CirceR/contents/DESCRIPTION?ref=HEAD'
If we change the *** to the actual organization OHDSI for this URL the request works, so is it possible the URL is being mangled?
We've tested loading each individual package locally and this error doesn't occur, so we think it's localized to github actions.
I believe the output is trying to shorten the string so you can see how it starts, and how it ends, but not the middle...for readability purposes. My issue was I wanted the entire contents of the string (other errors in 'shorter' repository names gives the full URL). So, I believe this truncation is by design.
To solve the underlying issue, I had to specify a GIT_PAT to use to invoke the API and that cleared out the error I was getting.

WeChat - Feature policy violation: accelerometer is not allowed in this document

From Angular application we're using on WeChat the last Tencent Captcha API and this error appear in DevTools console (on desktop - windows - Chrome webkit):
[Violation] Feature policy violation: accelerometer is not allowed in this
document.
Unfortunately, there isn't more stacktraces.
It seems Tencent Captcha try to use through iframe the accelerometer browser API which is not allowed from our website. We need to add an HTTP header like 'Feature-Policy : accelerometer ...'
https://developer.mozilla.org/en-US/docs/Web/API/Accelerometer
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Feature-Policy
I don't know where we should add this http header
thks
In your application server you should add a response header called Feature-Policy with a value of one of the following:
"accelerometer *"
"accelerometer 'self'"
"accelerometer 'src'"
The exact allowList argument you provide following accelerometer will depend on your specific circumstances and requirements (re. MDN docs - Feature-Policy: Syntax).
In an application using an Express server, the response header can be set by adding this line in a piece of middleware:
response.set('Feature-Policy', "accelerometer 'self'"
e.g.
// app.js
import express from 'express';
import applyFeaturePolicyHeaderMiddleware from './apply-feature-policy-header-middleware';
const app = express();
app.use(
applyFeaturePolicyHeaderMiddleware
);
// apply-feature-policy-header-middleware.js
export default (request, response, next) => {
response.header('Feature-Policy', "accelerometer 'self'");
next();
}
You can then ensure the Feature Policy is present by checking in the DevTools Network tab that the request for the page document includes the feature-policy header under the Response Headers.

getJson Access-Control-Allow-Origin

I just learned that using getJson with a url from another domain/port will usually lead to cross domain policy problem.
With this code:
var appGetApi = "http://localhost:30028/api/values";
$.getJSON(appGetApi, function (_returnedJson) {
...
});
I get this error:
XMLHttpRequest cannot load http://localhost:30028/api/values.
Origin http://localhost:17437 is not allowed by Access-Control-Allow-Origin.
After searching the web for answers, it seems that adding &callback=? is a famous fix. So i did that.
var appGetApi = "http://localhost:30028/api/values&callback=?";
$.getJSON(appGetApi, function (_returnedJson) {
...
});
But I still get an error:
Failed to load resource: the server responded with a status of 400 (Bad Request)
http://localhost:30028/api/values&callback=jQuery11020629610788077116_1373178114158?_=1373178114159
This is my first time with API and I am completely clueless right now on how to solve this issue. Please help me guys. Thanks.
By default, IIS in W2K3 and above won't serve files that aren't of a MIME type that it knows about (instead returning 404 errors).
You need to add a MIME type to IIS to allow it to serve that type of file. You can set it at the site level or at the server level.
To set this for the entire server:
Open the properties for the server in IIS Manager and click MIME Types
Click "New". Enter "JSON" for the extension and "application/json" for the MIME type.

Using Ext JS with my HTML Files

I have an application uses Spring Security 3(has a Jackson Marshaller) runs on a Tomcat 7. I designed my application with Jquery and it runs well. I designed a login page with Ext JS and after successful login it redirects to index.html. However it gives an error and can't redirect because when server sends HTML file it comes into that function at Ext JS:
Ext.util.JSON = new (function(){
...
doDecode = function(json){
return eval("(" + json + ")");
},
...
I wants to render it as a JSON response and gives an error as usual. How to solve it?
PS: It gives that on Firebug:
syntax error
[Break On This Error] (<!DOCTYPE html>
The server is not returning valid JSON. Its look as if it is returning a HTML page (perhaps a friendly error page). If you follow the stack trace up its probably Ext.decode response.responseText (inspect this you'll see whats returned although not the best way)
First step would be to investigate the request in the Net panel in Firebug or Chrome, look at the request and response headers and content this will point you in the right direction. Please please please do not resolve this problem without first learning to use a client side browser debugger (Firebug or Chrome Dev Tools or even Safari) such as walking the stack on break on error, break on XHR, inspect the XHR headers and response etc.. not just watching the console window.
You might be able to fix this continuing blind but you'll pay heavily again next time.

Custom 404 error without server

Is possible to intercept 404 error without using web server (browsing html file in the filesystem) ?
I tried with some javascript, using an hidden iframe that preload the destination page and check for the result and then trigger a custom error or redirect to the correct page.
This work fine but is not good on perfomance.
A 404 error is an HTTP status response. So unless you are trying to retrieve this file using an HTTP request/response, you can't have a genuine 404 error. You can only mimic one in something like the way you suggest. Any "standard" way of handling a 404 error is dependent on your flavour of web server anyway...
404 is a HTTP response code, and as such only delivered through the HTTP protocol by servers that speak it. The file:// extension isn't a real protocol response as such, it's a hack built into clients (like browsers) that enable local file support, however it's up to browsers / clients themselves whether they expose any response codes from their file:// implementation. In theory they could report them in the DOM, for example, but they would be response codes exposed to themselves, and as such rarely implemented. Most don't, and there isn't a standard way for it. You may look into browser extensions, like Firefox, and see if they support it, but then, this is highly unstandard and will likely break if you pop it on the web.
Why don't you want to use the server?
I don't believe that it's possible to handle a 404 error client-side, because a 404 error is server-side.
Whenever you load a webpage, you make a request to the server. Thus, when you ask for a file that's not there, it's the server that handles the error. Regular HTML/CSS/JavaScript only come into the picture when the server sends back a response to tell you that it can't find the file.
Steve
Because I was looking for this today. You can now do this without a server by using a Service Worker to cache the custom 404 page, and then serve it when a fetch request status is 404. Following the instructions on the google cache lab, the worker files looks as follows:
const filesToCache = [
'/',
'404.html'
];
const staticCacheName = 'pages-cache-v1';
self.addEventListener('install', event => {
console.log('Attempting to install service worker and cache static assets');
event.waitUntil(
caches.open(staticCacheName).then(cache => {
return cache.addAll(filesToCache);
});
);
});
self.addEventListener('fetch', event => {
console.log('Fetch event for ', event.request.url);
event.respondWith(
caches.match(event.request).then(response => {
if (response) {
console.log('Found ', event.request.url, ' in cache');
return response;
}
console.log('Network request for ', event.request.url);
return fetch(event.request).then(response => {
console.log('response.status:', response.status);
// fetch request returned 404, serve custom 404 page
if (response.status === 404) {
return caches.match('404.html');
}
});
});
);
});