Leo Zhang
菩提本无树,明镜亦非台!

 

.visit()

访问一个远程URL。>>详情参考 Cypress 之 cy.visit()

 

cy.visit(url)
cy.visit(url, options)
cy.visit(options)

 

.click()

点击一个DOM元素。

.click()
.click(options)
.click(position)
.click(position, options)
.click(x, y)
.click(x, y, options)

 

.get()

按选择器或别名获取一个或多个DOM元素

cy.get(selector)
cy.get(alias)
cy.get(selector, options)
cy.get(alias, options)

 

.type()

输入DOM元素。

.type(text)
.type(text, options)

 

.should()

.and()创建一个断言,断言会自动重试直到它们通过或超时。

.should(chainers)
.should(chainers, value)
.should(chainers, method, value)
.should(callbackFn)

 

.contains()

获取包含文本的DOM元素。

.contains(content)
.contains(selector, content)
.contains(selector, content, options)
// ---or---
cy.contains(content)
cy.contains(selector, content)
cy.contains(selector, content, options)

 

.pause()

停止cy运行命令并允许与正在测试的应用程序进行交互。然后可以“恢复”运行所有命令,或者选择从命令日志中逐步执行“下一步”命令。

.pause()
.pause(options)
// ---or---
cy.pause()
cy.pause(options)

 

.debug()

设置debugger并记录上一个命令产生的内容。

.debug()
.debug(options)
// ---or---
cy.debug()
cy.debug(options)

 

.request()

发出HTTP请求。

cy.request(url)
cy.request(url, body)
cy.request(method, url)
cy.request(method, url, body)
cy.request(options)

 

.exec()

执行系统命令。

cy.exec(command)
cy.exec(command, options)

 

.task()

通过插件事件Node.js中执行代码task

cy.task(event)
cy.task(event, arg)
cy.task(event, arg, options)

 

.config()

在测试中获取和设置配置选项

Cypress.config()
Cypress.config(name)
Cypress.config(name, value)
Cypress.config(object)

 

 

Cypress简单示例:

describe('Post Resource', function() {
  it('Creating a New Post', function() {
    cy.visit('/posts/new')     // 1. 访问页面/posts/new。

    cy.get('input.post-title') // 2. 找到输入框post-title。
      .type('My First Post')   // 3. 输入“My First Post”。

    cy.get('input.post-body')  // 4. 找到输入框post-body。
      .type('Hello, world!')   // 5.输入“Hello, world!”

    cy.contains('Submit')      // 6.找到包含文本Submit的元素
      .click()                 // 7.点击

    cy.url()                   // 8.抓取浏览器URL,确保其中包含/posts/my-first-post
      .should('include', '/posts/my-first-post')

    cy.get('h1')               // 9.找到h1标签,确保其中包含“My First Post”文字
      .should('contain', 'My First Post')
  })
})

 

>>>更多CypressAPI参考:https://docs.cypress.io/zh-cn/api/api/table-of-contents.html

 

posted on 2019-06-12 16:16  LeoZhanggg  阅读(3344)  评论(0编辑  收藏  举报