源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

protractor的安装与基本使用教程

  • 时间:2022-12-06 13:21 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:protractor的安装与基本使用教程
[b]前言[/b] Protractor是一个建立在WebDriverJS基础上的端到端(E2E)的AngularJS JavaScript Web应用程序测试框架。Protractor全自动化真实的模拟用户在真正的浏览器中操作、运行并测试开发者的应用程序。下面就来一起看看关于protractor安装与基本使用的相关内容吧。 [b]1、JDK的安装和环境的配置[/b]      关于JDK的安装配置这里就不说了,需要的朋友们可以参考[url=http://www.1sucai.cn/article/95890.htm]这篇文章[/url] [b]2、npm protractor[/b]
npm install -g protractor 
[b]3、npm install protractor的依赖项[/b] 基于第二步下载到的文件,在命令行里面进入到nodejs ->protractor的目录
npm install 
[b]4、test工程[/b] 包括一个简单的angular的页面,一个配置文件和一个测试文件 [img]http://files.jb51.net/file_images/article/201707/20177792455709.png?2017679258[/img] 配置文件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> 
[b]总结[/b] 以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对编程素材网的支持。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部