PhantomJs不使用硒

时间:2016-05-31 14:10:52

标签: javascript selenium selenium-webdriver phantomjs cucumber

我正在使用selenium和phantom js浏览器运行功能测试。为了给出一些上下文,我正在运行selenium(java -jar selenium-server-standalone-2.45.0.jar),然后运行命令for feature file(cucumber-js login _ip.feature -t @Dashboard),它应该显示UI。

由于PhantomJs预先安装了Ghostdriver,我希望不需要运行驱动程序。

World.js配置文件

var webdriverjs = require('webdriverio');

    var World;
    World = function World(callback) {
        'use strict';
        var client = webdriverjs.remote({
            desiredCapabilities: {
                browserName: 'phantomjs'
            },
            logLevel: 'silent'
        });

        var world = {
            client: client
        };
        callback(world);
    };
    exports.World = World;

我的黄瓜功能文件: -

Feature: Login ip user
  Background:
    Given that I am on the login page "http://ocdev3-web.ops.omgeollc.com:8002/cleartrust/ct_logon.jsp"
    And I entered correct  credentials  "user1ip83" "welcome1"
    When I select the second option in the oboList and click on enter button "3"
    Then I am on the home page
    And I pause "5000"
    When I click on Equity tab
    And I pause "6000"

  @Dashboard
  Scenario: Dashboard page with all the charts
    When I click on Dashboard from left nav
    Then I click on Debt & Equity under dashboard
    Then I can see the charts

Login_steps文件: -

var assert = require('assert');

module.exports = function() {
    'use strict';

    /* jshint validthis: true */
     var maxTimeOut = 15000;
    this.World = require('../../support/world.js').World;
    this.Given(/^that I am on the login page "([^"]*)"$/, function (arg1, callback) {
        this.client
            .init()
            .url(arg1)
            .call(callback);
    });

   this.Then(/^the browser title should be "([^"]*)"$/, function (arg1, callback) {

       this.client
           .getTitle(function (err, title) {
               if (title === arg1){
                   callback();
               }
               else{
                   callback('fail');
               }
           });
   });

    this.Then(/^I entered correct  credentials  "([^"]*)" "([^"]*)"$/, function (arg1,arg2,callback) {
        console.log('hello');
        this.client
            .setValue('#UserId', arg1)
            .setValue('#password', arg2)
            .click('#login-button')
            .call(callback);
    });



    this.When(/^I select the second option in the oboList and click on enter button "([^"]*)"$/,function(arg1,callback){

        this.client
            .pause(5000)
            .click('#obo-list')
             .click('//select[@id="obo-list"]/option[' +arg1 + ']')
             .click('#enter-button')
             .call(callback);

    });

    this.Then(/^I am on the home page$/, function (callback) {
        this.client
            .waitFor('#home-page', 6000)
            .elements('#home-page', function(err, elements) {
                assert(err === null);
                assert(elements.value.length === 1);
            })
        .call(callback);
    });

this.When(/^I click on Dashboard from left nav$/,function(callback){
        this.client
            .click('#left-nav-container > div > ul > li.k-item.k-first')
            .call(callback);
    });

    this.Then(/^I click on Equity under dashboard$/,function(callback){
        this.client
            .click('#left-nav-container > div > ul > li.k-item.k-first > ul > li')
            .call(callback);
    });
    this.Then(/^I can see the charts$/,function(callback){
        var self =  this.client;
        self.pause(2000);
        self.isExisting('#chart-container',function(err, existing){
            if(existing){
                self.pause(3000);
                callback();
            }else{
                callback('Fail');
            }
        });
    });

0 个答案:

没有答案