wonderful-author-91008
05/01/2022, 9:32 PMgentle-accountant-4760
05/02/2022, 2:58 PMjs
Suite('Test Cypress', () => {
before(() => {
prepare();
});
Scenario('Test', () => {
Given('works', () => {
const bomMessage = cy.stub().as('bom');
cy.on('window:before:load', (win) => {
win.addEventListener('message', (event) => {
if (event.data.event === 'BOMComputationReady') {
bomMessage(event.data);
}
});
});
cy.visit('https://wwww.google.com');
cy.get('@bom', { timeout: 30_000 }).should('be.calledOnce');
});
Inside my prepare(); is
js
cy
.visit('https://google.com/barry', { auth: username: 'helloworld', password: 'testing');
cy.get('div.hello_world')
.window()
.then((window) => {
Object.assign(ProvisionConfig, (window).provisionConfig);
});
the script works fine I comment away the "prepare()" but if I keep it, then the cy.get('@bom', { timeout: 30_000 }).should('be.calledOnce');
will never be called but it works if I comment the prepare()
- Anyone knows the reason?gentle-accountant-4760
05/02/2022, 6:54 PMmagnificent-finland-58048
05/02/2022, 7:04 PMgentle-accountant-4760
05/02/2022, 7:05 PMwindow:before:load
if you do a before() call. beacuse when I do the prepare() call, then the window:before:load
doesn't work for me 😦magnificent-finland-58048
05/02/2022, 7:07 PMgentle-accountant-4760
05/02/2022, 7:09 PMgray-kilobyte-89541
05/02/2022, 7:25 PMgentle-accountant-4760
05/02/2022, 7:26 PMgray-kilobyte-89541
05/02/2022, 8:29 PMgentle-accountant-4760
05/02/2022, 9:03 PMwonderful-author-91008
05/03/2022, 2:43 AMgentle-accountant-4760
05/03/2022, 7:39 AMts
Given('works', () => {
const bomMessage = cy.stub().as('bom');
cy.visitWithAuth('https://helloworld.com');
// Wait for BOM to be loaded
cy.window().then((win) => {
win.addEventListener('message', (event) => {
if (event.data.event === 'BOMComputationReady') {
bomMessage(event.data);
}
});
});
cy.get('@bom').should('be.calledOnce');
});
My question is if its possible to somehow refactor it and skip the cy.stub()? and to continue once the event is found?gray-kilobyte-89541
05/03/2022, 10:05 AMgentle-accountant-4760
05/03/2022, 10:08 AMgray-kilobyte-89541
05/03/2022, 12:57 PMhundreds-father-43644
05/03/2022, 4:12 PMmagnificent-finland-58048
05/03/2022, 7:01 PMcy.intercept('PATCH', '**/coupons/*')
?
you can try a regex too
cy.intercept('PATCH', /coupons/whateverFunStuff/$)
hundreds-father-43644
05/03/2022, 7:11 PMdescribe('Edit coupon good alerts', () => {
const affiliatesUrl = Cypress.env('api_url') + Cypress.env('get_affiliates')
const affiliateCategoriesUrl = Cypress.env('api_url') + Cypress.env('coupon_affiliate_categories')
const storesUrl = Cypress.env('api_url') + '/stores*'
const getCoupom = Cypress.env('api_url') + "/coupons/385162-2"
beforeEach(() => {
cy.clearCache()
cy.setFirebaseCookies()
cy.intercept('PATCH', getCoupom, { statusCode: 201, delay: 5000 }).as('editCoupon');
cy.intercept('GET', storesUrl, { fixture: 'store/good.response.json' }).as('store')
cy.intercept('GET', affiliatesUrl, { fixture: 'affiliate/good.response.json' }).as('affiliates')
cy.intercept('GET', affiliateCategoriesUrl, { fixture: 'affiliate-categories/good.response.json' }).as('affiliateCategories')
cy.intercept('GET', getCoupom, { statusCode: 201, fixture: 'coupon/coupon.json' }).as('coupon');
cy.visit('/cupons/385162-2')
cy.wait(['@coupon', '@affiliateCategories', '@affiliates'])
})
afterEach(() => {
cy.clearCache()
})
it('Should show success alert when edit Coupon success', () => {
cy.get('[data-cy="coupon-id"]').type('TESTE123450192TESTE')
cy.get('[data-cy="coupon-save-button"]').click()
cy.wait('@editCoupon')
cy.get('[data-cy="snack-alert"]').invoke('text').should('eq', 'O Cupom foi editado com sucesso!')
})
})
little-france-10142
05/03/2022, 10:40 PMit('renders an active base button', () => {
mount(
<Button
onClick={() => {
return true
}}
>
Click me
</Button>
)
cy.get('button').click().should('be.true')
})
gray-kilobyte-89541
05/04/2022, 12:05 AMjs
import React from 'react'
import { mount } from '@cypress/react'
const Button = ({ onClick, children }) => (
<button onClick={onClick}>Click me</button>
)
it('renders an active base button', () => {
mount(<Button onClick={cy.stub().as('click')}>Click me</Button>)
cy.get('button').click()
cy.get('@click').should('have.been.calledOnce').invoke('resetHistory')
cy.get('button').click().click()
cy.get('@click').should('have.been.calledTwice')
})
little-france-10142
05/04/2022, 12:18 AMcy.stub()
and '@click'
concepts I was not aware of. Thank you!gray-kilobyte-89541
05/04/2022, 12:21 AMhundreds-father-43644
05/04/2022, 12:20 PMlittle-france-10142
05/04/2022, 1:12 PMlittle-france-10142
05/04/2022, 1:13 PMthousands-pharmacist-63522
05/04/2022, 6:44 PMthousands-pharmacist-63522
05/04/2022, 6:45 PMwonderful-author-91008
05/04/2022, 8:26 PMmelodic-king-62847
05/05/2022, 9:44 AM