Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
cypress-crud
Advanced tools
cy.crud is a project that aims to have a new framework to make cy.api and cy.request easier
generate-datafaker
| NodeJs | Cypress version 10 >
To install the package, run the following command in your Cypress project:
npm i cypress-crud
test_bdd
test_action
test_bdd_BR
scenario
given
when
and
then
cenario
dado
quando
e
entao
cy.crud automatically adds dependencies to the project in e2e.js file
export {
Scenario,
Given,
When,
And,
Then,
Cenario,
Dado,
Quando,
E,
Entao,
describes,
its,
crudStorage,
} from "cypress-crud/src/gherkin/bdd.js";
import "cypress-plugin-steps";
export const faker = require("generate-datafaker");
import "cypress-crud";
import "cypress-plugin-api";
š© create a json in the fixtures folder, which can be inside a subfolder "fixtures/token/createToken.json"
{
"request": {
"method": "GET",
"url": "https://reqres.in/api/users/2",
"body": null,
"qs": null,
"headers": {
"Content-Type": "application/json"
}
}
}
cy.crud({ payload: "requests/createToken.json" }) // save response in crudStorage.alias.bodyResponse
cy.crud({ payload: "requests/createToken.json", alias:"body" }) // save response in crudStorage.alias.body
Or
let obj = {
"request": {
"method": "GET",
"url": "https://reqres.in/api/users/2",
"body": null,
"qs": null,
"headers": {
"Content-Type": "application/json"
}
}
}
cy.crud({ payload: obj })
> JSON
{
"request": {
"method": "GET",
"url": "https://reqres.in/api/users/2",
"path": "save" // or alias defined in save({path:"id", alias: "id_user"})
"body": null,
"qs": null,
"headers": {
"Content-Type": "application/json"
}
}
}
it('Generate id ', ()=>{
cy.crud({ payload: "token/createToken.json" })
})
env: {
environment: "QA", // modify env for DEV or PROD
QA: {
getUser: "https://reqres.in/api/users?page=2",
},
DEV: {
getUser: "https://reqres.in/api/users?page=2"
},
PROD: {
getUser: "https://reqres.in/api/users?page=2"
},
}
in JSON
{
"endpoint": "getUser", // endpoint modify for path in env
"request": {
"method": "GET",
"url": "https://reqres.in/api/users/2",
"body": null,
"qs": null,
"headers": {
"Content-Type": "application/json"
}
}
}
š» with validations you just need to inform the path and the value, regardless of which part of your JSON it is.
{
"request": {
"method": "GET",
"url": "https://reqres.in/api/users/2",
"body": null,
"qs": null,
"headers": {
"Content-Type": "application/json"
}
},
"validation": [{ "path": "status", "value": 200 }, { "path": "first_name" }, ...]
}
cy.crud({ payload: "token/createToken.json" })
assert expected 200 to exist
assert expected 200 to deeply equal 200
assert expected Michael to exist
š» If you don't want to use validations directly in JSON, you can use .bodyResponse to validate the return.
cy.crud({ payload: "token/createToken.json" })
.bodyResponse({path: "name", value:"Jam Batista"})
// .bodyResponse({path: "name""})
code hiden bodyResponse
expect(search).to.exist;
if (equal) {
expect(search).to.eql(equal);
}
return expect(search);
š» save will set aside a value entered to be used in the future when you request it.
cy.crud({ payload: "token/createToken.json" })
.save({path:"name"}) // save name in crudStorage
// .save({path:"name", alias: "user_id"}) // save name in crudStorage whit new alias
console.log('storage', crudStorage.save.save)
// console.log('storage', crudStorage.save.user_id)
// .save({path:"name"})
cy.save({ log: false }).then((rescue) => {
expect(rescue).to.eql("Weaver");
});
});
// .save({path:"name", alias:"name"})
cy.save({ log: false , alias:"name"}).then((rescue) => {
expect(rescue).to.eql("Weaver");
});
});
OR
console.log('save', crudStorage.save.save)
š» Uses cy.writeFile requirements
cy.crud({ payload: "token/createToken.json" })
.write({ path: "user/getUser" }); // create json response in cypress/fixtures/user
š» Uses cy.writeFile requirements
cy.crud({ payload: "token/createToken.json" })
.read({ path: "user/getUser" }); // read json response in cypress/fixtures/user
cy.read({ path: "user/getUser" }).then((json)=>{
console.log(json)
});
it('Generate access_token', ()=>{
cy.crud({ payload: "requests/getUser" })
.save({ path: "access_token", alias: "token" }); // save token in alias token
})
š„ in another file or in the same test
let json require('../fixtures/requests/createToken.json')
let data = {...json};
it('Get token in use headers', ()=>{
data.request.headers = {Authorization: `Bearer ${crudStorage.save.token}`}
cy.crud({ payload: data })
.bodyResponse({path: "status", equal: 201})
.bodyResponse({path: "name", equal:"Jam"})
.save({ path: "data"})
.write({ path: "user/getUser" });
})
Contributions are always welcome. Feel free to open issues or send pull requests.
This project is licensed under the terms of the MIT License.
FAQs
cy.crud is a project that aims to have a new framework to make cy.api and cy.request easier
The npm package cypress-crud receives a total of 195 weekly downloads. As such, cypress-crud popularity was classified as not popular.
We found that cypress-crud demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Ā It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.