mkdir cez_checker
cd cez_checker/
npm init --yes
npm install cypress --save-dev
echo '{}' > cypress.json
mkdir -p cypress/integration
touch cypress/integration/cez_breakdown_spec.js
# Paste the content of the script in "cypress/integration/cez_breakdown_spec.js"
# Run in the CLI
npx cypress run --quiet
# Run in the browser
npx cypress open
Created
December 4, 2020 15:12
-
-
Save PaperNick/9724850693cc679032797c40542641d1 to your computer and use it in GitHub Desktop.
CEZ breakdowns
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const CEZ_BREAKDOWNS_URL = 'https://info.cez.bg/js/avarii/av1.php'; | |
const NO_BREAKDOWNS_ASSERT_MESSAGE = 'няма прекъсвания на захранването'; | |
const populatedPlaces = [ | |
{ name: 'Перник', fullMatch: false }, | |
{ name: 'Кюстендил', fullMatch: false }, | |
{ name: 'Буново, общ. Кюстендил', fullMatch: true }, | |
]; | |
function escapeRegExp(string) { | |
return string.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string | |
} | |
describe('CEZ Breakdowns', () => { | |
beforeEach(() => { | |
// https://docs.cypress.io/api/events/catalog-of-events.html#Examples | |
cy.on('uncaught:exception', (err, runnable) => { | |
// An "Uncaught ReferenceError: object is not defined" exception is thrown from CEZ webpage. | |
// Ignore it so that the execution can continue. | |
// Return false to prevent the error from failing the current test. | |
return false; | |
}); | |
}); | |
function checkBreakdown(place, fullMatch) { | |
it(`should not have any breakdowns for "${place}"`, () => { | |
cy.visit(CEZ_BREAKDOWNS_URL); | |
cy.get('#searchField').type(place); | |
const searchValue = fullMatch ? place.toUpperCase() : new RegExp(`^${escapeRegExp(place.toUpperCase())}`); | |
const placeSuggestion = cy.get('#suggestions .ui-btn').contains(searchValue, { matchCase: true }); | |
placeSuggestion.should('have.length.greaterThan', 0); | |
placeSuggestion.click(); | |
cy.get('[data-role="content"] .ui-body').should('contain', NO_BREAKDOWNS_ASSERT_MESSAGE); | |
}); | |
} | |
populatedPlaces.forEach(place => checkBreakdown(place.name, place.fullMatch)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment