misc.cy.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. context('Misc', () => {
  2. beforeEach(() => {
  3. cy.visit('https://example.cypress.io/commands/misc')
  4. })
  5. it('.end() - end the command chain', () => {
  6. // https://on.cypress.io/end
  7. // cy.end is useful when you want to end a chain of commands
  8. // and force Cypress to re-query from the root element
  9. cy.get('.misc-table').within(() => {
  10. // ends the current chain and yields null
  11. cy.contains('Cheryl').click().end()
  12. // queries the entire table again
  13. cy.contains('Charles').click()
  14. })
  15. })
  16. it('cy.exec() - execute a system command', () => {
  17. // execute a system command.
  18. // so you can take actions necessary for
  19. // your test outside the scope of Cypress.
  20. // https://on.cypress.io/exec
  21. // we can use Cypress.platform string to
  22. // select appropriate command
  23. // https://on.cypress/io/platform
  24. cy.log(`Platform ${Cypress.platform} architecture ${Cypress.arch}`)
  25. // on CircleCI Windows build machines we have a failure to run bash shell
  26. // https://github.com/cypress-io/cypress/issues/5169
  27. // so skip some of the tests by passing flag "--env circle=true"
  28. const isCircleOnWindows = Cypress.platform === 'win32' && Cypress.env('circle')
  29. if (isCircleOnWindows) {
  30. cy.log('Skipping test on CircleCI')
  31. return
  32. }
  33. // cy.exec problem on Shippable CI
  34. // https://github.com/cypress-io/cypress/issues/6718
  35. const isShippable = Cypress.platform === 'linux' && Cypress.env('shippable')
  36. if (isShippable) {
  37. cy.log('Skipping test on ShippableCI')
  38. return
  39. }
  40. cy.exec('echo Jane Lane')
  41. .its('stdout').should('contain', 'Jane Lane')
  42. if (Cypress.platform === 'win32') {
  43. cy.exec('print cypress.json')
  44. .its('stderr').should('be.empty')
  45. } else {
  46. cy.exec('cat cypress.json')
  47. .its('stderr').should('be.empty')
  48. cy.exec('pwd')
  49. .its('code').should('eq', 0)
  50. }
  51. })
  52. it('cy.focused() - get the DOM element that has focus', () => {
  53. // https://on.cypress.io/focused
  54. cy.get('.misc-form').find('#name').click()
  55. cy.focused().should('have.id', 'name')
  56. cy.get('.misc-form').find('#description').click()
  57. cy.focused().should('have.id', 'description')
  58. })
  59. context('Cypress.Screenshot', function () {
  60. it('cy.screenshot() - take a screenshot', () => {
  61. // https://on.cypress.io/screenshot
  62. cy.screenshot('my-image')
  63. })
  64. it('Cypress.Screenshot.defaults() - change default config of screenshots', function () {
  65. Cypress.Screenshot.defaults({
  66. blackout: ['.foo'],
  67. capture: 'viewport',
  68. clip: { x: 0, y: 0, width: 200, height: 200 },
  69. scale: false,
  70. disableTimersAndAnimations: true,
  71. screenshotOnRunFailure: true,
  72. onBeforeScreenshot () { },
  73. onAfterScreenshot () { },
  74. })
  75. })
  76. })
  77. it('cy.wrap() - wrap an object', () => {
  78. // https://on.cypress.io/wrap
  79. cy.wrap({ foo: 'bar' })
  80. .should('have.property', 'foo')
  81. .and('include', 'bar')
  82. })
  83. })