misc.spec.js 3.0 KB

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