首页 > 编程 > JavaScript > 正文

protractor的安装与基本使用教程

2019-11-19 16:08:40
字体:
来源:转载
供稿:网友

前言

Protractor是一个建立在WebDriverJS基础上的端到端(E2E)的AngularJS JavaScript Web应用程序测试框架。Protractor全自动化真实的模拟用户在真正的浏览器中操作、运行并测试开发者的应用程序。下面就来一起看看关于protractor安装与基本使用的相关内容吧。

1、JDK的安装和环境的配置

     关于JDK的安装配置这里就不说了,需要的朋友们可以参考这篇文章

2、npm protractor

npm install -g protractor 

3、npm install protractor的依赖项

基于第二步下载到的文件,在命令行里面进入到nodejs ->protractor的目录

npm install 

4、test工程

包括一个简单的angular的页面,一个配置文件和一个测试文件

配置文件protractor_conf.js代码:

/** * Created by Administrator on 2015/4/24. */exports.config = { directConnect: true,  // Capabilities to be passed to the webdriver instance. capabilities: {  'browserName': 'chrome' },  // Spec patterns are relative to the current working directly when // protractor is called. specs: ['test.js'],  // Options to be passed to Jasmine-node. jasmineNodeOpts: {  showColors: true,  defaultTimeoutInterval: 30000 }}; 

test.js文件代码

/** * Created by Administrator on 2015/4/24. */describe('angularjs homepage', function () { it('should greet the named user', function () {  browser.get('http://localhost:63342/protractor/Index.html');  element(by.id('userName')).sendKeys(' Sparrow');  browser.sleep(4000); });}); 

Index.html的代码

<!DOCTYPE html><html data-ng-app="protractor"><head lang="en"> <meta charset="UTF-8"> <title></title></head><body><div data-ng-controller="myAppController"> {{userName}} <input id="userName" data-ng-model="userName" /></div></body><script src="lib/angular.min.js"></script><script> var app = angular.module('protractor',[]); app.controller('myAppController',['$scope',function($scope){  $scope.userName = 'Jackey'; }]);</script> </html> 

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对武林网的支持。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表