zoukankan      html  css  js  c++  java
  • 使用Protractor进行AngularJS e2e测试案例

    环境:

    y@y:karma-t01$ protractor --version
    Version 3.0.0
    y@y:karma-t01$ node -v
    v4.2.2
    y@y:karma-t01$ 
    y@y:karma-t01$ webdriver-manager update
    y@y:karma-t01$ webdriver-manager start

    安装http-server:

    y@y:karma-t01$ npm install -g http-server
    y@y:karma-t01$ http-server    -p    8080

    浏览器:Chrome 版本 46.0.2490.86 (64-bit)

    目录结构:

    y@y:karma-t01$ tree -L 2
    .
    ├── client
    │   ├── app
    │   ├── bower_components
    │   └── bower.json
    ├── e2e
    │   └── todo
    ├── karma.conf.js
    ├── protractor.conf.js
    └── readme

    (1)e2e/todo/todo.spec.js

    'use strict';
    
    describe('',function(){
    
    
        beforeEach(function(){
            browser.get('/client/app/todo/todo.html');
        });
    
        it('',function(){
            var todoListItems = element.all(by.repeater('item in list'));
    
            expect(todoListItems.count()).toBe(3);
        });
    });

    (2)client/app/todo/todo.js

    'use strict';
    
    var app = angular.module('Application',[]);
    
    app.controller('TodoCtrl',function($scope){
        $scope.list = ['user1','user2','user3'];
    
    
    });

    (3)client/app/todo/todo.html

    <!DOCTYPE html>
    <html>
    <head lang="en">
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body ng-app="Application">
    
        <div ng-controller="TodoCtrl">
            <ul ng-repeat="item in list">
                <li>{{item}}</li>
            </ul>
        </div>
    
        <script src="../../bower_components/angular/angular.js"></script>
        <script src="todo.js"></script>
    </body>
    </html>

    (4)protractor.conf.js

    'use strict';
    
    exports.config = {
      allScriptsTimeout: 110000,
    
      baseUrl: 'http://localhost:8080',
    
      chromeOnly: true,
    
      specs: [
        'e2e/**/*.spec.js'
      ],
    
      exclude: [],
    
      capabilities: {
        'browserName': 'chrome'
      },
    
      framework: 'jasmine',
    
      jasmineNodeOpts: {
        defaultTimeoutInterval: 30000
      }
    };

    进行测试:

    (1)启动webdriver构建测试工程

    y@y:karma-t01$ webdriver-manager start
    seleniumProcess.pid: 27021
    13:17:58.939 INFO - Launching a standalone Selenium Server

    (2)启动http服务

    y@y:karma-t01$ http-server -p 8080
    Starting up http-server, serving ./
    Available on:
      http:127.0.0.1:8080
      http:192.168.0.177:8080
    Hit CTRL-C to stop the server

    (3)运行测试脚本

    y@y:karma-t01$ protractor protractor.conf.js 
    Starting selenium standalone server...
    [launcher] Running 1 instances of WebDriver
    Selenium standalone server started at http://192.168.0.177:47286/wd/hub
    Started
    .
    
    
    1 spec, 0 failures
    Finished in 1.207 seconds
    Shutting down selenium standalone server.
    [launcher] 0 instance(s) of WebDriver still running
    [launcher] chrome #1 passed
  • 相关阅读:
    spring容器与java访问权限的关系!
    Mybatis初始化过程详解
    Spring-boot 一些常用注解说明!
    JNDI + Spring 如何读取数据
    HashMap,,ConcurrentHashMap------------------浅谈!!
    spring ioc容器和spring mvc 容器--------浅谈!!
    针对xml文件做提取与写入的操作
    vim编辑器显示行号
    ubuntu双系统修复windows引导
    git基本操作
  • 原文地址:https://www.cnblogs.com/yshyee/p/5004652.html
Copyright © 2011-2022 走看看