什么是TestCafe?

TestCafe是一个基于Node.js,支持多平台(Linux,Windows,macOS)的端到端web测试框架

安装指南

最简单的方式是通过npm包管理工具进行安装,以下命令会在电脑上全局安装testcafe

    npm i -g testcafe

构成

TestCafe测试基于Node.js脚本执行,可通过新创建TypeScript或JavaScript文件开始进行测试用例编写,TestCafe的测试文件由fixtures和tests组成,一个fixture是一组共享初始URL的test函数组成的
建议:在每一个test文件中仅使用一个fixture,如用例集中包含不同初始URL的测试,最好将其分配至不同的测试文件中——通过初始URL进行分类

  1. 通过如下方式进行fixture的创建:

     fixture("Getting Started")
  2. 然后使用page方法为fixture指定初始的URL:

     fixture("Getting Started").page("https://devexpress.github.io/testcafe/example")
  3. 最后,通过使用test方面进行测试用例的声明:

     fixture("Getting Started").page("https://devexpress.github.io/testcafe/example")
    
     test("My first test", async (t) => {
         // Test code here
     })

    测试动作

testcafe当前支持的页面操作:

  1. Click(点击)

    点击操作又可分为:Click、Double Click、Right Click,示例:

     import {Selector} from 'testcafe';
     
     fixture `Interact With the Page`.page`example`;
     
     test("Click Test", async (t) => {
         const btn = Selector("button").withText("Test")
         // await t.doubleClick(btn)
         // await t.rightClick(btn)
         await t.click(btn)
     })
    
    
  2. Press Key(键盘输入)

    Press Key操作用于一些键盘输入如:enter、shift等,具体如下:

         
         `backspace`
         `tab`
         `enter`
         `capslock`
         `esc`
         `space`
         `pageup`
         `pagedown`
         `end`
         `home`
         `left`
         `right`
         `up`
         `down`
         `ins`
         `delete`
     同时,pressKey还支持组合键:`ctrl+c`等

    示例:

     
     import { Selector } from 'testcafe'
     
     const nameInput = Selector("developer-name")
     
     fixture`TestController.pressKey`
         .page`https://devexpress.github.io/testcafe/example/`;
     
     test('Key Press', async (t) => {
         await t
             .typrText(nameInput, 'Peter Parker')
             .pressKey('home right . delete delete delete delete)
             .expect(nameInput.value).eql('P. Parker');
     }
     
  3. Type Text(输入文字)
  4. Select Text (选择文本)
  5. Hover(高亮)
  6. Scroll(滑动)
  7. Drag Element(拖动元素)
  8. Upload Files
  9. Work with iframes

testcafe当前支持的浏览器操作:

1.Navigate to a URL

(持续更新至完全~)


sayornottt
1 声望0 粉丝

姑且是测试开发工程师.