CodeCeption -- 使用
来源:互联网 发布:windows装tensorflow 编辑:程序博客网 时间:2024/05/07 01:29
一、命令行运行
安装成功Codeception之后,有以下命令进行操作
Available commands:
bootstrap Creates default test suites and generates all requires files安装成功Codeception之后,有以下命令进行操作
Available commands:
build Generates base classes for all suites
clean Cleans or creates _log directory
console Launches interactive test console
help Displays help for a command
list Lists commands
run Runs the test suites
generate
generate:cept Generates empty Cept file in suite
generate:cest Generates empty Cest file in suite
generate:group
generate:helper Generates new helper
generate:pageobject Generates empty PageObject class
generate:phpunit Generates empty PHPUnit test without Codeception additions
generate:scenarios Generates text representation for all scenarios
generate:stepobject Generates empty StepObject class
generate:suite Generates new test suite
generate:test Generates empty unit test file in suite
其中,可以使用generate:cest来创建一个测试类
<span style="font-size:14px;">php codecept generate:cest acceptance BasicTest</span>
这将在tests/acceptance下面创建一个名为BasicTestCest.php的文件。
我们可以再里面写入
<span style="font-size:14px;"> // tests public function tryToTest(AcceptanceTester $I) { $I->amOnPage('/'); $I->see('首页'); }</span>如果我们的配置正确,并且我们的首页确实有'首页两个字的话',当我们运行这个测试,就可以PASSED!
配置文件时在acceptance.suite.yml里面进行配置
class_name: AcceptanceTester
modules:
enabled:
- PhpBrowser
- AcceptanceHelper
config:
PhpBrowser:
url: 'http://www.shouye.com' //我们自己的url
第一行为测试父类的名称
加载的模块和类
所请求的地址
然后,运行的命令为run 后面可以接-d 调试; --steps一步一步显示操作; --html='outPut.html' html输出
php codecept run --steps -d acceptance BasicTestCest.php:tryToTest
就可以成功运行了!
二、测试代码编写
具体的代码编写也很简单而且人性化
比如写个登陆的测试
public function login(WebGuy $I) { $I->amOnPage('/login'); $I->see('登录'); $I->fillField("#loginUserName", "user"); $I->fillField("#loginUserPwd", "password"); $I->click('#login_btn'); }amOnPage函数表示到达这个页面
see表示能看到里面的字符。这里表示登陆
fillField表示在什么地方填写什么东西
click表示一个点击
文档中均有接口的说明,可以参考接口说明和Webdriver这个源码进行操作
如果要进行稍微复杂一点的js操作,可以直接进行执行
executeJS(js),如果要直接编写webdriver代码可以执行下面这个函数
/** * Low-level API method. * If Codeception commands are not enough, use Selenium WebDriver methods directly * * ``` php * $I->executeInSelenium(function(\WebDriver $webdriver) { * $webdriver->get('http://google.com'); * }); * ``` * * Use [WebDriver Session API](https://github.com/facebook/php-webdriver) * Not recommended this command too be used on regular basis. * If Codeception lacks important Selenium methods implement then and submit patches. * * @param callable $function */ public function executeInSelenium(\Closure $function) { return $function($this->webDriver); }
总之,我们的代码,调用了webdriver,webdriver调用了浏览器,执行操作。
PS:webdriver是无法获取iframe里面的数据
0 0
- CodeCeption -- 使用
- codeception 基础使用[简译]
- Yii2中如何使用CodeCeption
- CodeCeption -- 初探
- codeception快速入门
- codeception的Module们
- reference for codeception
- Codeception API testing
- debug codeception in Eclipse
- codeception 运行testcase 的方式
- YII2中Codeception的安装
- PHP 行为测试工具 Codeception 介绍
- swagger + codeception 测试自动化落地方案
- PHP 行为测试工具 Codeception 介绍
- 利用codeception过程中遇到的问题及解决方式
- 使用
- 使用
- 使用
- 比较一下主流国际快递系统 国际快递公司如何选择
- html4标签语义化给予的常用标签作用讲解
- 信息平台时间错误或者不更新
- Thrift初探:简单实现C#通讯服务程序
- 关于<ul>标签“·”跑远的问题
- CodeCeption -- 使用
- 分布式文件系统FastDFS架构剖析
- Wireshark数据抓包分析(网络协议篇)1.2安装Wireshark
- 四种途径将HTML5应用变成android应用
- Android下的BLE编程解析(二)
- 慢慢来吧
- Linux中的工作队列
- 设备管理
- ObjectMapper