Accessing Cypress results outside of the application to display on a Webpage - cypress

Scope: I am trying to make a website (hub) that displays the test results of other websites in a table like format. For Example:
Google.com - 42 tests - 41 passed.
Or Ebay.com - 50 tests - 50 passed.
Then for each website have a green or red if all the tests pass.
I have been looking for a way to access Cypress results like you would access an API to get data from it to be displayed. Is there already a Cypress function like this, that enables access to test results outside of the application?

You might be interested in running via the Module API, specifically
const cypress = require('cypress')
cypress
.run({
// the path is relative to the current working directory
spec: './cypress/integration/examples/actions.spec.js',
})
.then((results) => {
console.log(results)
})
Results - Stats section
{
...
"stats": {
"suites": 1,
"tests": 1,
"passes": 0,
"pending": 0,
"skipped": 0,
"failures": 1,
"startedAt": "2020-08-05T08:38:37.589Z",
"endedAt": "2018-07-11T17:53:35.675Z",
"duration": 1171
},
}
or per test details
"tests": [{
"title": [ "test" ],
"state": "failed",

You can use a reporter to customize what the output of the report looks like, as well as several other things, including a destination output for the results. Check out Cypress's documentation on reporters for more information.
Cypress's Reporter Documentation

Related

Is there an API that shows the user task histroy on the Camunda side?

I have a Camunda flow, there are 2-3 user tasks in this flow. I want to see their history after completing these tasks. There are a couple of methods, but I just want to get both the label and the entered value with rest-api.
I can't get them directly with rest-api.
The following method returns variables with the processInstanceId.
List<HistoricVariableInstance> instances = historyService.createHistoricVariableInstanceQuery()
.processInstanceId(processIntanceId)
.list();
but I need to call another rest-api to get the labels. GET /process-definition/{id}/xml with this api.
Other topics have been opened for this, but it does not meet exactly what I want.
similar question
I think you are right, you need 2 steps. I would combine the following requests:
First get all User Tasks:
GET /history/task -see API Reference
From its result Array you need the id and the name (which is the label):
[{"id":"anId",
...
"name":"aName",
...
}]
Now you can get the variables for each UserTask, like
GET /history/variable-instance?taskIdIn=YourTaskId see API Reference
https://docs.camunda.org/manual/7.16/reference/rest/history/variable-instance/post-variable-instance-query/
returns the name (label) and the value of the process variables
[
{
"id": "someId",
"name": "someVariable",
"type": "Integer",
"variableType": "integer",
"value": 5,
"valueInfo": {},
"processDefinitionKey": "aProcessDefinitionKey",
"processDefinitionId": "aProcessDefinitionId",
"processInstanceId": "aProcInstId",
"executionId": "aExecutionId",
"activityInstanceId": "aActivityInstId",
"caseDefinitionKey": null,
"caseDefinitionId": null,
"caseInstanceId": null,
"caseExecutionId": null,
"taskId": null,
"tenantId": null,
"errorMessage": null,
"state": "CREATED",
"createTime":"2017-02-10T14:33:19.000+0200",
"removalTime": "2018-02-10T14:33:19.000+0200",
"rootProcessInstanceId": "aRootProcessInstanceId"
}
]

How to access Cypress data in the console

Below is a screen shot of Cypress 6.8 runner. I am interested in accessing the data printed in the console shown on the right.
In order to see this information within the browser window where tests are executed, you would open the developer tools and click a row. In the example, I had clicked row 8 which is shown by the purple pin and tooltip stating that "Printed output to your console".
Is it possible to programmatically access to this same information printed in the console? For example, could I get access to the command, applied to and any other information that might be logged. My understanding is this information only appears when clicking the row.
I would like to access this information using a custom plugin. Can you please provide insight into how this might be possible? I've been experimenting with the plugins/index.js module exports which provides access to on. But, at this time I don't have any meaningful code to share. I'm in the learning stage trying to determine if its feasible to access this information. Thanks.
At the top of your spec or in cypress/support/index.js you can add an event listener which listens for log:added, ref Catalog of Events.
Cypress.on('log:added', (logObject) => console.log(logObject))
This provides your callback a stream of the "log attributes" objects in the first parameter, which have a console.props property, which is what is printed when you click a line in the LHS Cypress log.
{
"message": "http://example.com/",
"timeout": 60000,
"name": "visit",
"type": "parent",
"event": false,
"id": 3,
"state": "passed",
"instrument": "command",
"url": "http://example.com/",
"hookId": "r2",
"testId": "r2",
"testCurrentRetry": 0,
"viewportWidth": 1000,
"viewportHeight": 660,
"wallClockStartedAt": "2021-03-20T03:12:21.490Z",
"chainerId": "chainer4",
"consoleProps": {
"Command": "visit",
"Resolved Url": "http://example.com/",
"Redirects": [],
"Cookies Set": []
},
"renderProps": {},
"totalTime": 218,
"snapshots": [
{
"htmlAttrs": {},
"body": {}
}
],
"ended": true
}

"NoSuchSessionError: This driver instance does not have a valid session ID" when running a simple Selenium Runner test

I just installed the latest version of Selenium Runner
npm install -g selenium-side-runner
on my Mac High Sierra. I'm running node v14.1.0. I'm using Chrome Driver v 83. I want to run a very simple file that simply opens a page, waiting for an element on that page to be present. However, I'm getting a "NoSuchSessionError: This driver instance does not have a valid session ID" error.
The Selenium Runner .side file in question is
$ cat selenium/KarmaDecayGetResults.side
{
"id": "9664bd47-b18f-405f-9bd3-06014919ca7e",
"version": "2.0",
"name": "KarmaDecay",
"url": "http://karmadecay.com",
"tests": [
{
"id": "8f462171-01b8-4247-87b9-40e2d1fef143",
"name": "KarmaDecay",
"commands": [
{
"id": "c297319b-4350-4f04-b72e-1a347a67100c",
"comment": "",
"command": "open",
"target": "/r/gifs/comments/gz5v5j/caracal_visits_jimmy_kimmel_gets_shy_and_tries_to/",
"targets": [],
"value": ""
},
{
"id": "32f35ed7-1a28-4540-a93d-3cb8ba0e012a",
"comment": "",
"command": "pause",
"target": "",
"targets": [],
"value": "2000"
},
{
"id": "95261633-22ff-4477-ab6f-7b3354bea8b9",
"comment": "",
"command": "setWindowSize",
"target": "1440x900",
"targets": [],
"value": ""
},
{
"id": "fbf35ed7-1a28-4540-a93d-3cb8ba0e012a",
"comment": "",
"command": "waitForElementPresent",
"target": "id=content",
"targets": [],
"value": ""
},
{
"id": "aed35ed7-1a28-4540-a93d-3cb8ba0e012a",
"comment": "",
"command": "waitForElementVisible",
"target": "id=content",
"targets": [],
"value": ""
},
{
"id": "fbf59ed7-1a28-4540-a93d-3cb8ba0e012a",
"comment": "",
"command": "pause",
"target": "",
"targets": [],
"value": "2000"
}
]
}
],
"suites": [
{
"id": "91809d77-24c1-457b-8266-516b2fc58555",
"name": "Default Suite",
"persistSession": false,
"parallel": false,
"timeout": 300,
"tests": [
"8f462171-01b8-4247-87b9-40e2d1fef143"
]
}
],
"urls": [
"http://karmadecay.com/"
],
"plugins": []
}
Below is the output of running the file ...
$ PATH=/Users/davea/Documents/workspace/article_project/selenium/dev:/usr/local/bin:$PATH /usr/local/bin/selenium-side-runner -c "goog:chromeOptions.args=[--headless,--nogpu] browserName=chrome" selenium/KarmaDecayGetResults.side
FAIL ./DefaultSuite.test.js (301.959s)
Default Suite
✕ KarmaDecay (300540ms)
● Default Suite › KarmaDecay
: Timeout - Async callback was not invoked within the 300000ms timeout specified by jest.setTimeout.Timeout - Async callback was not invoked within the 300000ms timeout specified by jest.setTimeout.Error:
8 | jest.setTimeout(300000);
9 | describe("Default Suite", () => {
> 10 | it("KarmaDecay", async () => {
| ^
11 | await tests["KarmaDecay"](driver, vars);
12 | expect(true).toBeTruthy();
13 | });
at new Spec (../../../../../../usr/local/lib/node_modules/selenium-side-runner/node_modules/jest-jasmine2/build/jasmine/Spec.js:116:22)
at Suite.<anonymous> (DefaultSuite.test.js:10:3)
● Default Suite › KarmaDecay
NoSuchSessionError: This driver instance does not have a valid session ID (did you call WebDriver.quit()?) and may no longer be used.
at ../../../../../../usr/local/lib/node_modules/selenium-side-runner/node_modules/selenium-webdriver/lib/webdriver.js:729:38
at Object.thenFinally [as finally] (../../../../../../usr/local/lib/node_modules/selenium-side-runner/node_modules/selenium-webdriver/lib/promise.js:124:12)
at runMicrotasks (<anonymous>)
at WebdriverEnvironment.global.cleanup (../../../../../../usr/local/lib/node_modules/selenium-side-runner/node_modules/jest-environment-selenium/dist/index.js:30:7)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 302.159s
Ran all test suites.
Do I need to be doing something different to get my test to run cleanly?
invalid session id
The invalid session ID error is a WebDriver error that occurs when the server does not recognize the unique session identifier. This happens if the session has been deleted or if the session ID is invalid.
A WebDriver session can be deleted through either of the following ways:
Explicit session deletion: A WebDriver session is explicitly deleted when explicitly invoking the quit() method.
Implicit session deletion: A WebDriver session is implicitly deleted when you close the last window or tab invoking close().
You can find a detailed discussion in selenium.common.exceptions.WebDriverException: Message: invalid session id using Selenium with ChromeDriver and Chrome through Python
This usecase
I don't see any such error within your code block. However your main error seems to be...
Timeout - Async callback was not invoked within the 300000ms timeout specified by jest.setTimeout.Timeout - Async callback was not invoked within the 300000ms timeout specified by jest.setTimeout.Error:
...which implies that the Async callback being referred to in the error is getting timedout even with timeout set as 300000:
jest.setTimeout(300000);
The real issue is with the url of KarmaDecay which contains a hCaptcha to keep off automated bots.
URL Snapshot:
Conclusion
As per your test setup to execute the selenium-side-runner within the website http://karmadecay.com/ first you have to interact with the captcha to get authenticated and then run your tests.
You can find a couple of relevant discussions on how to interact with recaptcha in:
How to identify the 32 bit data-sitekey of ReCaptcha V2 to obtain a valid response programmatically using Selenium and Python Requests?
Find the reCAPTCHA element and click on it — Python + Selenium
How to click on the reCaptcha using Selenium and Java
Another aspect
If the initial tests works fine but for the rest of your tests you get a session ID error most possibly the Selenium WebDriver controled Browsing Context is getting detected and hence blocking the next requests.
There are different reasons for the WebDriver controled Web Browser to get detected and simultaneously get blocked. You can find a couple of detailed discussion in:
Can a website detect when you are using selenium with chromedriver?
Selenium webdriver: Modifying navigator.webdriver flag to prevent selenium detection

How to download an image/media using telegram API

I want to start by saying that this question is not for telegram bot API. I am trying to fetch images from a channel using telegram core API. The image is in the media property of the message object
"_": "message",
"pFlags": {
"post": true
},
"flags": 17920,
"post": true,
"id": 11210,
"to_id": {
"_": "peerChannel",
"channel_id": 1171605754
},
"date": 1550556770,
"message": "",
"media": {
"_": "messageMediaPhoto",
"pFlags": {},
"flags": 1,
"photo": {
"_": "photo",
"pFlags": {},
"flags": 0,
"id": "6294134956242348146",
"access_hash": "11226369941418527484",
"date": 1550556770,
I am using the upload.getFile API to fetch the file. Example is
upload.getFile({
location: {
_: 'inputFileLocation',
id: '6294134956242348146',
access_hash: '11226369941418527484'
},
limit: 1000,
offset: 0
})
But the problem is it throws the error RpcError: CODE#400 LIMIT_INVALID. From looking at the https://core.telegram.org/api/files it looks like limit value is invalid. I tried giving limit as
1024000 (1Kb)
20480000 (20Kb)
204800000 (200kb)
But it always return the same error.
For anyone who is also frustrated with the docs. Using, reading and trying out different stuff will ultimately work for you. If possible someone can take up the task of documenting the wonderful open source software.
Coming to the answer, the location object shouldn't contain id or access hash like other APIs rather it has its own parameters as defined in telegram schema.
There is a media property to a message which has a sizes object. This will contains 3 or more size options (thumbnail, preview, websize and so on). Choose the one that you will need and use the volume_id, local_id and secret properties. The working code will look something like this.
upload.getFile({
location: {
_: 'inputFileLocation', (This parameter will change for other files)
volume_id: volumeId,
local_id: localId,
secret: secret
},
limit: 1024 * 1024,
offset: 0
}, {
isFileTransfer: true,
createClient: true
})
The following points should be noted.
Limit should be in bytes (not bits)
Offset will be 0. But if its big file use this and limit to download parts of the file and join them.
Additional parameters such as isFileTransfer and createClient also exists. I haven't fully understood why its needed. If I have time I'll update it later.
Try using a library that's built on top the original telegram library. I'm using Airgram, a JS/TS library which is a well maintained Repo.

How does changes() work in rethinkdb?

Example from the home page of rethinkdb.com doesn't work as expected.
r.db("test").tableCreate("game");
r.db("test").table("game").indexCreate("score");
r.db("test").table("game").insert({name: "brandon", score: 60});
r.db("test").table("game").insert({name: "leon", score: 80});
r.db("test").table("game").insert({name: "connor", score: 100});
r.db("test").table("game").orderBy({index: "score"}).limit(3).changes()
Output:
{ "new_val": { "id": "c727b9eb-5aaa-46f9-bc09-a6c879cfbfa0" , "name":
"brandon" , "score": 60 } } { "new_val": { "id":
"b59d4314-b78c-48c9-8780-0f9d3a6b6887" , "name": "leon" , "score": 80
} } { "new_val": { "id": "519343b1-cd98-4969-8f07-7bff5d981c81" ,
"name": "connor" , "score": 100 } }
r.db("test").table("game").insert({name: "mike", score: 70});
Nothing changes but must be changed due to ordering by score.
r.db("test").table("game").get("519343b1-cd98-4969-8f07-7bff5d981c81").update({score: 50}) // {name: "connor"}
Still nothing..
So why ordered list is not updates as it should be?
This is a bug in the data explorer, unfortunately. It was fixed in https://github.com/rethinkdb/rethinkdb/issues/4852 and the fix will be pushed out as a point release soon. Until it's released I'd recommend using one of the drivers to test these queries instead.
This appears to be a failure of the Web interface. Running these commands from a client driver (I tried it with the JavaScript driver on 2.1.3 and 2.1.4) shows the changes as expected, it's just that the Data Explorer does not update correctly. If you swap tabs to Table View and back you can see that the cursor has received the changes at the bottom.

Resources