Skip to content

Instantly share code, notes, and snippets.

@RockChild
RockChild / condition.cy
Created February 14, 2024 10:49
Conditional cypress
/*
1. el - is a jquery element, you cannot use jquery find with cypress command inside (cy.xpath) as it yelds a cypress chainable object
2. why do you use find on an element, when the xpath starts with // meaning find anywhere
3. I don't use .xpath() plugin command so I don't know how it works.
4. I suggest using more specific selectors. Here you have just div without any class/id or whatever.
Even if you make it work, just one new additional div in the page code will brake your test
*/
// your code from comment
cy.get('[class="sc-foRNMQ dpJTX1"]').then (el => {
// You can keep it inside of the test but it's preferable to store such commands in cypress/support/commands.js
// or create a separate file for related commands e.g. cypress/support/buttons.js
// but don't forget to import it in cypress/support/index.js
Cypress.Commands.add('getLoginButton', (label) => {
switch(label) {
case 'login':
return cy.get(loginBtnSelector);
case 'register':
return cy.get(registerBtnSelector);
}
describe('Canvas object validation', () => {
const email = "pasha.shtefanesku@gmail.com";
const password = "Collaboard1!";
beforeEach('Define routes', () => {
cy.server();
cy.route('POST', "api/Authorization/Authenticate").as('authenticate');
cy.route('POST', "api/CollaborationHub/GetParticipatingProjecs").as('getParticipantProjects');
cy.route('POST', 'api/CollaborationHub/UpdateProjectThumbnail').as('projectLoaded');
});
describe('Cypress aliases', () => {
before('wrap it first', () => {
cy.wrap('1').as('one');
});
it('test 1', () => {
cy.get('@one').should('be.eq', 1);
});
it('test 2', () => {
describe('Common varibles', () => {
context('Scoped js variables', () => {
// this variable is accessible in both tests of current context
var a;
it('test 1', () => {
a = 1;
});
// for Intelligent Code Completion
// https://docs.cypress.io/guides/tooling/intelligent-code-completion.html#Writing-Tests
/// <reference types="cypress" />
describe('Canvas object validation', () => {
// definitely not the best place for such info :)
// Ideally a user should be either created before every test run
// or saved in env vars and then obtained like this:
// Cypress.env('testUserEmail')
// https://docs.cypress.io/guides/guides/environment-variables.html

Немножечко интересных фактов из книги, может будет интересно тому, кто не читал.

  1. Избитый студент-японец - в книге на самом деле негр. Его добивает сам Брюс несколькими ударами молотком-гвоздодером, получая от этого огромное удовольствие. Он считает чернокожего ничтожеством, истинным врагом, который разлучил его с любимой. Напомню - Кэрол ушла к негру. А ушла, если не ошибаюсь, после того, как Брюс ее ударил. Именно поэтому Брюс в одной из сцен собирается ударить Аманду, но останавливается и мямлит, что не хотел ее бить.

  2. В фильме все очень смутно сказано о младшем брате Брюса. Брюс появился на свет в результате изнасилования его матери. Она обращалась за советом к священнику, и он запретил ей делать аборт. Второй ребенок в семье, Дэйви, был родным и желанным.

it(`should stub a POST request`, () => {
cy.fixture('example').then((json) => {
cy.server();
cy.route({
method: 'POST',
url: '/api/users',
status: '204',
}).as('createUser');
cy.request({
@RockChild
RockChild / gist:21567a12578afd9e5151d26607c5b085
Created September 3, 2018 14:02
Error when stopping an AWS task
Unable to stop tasks
[
{
"startedAt": 1535964643626,
"createdAt": 1535964604470,
"stoppedAt": null,
"executionStoppedAt": null,
"pullStoppedAt": 1535964643626,
"containerInstanceArn": "arn:aws:ecs:ap-southeast-2:053536866507:container-instance/604624f3-0b45-4134-befc-e7c81aef36d4",
"memory": "1024",
2018/03/20 13:39:12 ERROR com.finder.nichemanagement.impl.sql.AbstractSql [v70] [] - Could not run SQL: INSERT INTO `FTN_providers` (`ANOTHER_REQUIRED_FIELD_GROUP_NEW_FIELD_RQ`, `NAME`, `TEST_FIELD`, `ACTIVE`, `DELETED`, `IMAGES_PROVIDER_LOGO`, `IMAGES_REQUIRED_IMAGE_TEST_FIELD`, `IMAGES_ASD`, `LOCALE`, `ID`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE `ANOTHER_REQUIRED_FIELD_GROUP_NEW_FIELD_RQ` = ?, `NAME` = ?, `TEST_FIELD` = ?, `ACTIVE` = ?, `DELETED` = ?, `IMAGES_PROVIDER_LOGO` = ?, `IMAGES_REQUIRED_IMAGE_TEST_FIELD` = ?, `IMAGES_ASD` = ?, `LOCALE` = ?, `ID` = ?, Data truncation: Incorrect datetime value: '2018-03-06T00:00:00+-11:00' for column 'ANOTHER_REQUIRED_FIELD_GROUP_NEW_FIELD_RQ' at row 1 (error code: 1292)
2018/03/20 13:39:12 ERROR com.finder.nichemanagement.impl.sql.AbstractSql [v70] [] - Could not run SQL: INSERT INTO `FTN_providers` (`ANOTHER_REQUIRED_FIELD_GROUP_NEW_FIELD_RQ`, `NAME`, `TEST_FIELD`, `ACTIVE`, `DELETED`, `IMAGES_PROVIDER_LOGO`, `IMAGES_REQUIRED_IMAGE_TEST_FIELD