<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      [Cypress] install, configure, and script Cypress for JavaScript web applications -- part3

      Use custom Cypress command for reusable assertions

      We’re duplicating quite a few commands between the registration and login of our user for assertions. Let’s see how we can take these assertions and create a custom command to make the assertions.

      We have the tests:

          it('should register a new user', () => {
              cy.createUser().then(user => {
                  cy.visit('/')
                  .getByText(/login/i)
                  .click()
                  .getByLabelText(/username/i)
                  .type(user.username)
                  .getByLabelText(/password/i)
                  .type(user.password)
                  .getByText(/submit/i)
                  .click()
      
                  // verify the user in localStorage
                  .url()
                  .should('eq', `${Cypress.config().baseUrl}/`)
                  .window()
                  .its('localStorage.token')
                  .should('be.a', 'string')
                  .getByTestId('username-display', {timeout: 500})
                  .should('have.text', user.username)
              })
          });

      We can create some assertions commands to make it more reusable:

      Cypress.Commands.add('assertHome', () => {
        cy.url().should('eq', `${Cypress.config().baseUrl}/`)
      })
      
      Cypress.Commands.add('assertLoggedInAs', user => {
        cy
          .window()
          .its('localStorage.token')
          .should('be.a', 'string')
          .getByTestId('username-display', {timeout: 500})
          .should('have.text', user.username)
      })

       

      Then we can improve the test:

          it('should register a new user', () => {
              cy.createUser().then(user => {
                  cy.visit('/')
                  .getByText(/login/i)
                  .click()
                  .getByLabelText(/username/i)
                  .type(user.username)
                  .getByLabelText(/password/i)
                  .type(user.password)
                  .getByText(/submit/i)
                  .click()
                  .assertHome()
                  .assertLoggedInAs(user);
              })
          });

       

      Run tests as an authenticated user with Cypress

      For most applications you’re going to need to be logged in as a user to interact with the application. Let’s see how we can register as a new user and login as that user to test using the application as a logged in user.

      Sometime you want to check some DOM element is not present, you cna use queryByTestId()

          it('displays the username', () => {
              cy.createUser().then(user => {
                  cy.visit('/')
                      .getByText(/login/i)
                      .click()
                      .getByLabelText(/username/i)
                      .type(user.username)
                      .getByLabelText(/password/i)
                      .type(user.password)
                      .getByText(/submit/i)
                      .click()
                      .assertLoggedInAs(user)
                      .getByText(/logout/i)
                      .click()
                      .queryByTestId('username-display', {timeout: 300})
                      .should('not.exist')
              })
          });

       

      Combine custom Cypress commands into a single custom command

       Almost every time we need to login, we’ll want to have a newly created user to login as. Let’s go ahead and combine the createNewUser and logincommands to create a single loginAsNewUser which we can use in any test that needs an authenticated user.

      // support/commands.js
      
      Cypress.Commands.add('loginAsNewUser', () => {
          cy.createUser().then(user => {
              cy.login(user)
          });
      });
      
      Cypress.Commands.add('login', user => {
          cy.request({
              url: 'http://localhost:3000/login',
              method: 'POST',
              body: user,
          }).then(({body}) => {
              window.localStorage.setItem('token', body.user.token);
              return body.user;
          })
      })
      // e2e/calcualtor.js
      
      describe('authenticated calculator', () => {
          it('displays the username', () => {
              cy.loginAsNewUser().then((user) => {
                  cy.visit('/')
                  .getByTestId('username-display')
                  .should('have.text', user.username)
                  .getByText(/logout/i)
                  .click()
                  .queryByTestId('username-display', {timeout: 300})
                  .should('not.exist')
              })
          });
      })

       

      Install React DevTools with Cypress

      Because Cypress runs in a real Chrome browser, we can install extensions, like React DevTools. The tricky bit will be to make our application hook up to the extension properly.

      react-dev-tools.js

      if (window.Cypress) {
          window.__REACT_DEVTOOLS_GLOBAL_HOOK__ = window.parent.__REACT_DEVTOOLS_GLOBAL_HOOK__
        }

       

      Import the script before we import the REACT

      index.js

      import './react-dev-tools'
      
      import './global.css'
      import React from 'react'

       

      posted @ 2018-12-06 21:13  Zhentiw  閱讀(437)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 377P欧洲日本亚洲大胆| 天天看片视频免费观看| 汾西县| 丰满少妇被猛烈进出69影院| 国产成人精品亚洲一区二区| 国产sm重味一区二区三区| 精品人妻中文字幕在线| 日韩有码中文字幕国产| 国精品午夜福利视频不卡| 欧美成人片一区二区三区| 国产精品一品二区三四区| 国产精品国三级国产av| 亚洲欧美在线观看品| 人人人澡人人肉久久精品| 日韩av一区二区三区不卡| 精品国产乱码久久久久夜深人妻| 国产精品中文字幕一区| a4yy私人毛片| 激情综合网激情国产av| 亚洲日本精品一区二区| 色吊丝一区二区中文字幕| 国产超碰无码最新上传| 狠狠躁夜夜躁人人爽蜜桃| 麻豆精品一区二区视频在线| 欧美和黑人xxxx猛交视频| 久久人人爽人人爽人人片| 亚洲无人区一码二码三码| 中文字幕亚洲精品第一页| 国色天香中文字幕在线视频| 久爱无码精品免费视频在线观看| 亚洲av成人一区国产精品| 欧美老熟妇乱子伦牲交视频| 影视先锋av资源噜噜| 开心五月深深爱天天天操| 在线观看国产午夜福利片| 久久亚洲国产品一区二区| 欧美成人精品三级在线观看| 丁香五月亚洲综合在线| 久久中文字幕av第二页| 欧美丰满熟妇xxxx性| 麻豆国产va免费精品高清在线|