2016-09-19 8 views
0

現在私の会社のウェブサイトにはSelenium WebdriverとCucumberを使用して自動テストスクリプトを作成しています。これを行うために、私はMatt-B's exampleを開始として使用しました。ファイルを取得するので、私はにgoogle.featureの内容を変更:セレンテストスクリプトの作成時に "TypeError:obj.indexOfが関数ではありません"エラー

Feature: Changing Pages 
    As an internet user 
    In order to move through a website 
    I want to be able to click a button and go to another page 

    Scenario: Digital3rd Testing page 
     Given I am on the Digital3rd website 
     When I click the "Testing" button 
     Then I should go to "../testing" 

そして今、このためにGoogle-steps.jsを変更し始めている:

'use strict'; 

var expect = require('chai').expect; 

module.exports = function() { 
    this.World = require('../support/world.js').World; 

    this.Given(/^I am on the Digital(\d+)rd website$/, function (arg1, callback) { //declaring function that relates to Cucumber Script 
     this.driver.get('http://www.Digital3rd.org'); //open intended website 
    callback(null, 'set-up'); 
    }); 

    this.When(/^I click the "([^"]*)" button$/, function (arg1, callback) { //declaring function that relates to Cucumber Script 
     this.onload = //when the page loads... 
     this.driver.manage().window().maximize(); //maximise the screen... 
     this.driver.findElement({id: 'menu-item-24'}).click(); //click the "Testing" button. 
    callback(null, 'test'); 
    }); 

    this.Then(/^I should go to "([^"]*)"$/, function (promise) { 
     var wbaddrss = this.driver.getCurrentUrl(); 
     return expect(wbaddrss).to.contain('/testing'); 
    }); 
}; 

最初の2つのステップは、開口部により正常に動作しますウェブサイトを最大化してボタンをクリックします。私は現在、URLのセクションを使って正しいページにいることを検証しようとしています。 "TypeError:obj.indexOfは関数ではありません"というエラーを修正したり、代替案を与えてくれてありがとうございました。申し訳ありませんが単純な答えですが、これは私がこのようなことをしたのは初めてです。

私はコンソールに入る完全なエラーコードは次のとおりです。

TypeError: obj.indexOf is not a function 
    at Assertion.include (C:\Users\User\Test program\node_modules\chai\lib\chai\core\assertions.js:228:45) 
    at Assertion.assert (C:\Users\User\Test program\node_modules\chai\lib\chai\utils\addChainableMethod.js:84:49) 
    at World.<anonymous> (C:\Users\User\Test program\features\step_definitions\google-steps.js:32:30) 
    at nextTickCallbackWith0Args (node.js:420:9) 
    at process._tickCallback (node.js:349:13) 

答えて

-1

のindexOfは、アレイのプロパティではなく、オブジェクトの

+0

[OK]を、よく私は、複数のサイトがあなたを言いましたそれを使って私がここで試していた文字列から部分文字列を見つけることができます –

+0

あなたのobjは何ですか?それは文字列ですか? –

+0

私のコードを見ると、URLを取得してvarに保存してからChaiの "expect"を使って実行すると仮定します –

0

私はちょうどチャイにexpect(object).to.contain('string')と同じ問題に遭遇し、希望何が起こっているのかを突き止めるためにそれを進めていくことです。一方、あなたは慎重match()機能ではなく、contain()とJSの正規表現を使用することができます。

expect(object1).to.match(/String to contain/); 
expect(object2).to.match(/^Exact string to match$/); 

expect(object3).to.match(/^This string might contain other things/); 
expect(object3).to.match(/before it ends here$/); 

この他を参照してください、正規表現で変数を使用するにはSO答え:https://stackoverflow.com/a/17886301/949911/

関連する問題