pa11y-ci fails to find HTML element - pa11y

I am trying to test the accessibility of the login experience of a website I am working on using pa11y. I am using pa11y-ci with the config below but can't seem to get it to work:
{
"urls": [
{
"url": "https://somewhere/home",
"actions": [
"set field #email to jondoe#somewhere.com",
"click element #passwordsignin",
"wait for url to be https://somewhere/password"
],
"timeout": 60000
}
]
}
It fails with the following error:
Error: Failed action: no element matching selector "#email"
I can see the input with id #email is in the HTML (based on the code and inspecting the HTML). I suspect the problem is that the tests are run before the input is rendered in the DOM (it is a single page application written in React). I tried to add something like below to the actions:
"wait for element #email to be added"
But it didn't work. I get the following error:
Error: Evaluation failed: EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "default-src 'self'".
at new Function (<anonymous>)
at waitForPredicatePageFunction (<anonymous>:2:21)
Any help would be greatly appreciated, many thanks.
(FYI I am able to run the example listed here without any problems)

Related

Blank pdf output using jsreport

I know this has got to have some super easy answer but I am just beginning with this stuff and followed this tutorial: https://jsreport.net/blog/pdf-reports-in-sql-server
Except it gives me a blank page as an output with no real error message.
I'm using handlebars and chrome-pdf to do this...
My database connection script is:
const sql = require('mssql');
const config = {
"user": "user",
"password": "password",
"server": "server",
"database": "database"
}
async function beforeRender(req, res) {
await sql.connect(config)
const sqlReq = new sql.Request();
const recordset = await sqlReq.query(
`SELECT DBVersion
,MinAppVersion
FROM VersionTbl`
)
Object.assign(req.data, {Versions: recordset });
}
I can see it running and connecting properly in the debug tab... and my sql query seems to be correct if I test it directly in the database server.
My template looks like this:
<table>
{{#each Version}}
<tr>
<td>{{DBVersion}}</td>
<td>{{MinAppVersion}}</td>
</tr>
{{/each}}
</table>
The debug log...
+0 Starting rendering request 27 (user: null)
+2 Rendering template { name: PQRTemplate, recipe: chrome-pdf, engine: handlebars, preview: true }
+2 Data item not defined for this template.
+9 Resources not defined for this template.
+10 Executing script Connection using dedicated-process strategy
+779 Base url not specified, skipping its injection.
+780 Rendering engine handlebars using dedicated-process strategy
+937 Compiled template not found in the cache, compiling
+951 Executing recipe chrome-pdf
+1041 Converting with chrome HeadlessChrome/79.0.3945.0 using dedicated-process strategy
+1115 Page request: GET (document) file:///C:/Users/********/AppData/Local/Temp/jsreport/autocleanup/264c975a-9ef2-4130-960c-84eeae2ec04a-chrome-pdf.html
+1122 Page request finished: GET (document) file:///C:/Users/*******/AppData/Local/Temp/jsreport/autocleanup/264c975a-9ef2-4130-960c-84eeae2ec04a-chrome-pdf.html
+1124 Running chrome with params {"printBackground":true,"margin":{}}
+1327 Skipping storing report.
+1327 Rendering request 27 finished in 1327 ms
Can any of you smart people tell me what's going wrong? Thanks
See the answer from Jan_blaha here... https://forum.jsreport.net/topic/1814/blank-pdf-output
It perfectly solved my issue with the tutorial.

Karate: JSON is converted to string ([object Object]) when matching

I'm trying to match the response of an API with a schema. I have the following setup.
Here is the feature file:
Feature: As a user, I would like to test APIs of member modules.
Background:
* def DIR_PATH = 'data/users/'
* def signup_request_helpers = read(<path_to_js_file>)
* def signup_response_helpers = read(<path_to_js_file>)
* def request_data = signup_request_data()
Scenario: Test signup of user
Given url my_url
And request request_data
When method POST
Then status 200
Then match response == signup_response_schema
Here is the JS file that holds the response schema
var signup_response_schema = {
"success": true,
"message": "Successfully signed up.",
"data": {
"user": user_schema,
"confirmation_url": "#string",
"token": "#string",
"role": "#array"
}
};
The problem is that karate seems to be converting the response schema into a string. This is the error message that I get:
actual: {<response>}, expected: [object Object]
Please note that I can match individual string fields fine. The problem only occurs when I try to match objects. Also, I have tried printing the schema and the variable seems to be holding the correct value which is the schema object.
I've tried the following:
Convert the schema into a string and then a JSON using the library's directives. This doesn't verify the schema
Convert directly to json which still renders the schema as [object Object]
NOTE: I'm running Karate on docker if that makes any difference. Following is the command that I use in my docker-compose file:
java -jar -Dkarate.config.dir=/app /app/karate-0.9.1.jar -T 5 path_to_file
JS in Karate is not that seamless. This will work:
var temp = {
"success": true,
"message": "Successfully signed up.",
"data": {
"user": user_schema,
"confirmation_url": "#string",
"token": "#string",
"role": "#array"
}
};
karate.set('signup_response_schema', temp);
Normally in Karate *.js files start with function and contain a single function block. And the result of reading (evaluating) that block is assigned to a Karate variable using def. But the recommended option for you is this, where you just have a JSON in the file, and the extension matters:
Then match response == read('signup_response_schema.json')
Note that read() will also evaluate embedded expressions, which can be useful. Although the JSON is not expected to be strictly well-formed, it is recommended.
The issue here wasn't of JS evaluation. The variable signup_response_schema holds the value that I assigned to it in the JS file.
The problem was with the actual matching of the schema because one of the keys was missing in the actual response. Karate usually throws specific error messages indicating which keys were missing but for some reason, this isn't the case here.

SPServices loading but not working

$().SPServices({
operation: "GetGroupCollectionFromUser",
userLoginName: $().SPServices.SPGetCurrentUser(),
async: false,
debug: true,
completefunc: function (xData, Status) {
console.log($.fn.jquery);
console.log(xData.responseXML);
console.log(xData.responseXML.xml);
}
});
I am having a problem with SPServices not working on our dev server. It works fine on prod and testing but not on dev for some reason. If I run the code above I get the following in the console.
{readyState: 0, responseXML: undefined, status: 0, statusText: "No Transport"}
I read online this can be a problem with cross domain transfers so I set the following:
$.support.cors = true;
With that I now get the following:
{readyState: 0, responseXML: undefined, status: 0, statusText: "Error: Invalid Argument"}
I think this is because the SPGetCurrentUser call is always just returning an empty string for some reason instead of the user. Has anyone seen this behavior before? What are common things that can cause SPServices to load but not be able to execute calls? Thanks for the help.
So turns out this appears to be a bug with SPServices. It appears that when you use SPServices on a site with a port number for some reason it duplicates the port number and so everything breaks. So as in my example above I did not specify the webURL and so SPServices used the current web but duplicates the port as shown here:
correct url: http://yourserver:123/sites/yoursite
SPServices: http://yourserver:123123/sites/yoursite
To fix this simply specify a site relative webURL as shown in the working code below. Hopefully this saves someone some aggravation.
var site = "/sites/yoursite";
$(document).ready(function () {
$().SPServices({
operation: "GetGroupCollectionFromUser",
userLoginName: $().SPServices.SPGetCurrentUser({
webURL: site
}),
webURL: site,
async: false,
completefunc: function (xData, Status) {
//Do stuff here
}
});
});
Thank you for your post. Actually i got statusText:"Network Error" when i try to get the user groups using jquery in sharepoint. After passing the site url to the site variable like above code. my issue got resolved.

Cross-domain requests does not work using Sencha Touch 2

I have an application which displays some articles. The application works perfectly on Wamp in localhost. I've uploaded my database management in an other server. I already configured my ArticleStore.js in JSONP but when I run my application the following error appears in the console :
Resource interpreted as Script but transferred with MIME type text/html: "http://[ip_address]:[port]/totos?_dc=1372152920457&keyword=&page=1&start=0&limit=25&callback=Ext.data.JsonP.callback1"
and :
Uncaught SyntaxError: Unexpected token : totos:1
When I clic on the url above I'm redirected to the view which display the following content :
{"articles_list":[{"id":"28","title":"Prixtel dope son service client avec le forfait Sumo"}],"total":1}
For sake of simplicity, I tested to display just the title of one article. Here's the JSON response for the line 1 when I clic on 'totos:1':
{"articles_list":[{"id":"28","title":"Prixtel dope son service client avec le forfait Sumo"}],"total":1}
Here's my ArticleStore.js content :
Ext.define("MyApp.store.ArticleListStore",
{
extend: "Ext.data.Store",
requires: ["MyApp.model.ArticleModel","Ext.data.proxy.JsonP"],
config: {
model: "MyApp.model.ArticleModel",
proxy: {
type: 'jsonp',
model: "MyApp.model.ArticleModel",
url: "http://62.23.96.124:81/totos",
},
reader: {
type: "json",
rootProperty: "articles_list",
totalProperty: "total"
},
},
autoLoad: true
}
});
When I was launched my resquest in localhost directly on Wamp server my JSON responses had the same syntax (The JSON tree architecture is the same). Here's an example :
{"articles_list":[{"id":"384","title":"Skype est disponible sur Windows Phone"}],"total":1}
I cannot see any difference between the two responses. However, I have an 'Unexpected token' error!. As you can see the two nodes 'articles_list' and 'total' have the same place in the JSON tree for the two examples. I don't understand why there is an syntax error. I'm really lost. Does anyone can help me, please ?
Thanks a lot in advance for your help.
Your server is not formatting the response correctly for JSON-P. JSON-P essentially needs your response to be embedded within a function, which is specified by the callbackKey property of your proxy:
proxy: {
type: 'jsonp',
url : "http://62.23.96.124:81/totos",
callbackKey: 'myCallbackKey'
}
Then, on your server, you need to use that parameter to wrap your response:
myCallbackKey({
"articles_list": [
{
"id":"28",
"title":"Prixtel dope son service client avec le forfait Sumo"
}
],
"total":1
})
You can learn more about this from the docs here: http://docs.sencha.com/touch/2.2.1/#!/api/Ext.data.proxy.JsonP.
You also will want to know a little more about the purpose of JSON-P, and how it works. Find out more here: What is JSONP all about?

HTTP Adapter Error "Runtime: Failed to parse JSON string"

I am using IBM Worklight Studio, and trying to create HTTP Adapter which retrieve JSON object from external http server.
When I just access target http server with HTTP Get access(with browser, for example), I know their response is like following array style JSON format:
[
{ "xxx":"aaa", "yyy":"bbb", ... },
{ "xxx":"ccc", "yyy":"ddd", ... },
:
{ "xxx":"eee", "yyy":"fff", ... }
]
And I had created HTTP Adapter which would retrieve above information
var input = {
method : 'get',
returnedContentType : 'json',
path : path
};
return WL.Server.invokeHttp(input);
Now I tried to invoke this adapter with "Run As -> Invoke Worklight Procedure", then I got this error message:
{
"errors": [
"Runtime: Failed to parse JSON string\n\n[\n {\n
(raw JSON data) } ],
"info": [],
"isSuccessful": false,
"warnings": []
}
And in my log console, worklight says following error messages:
FWLSE0101E: Caused by: java.io.IOException: Expecting '{' on line 2, column 2 instead, obtained token: 'Token: ['
From above information, it seems that worklight would expect that returned JSON object need to start with "{", not "[".
Is this my guess right? Are there any workaround for this?
Thanks for advance.
Worklight knows how to handle JSON objects that start with [ (JSON arrays). In such case Worklight will return the response as:
{ "array" : [*the json array*]}
Looking at the code of the HTTP Adapter, I see that there is a bug with parsing JSON arrays that do not start with [.
I do not see a workaround for this problem, except changing the response returned from the http server.
I opened an internal bug about this, thank you for helping us find this bug.
You can change returnedContentType to "plain", this will make WL server return content as a big string and not attempt to parse it.
Then in your adapter you can use var obj = JSON.parse(response.text)