testcafe和WebdriverIO介绍

什么是WebdriverIO?

webdrivero可以用于各种用途。它实现了Webdriver协议API,可以自动运行浏览器。该框架设计用于任何环境和任何类型的任务。它独立于任何第三方框架,只需要Node.js节点去跑步。

单独模式

运行WebdriverIO最简单的形式可能是在独立模式下。这与Selenium服务器文件(通常称为Selenium服务器独立文件)无关。它基本上只是意味着您需要在项目中使用webdriverio包,并使用它的API来运行自动化。

下面是一个简单的例子:

const { remote } = require('webdriverio');(async () => {    const browser = await remote({        logLevel: 'trace',        capabilities: {            browserName: 'chrome'        }    })    await browser.url('https://duckduckgo.com')    const inputElem = await browser.$('#search_form_input_homepage')    await inputElem.setValue('WebdriverIO')    const submitBtn = await browser.$('#search_button_homepage')    await submitBtn.click()    console.log(await browser.getTitle()) // outputs: "Title is: WebdriverIO (Software) at DuckDuckGo"    await browser.deleteSession()})().catch((e) => console.error(e))

Testcafe/Webdriver技能

使用testcafe/网络驱动程序.io编写一些e2e测试用例http://todomvc.com/examples/react/

安装cypress
 

cnpm install cypress --save-dev✔ Installed 1 packages✔ Linked 176 latest versions[1/1] scripts.postinstall cypress@* run "node index.js --exec install", root: "/Users/apple/PythonProjects/testcaftdemo/node_modules/[email protected]@cypress"Installing Cypress (version: 4.6.0)  ✔  Downloaded Cypress  ✔  Unzipped Cypress  ✔  Finished Installation /Users/apple/Library/Caches/Cypress/4.6.0You can now open Cypress by running: node_modules/.bin/cypress openhttps://on.cypress.io/installing-cypress[1/1] scripts.postinstall cypress@* finished in 3m

一个Node.js节点自动化端到端web的工具测试。写入在JS或TypeScript中测试,运行它们并查看结果

什么是E2E测试?

端到端的测试是从开始到结束测试整个应用程序的地方。它包括确保应用程序的所有集成部分都能按预期协同工作。

端到端测试模拟真实的用户场景,本质上测试真实用户将如何使用应用程序。

什么是TestCafe?

它的关键特性是它不像其他解决方案那样使用WebDriver来处理浏览器。这就是为什么它只需要最少的测试环境,并且只需要一个命令就可以安装它。此外,这种方法允许您在任何物理设备上运行测试,而不需要浏览器。自动等待以及优雅和信息丰富的控制台记者。TestCafe的主要缺点是它不久前就出现了,而且它的社区比竞争对手小得多。特点比appium的selenum不需要加sleep进行等待。

安装TestCafe

npm install -g TestCafe

创建一个test

TestCafe允许您使用TypeScript或JavaScript(其现代特性如async/await)编写测试。通过使用TypeScript编写TestCafe测试,您可以获得强类型语言的优势,例如:丰富的编码帮助、无痛的可伸缩性、键入时检查代码验证等等。

要创建测试,请在计算机上的任何位置创建新的.js或.ts文件(测试.js). 这个文件必须有一个特殊的结构:测试必须组织成fixture

1)首次导入testcafe选择器

import { Selector } from 'testcafe';

2)设置

例子中直接用.page的方式,直接可以打开一个浏览器的例子,testcafe和seleium的比较像,testcafe上手比较快。直接可以拿例子修改。

fixture `Getting Started`    .page `http://devexpress.github.io/testcafe/example`;

3)创建一个测试并将代码放在那里

import { Selector } from 'testcafe';fixture `New Fixture`    .page `http://127.0.0.1:8000/admin/`;test('登录增加blog', async t => {    await t        .typeText(Selector('#id_username'),'admin')        .pressKey('tab')        .typeText(Selector('#id_password'), 'admin')        .pressKey('enter')        .click(Selector('a').withText('Blog articless'))        .click(Selector('a').withText('增加 BLOG ARTICLES'))        .typeText(Selector('#id_title'), 'you test')        .typeText(Selector('#id_author'), '1')        .typeText(Selector('#id_body'), 'you test')        .click(Selector('#blogarticles_form').find('[name="_save"]'))});

4)运行命令查看浏览器

testcafe -b 可以查看几个浏览器,有2个浏览器

testcafe -b

chrome

safari

5)运行

结果例子,testcafe会打开浏览器,执行上面的例子,模拟点击浏览器

testcafe chrome blog*.js

 Running tests in:

 - Chrome 83.0.4103.61 / macOS 10.14.6

 blogdel

 ✓ New Test

 New Fixture

​ ✓ 登录增加blog

猜你喜欢

转载自blog.csdn.net/keny88888/article/details/106311849