设置方法的watir无效参数错误

时间:2017-08-31 07:08:52

标签: ruby watir watir-webdriver

我正在使用watir和ruby来编写页面对象模式UI框架。这工作正常,直到我进行捆绑更新

我有一个yml文件代表像这样的页面

username:
 field: text_field
 attribute: name
 value: username
 default:
 operations:
  - exists?
  - set

一个页面对象方法生成器,它将其输入

def generate(elements)
    elements.each do |element|
        element[1]['operations'].each do |operation|
            if operation.eql? 'set'
                default = element[1]['default']
                self.class.send(:define_method, "#{element[0]}_#{operation}") do |default=''|
                    @b.send(element[1]['field'], element[1]['attribute'].to_sym, element[1]['value']).send(operation, default)
                end
            else
                self.class.send(:define_method, "#{element[0]}_#{operation}") do
                    @b.send(element[1]['field'], element[1]['attribute'].to_sym, element[1]['value']).send(operation)
                end
            end
        end
    end
end

当我对chrome运行watir测试时,这似乎工作正常。但是,当我的浏览器是Firefox时,我收到错误Expected [object Undefined] undefined to be a string (Selenium::WebDriver::Error::InvalidArgumentError)

生成方法中的第6行抛出该错误

这就是我将yml传递给generate方法

的方法
def initialize(browser)
    file_path = File.expand_path("../config/signin.yml", __FILE__)
    elements = YAML.load(File.read(file_path));
    super(browser, elements)
end

watir version 6.8.0 selenium-webdriver版本3.5.1 geckodriver-helper 0.0.3

更新

完整的堆栈跟踪:

http://127.0.0.1:4444/session/02500e7f-0c52-1e40-b151-39b2d857d17f/execute/sync | {"script":"return (function(){return function(){var d=this;function f(a){return\"string\"==typeof a};function h(a,b){this.code=a;this.a=l[a]||m;this.message=b||\"\";a=this.a.replace(/((?:^|\\s+)[a-z])/g,function(a){return a.toUpperCase().replace(/^[\\s\\xa0]+/g,\"\")});b=a.length-5;if(0>b||a.indexOf(\"Error\",b)!=b)a+=\"Error\";this.name=a;a=Error(this.message);a.name=this.name;this.stack=a.stack||\"\"}\n(function(){var a=Error;function b(){}b.prototype=a.prototype;h.b=a.prototype;h.prototype=new b;h.prototype.constructor=h;h.a=function(b,c,g){for(var e=Array(arguments.length-2),k=2;k<arguments.length;k++)e[k-2]=arguments[k];return a.prototype[c].apply(b,e)}})();var m=\"unknown error\",l={15:\"element not selectable\",11:\"element not visible\"};l[31]=m;l[30]=m;l[24]=\"invalid cookie domain\";l[29]=\"invalid element coordinates\";l[12]=\"invalid element state\";l[32]=\"invalid selector\";l[51]=\"invalid selector\";\nl[52]=\"invalid selector\";l[17]=\"javascript error\";l[405]=\"unsupported operation\";l[34]=\"move target out of bounds\";l[27]=\"no such alert\";l[7]=\"no such element\";l[8]=\"no such frame\";l[23]=\"no such window\";l[28]=\"script timeout\";l[33]=\"session not created\";l[10]=\"stale element reference\";l[21]=\"timeout\";l[25]=\"unable to set cookie\";l[26]=\"unexpected alert open\";l[13]=m;l[9]=\"unknown command\";h.prototype.toString=function(){return this.name+\": \"+this.message};var n;a:{var p=d.navigator;if(p){var q=p.userAgent;if(q){n=q;break a}}n=\"\"}function r(a){return-1!=n.indexOf(a)};function t(a,b){for(var e=a.length,c=f(a)?a.split(\"\"):a,g=0;g<e;g++)g in c&&b.call(void 0,c[g],g,a)};function v(){return r(\"iPhone\")&&!r(\"iPod\")&&!r(\"iPad\")};function w(){return(r(\"Chrome\")||r(\"CriOS\"))&&!r(\"Edge\")};var x=r(\"Opera\"),y=r(\"Trident\")||r(\"MSIE\"),z=r(\"Edge\"),A=r(\"Gecko\")&&!(-1!=n.toLowerCase().indexOf(\"webkit\")&&!r(\"Edge\"))&&!(r(\"Trident\")||r(\"MSIE\"))&&!r(\"Edge\"),aa=-1!=n.toLowerCase().indexOf(\"webkit\")&&!r(\"Edge\");function B(){var a=d.document;return a?a.documentMode:void 0}var C;\na:{var D=\"\",E=function(){var a=n;if(A)return/rv\\:([^\\);]+)(\\)|;)/.exec(a);if(z)return/Edge\\/([\\d\\.]+)/.exec(a);if(y)return/\\b(?:MSIE|rv)[: ]([^\\);]+)(\\)|;)/.exec(a);if(aa)return/WebKit\\/(\\S+)/.exec(a);if(x)return/(?:Version)[ \\/]?(\\S+)/.exec(a)}();E&&(D=E?E[1]:\"\");if(y){var F=B();if(null!=F&&F>parseFloat(D)){C=String(F);break a}}C=D}var G;var H=d.document;G=H&&y?B()||(\"CSS1Compat\"==H.compatMode?parseInt(C,10):5):void 0;var ba=r(\"Firefox\"),ca=v()||r(\"iPod\"),da=r(\"iPad\"),I=r(\"Android\")&&!(w()||r(\"Firefox\")||r(\"Opera\")||r(\"Silk\")),ea=w(),J=r(\"Safari\")&&!(w()||r(\"Coast\")||r(\"Opera\")||r(\"Edge\")||r(\"Silk\")||r(\"Android\"))&&!(v()||r(\"iPad\")||r(\"iPod\"));function K(a){return(a=a.exec(n))?a[1]:\"\"}(function(){if(ba)return K(/Firefox\\/([0-9.]+)/);if(y||z||x)return C;if(ea)return v()||r(\"iPad\")||r(\"iPod\")?K(/CriOS\\/([0-9.]+)/):K(/Chrome\\/([0-9.]+)/);if(J&&!(v()||r(\"iPad\")||r(\"iPod\")))return K(/Version\\/([0-9.]+)/);if(ca||da){var a=/Version\\/(\\S+).*Mobile\\/(\\S+)/.exec(n);if(a)return a[1]+\".\"+a[2]}else if(I)return(a=K(/Android\\s+([0-9.]+)/))?a:K(/Version\\/([0-9.]+)/);return\"\"})();var L,M=function(){if(!A)return!1;var a=d.Components;if(!a)return!1;try{if(!a.classes)return!1}catch(g){return!1}var b=a.classes,a=a.interfaces,e=b[\"@mozilla.org/xpcom/version-comparator;1\"].getService(a.nsIVersionComparator),c=b[\"@mozilla.org/xre/app-info;1\"].getService(a.nsIXULAppInfo).version;L=function(a){e.compare(c,\"\"+a)};return!0}(),N=y&&!(8<=Number(G)),fa=y&&!(9<=Number(G));I&&M&&L(2.3);I&&M&&L(4);J&&M&&L(6);var ga={SCRIPT:1,STYLE:1,HEAD:1,IFRAME:1,OBJECT:1},O={IMG:\" \",BR:\"\\n\"};function P(a,b,e){if(!(a.nodeName in ga))if(3==a.nodeType)e?b.push(String(a.nodeValue).replace(/(\\r\\n|\\r|\\n)/g,\"\")):b.push(a.nodeValue);else if(a.nodeName in O)b.push(O[a.nodeName]);else for(a=a.firstChild;a;)P(a,b,e),a=a.nextSibling};function Q(a,b){b=b.toLowerCase();return\"style\"==b?ha(a.style.cssText):N&&\"value\"==b&&R(a,\"INPUT\")?a.value:fa&&!0===a[b]?String(a.getAttribute(b)):(a=a.getAttributeNode(b))&&a.specified?a.value:null}var ia=/[;]+(?=(?:(?:[^\"]*\"){2})*[^\"]*$)(?=(?:(?:[^']*'){2})*[^']*$)(?=(?:[^()]*\\([^()]*\\))*[^()]*$)/;\nfunction ha(a){var b=[];t(a.split(ia),function(a){var c=a.indexOf(\":\");0<c&&(a=[a.slice(0,c),a.slice(c+1)],2==a.length&&b.push(a[0].toLowerCase(),\":\",a[1],\";\"))});b=b.join(\"\");return b=\";\"==b.charAt(b.length-1)?b:b+\";\"}function S(a,b){N&&\"value\"==b&&R(a,\"OPTION\")&&null===Q(a,\"value\")?(b=[],P(a,b,!1),a=b.join(\"\")):a=a[b];return a}function R(a,b){b&&\"string\"!==typeof b&&(b=b.toString());return!!a&&1==a.nodeType&&(!b||a.tagName.toUpperCase()==b)}\nfunction T(a){return R(a,\"OPTION\")?!0:R(a,\"INPUT\")?(a=a.type.toLowerCase(),\"checkbox\"==a||\"radio\"==a):!1};var ja={\"class\":\"className\",readonly:\"readOnly\"},U=\"async autofocus autoplay checked compact complete controls declare defaultchecked defaultselected defer disabled draggable ended formnovalidate hidden indeterminate iscontenteditable ismap itemscope loop multiple muted nohref noresize noshade novalidate nowrap open paused pubdate readonly required reversed scoped seamless seeking selected spellcheck truespeed willvalidate\".split(\" \");function V(a,b){var e=null,c=b.toLowerCase();if(\"style\"==c)return(e=a.style)&&!f(e)&&(e=e.cssText),e;if((\"selected\"==c||\"checked\"==c)&&T(a)){if(!T(a))throw new h(15,\"Element is not selectable\");b=\"selected\";e=a.type&&a.type.toLowerCase();if(\"checkbox\"==e||\"radio\"==e)b=\"checked\";return S(a,b)?\"true\":null}var g=R(a,\"A\");if(R(a,\"IMG\")&&\"src\"==c||g&&\"href\"==c)return(e=Q(a,c))&&(e=S(a,c)),e;if(\"spellcheck\"==c){e=Q(a,c);if(null!==e){if(\"false\"==e.toLowerCase())return\"false\";if(\"true\"==e.toLowerCase())return\"true\"}return S(a,\nc)+\"\"}g=ja[b]||b;a:if(f(U))c=f(c)&&1==c.length?U.indexOf(c,0):-1;else{for(var u=0;u<U.length;u++)if(u in U&&U[u]===c){c=u;break a}c=-1}if(0<=c)return(e=null!==Q(a,b)||S(a,g))?\"true\":null;try{var k=S(a,g)}catch(ka){}(c=null==k)||(c=typeof k,c=\"object\"==c&&null!=k||\"function\"==c);c?e=Q(a,b):e=k;return null!=e?e.toString():null}var W=[\"_\"],X=d;W[0]in X||!X.execScript||X.execScript(\"var \"+W[0]);\nfor(var Y;W.length&&(Y=W.shift());){var Z;if(Z=!W.length)Z=void 0!==V;Z?X[Y]=V:X[Y]&&X[Y]!==Object.prototype[Y]?X=X[Y]:X=X[Y]={}};; return this._.apply(null,arguments);}.apply({navigator:typeof window!='undefined'?window.navigator:null,document:typeof window!='undefined'?window.document:null}, arguments);}\n).apply(null, arguments)","args":[{"element-6066-11e4-a52e-4f735466cecf":"cae111e7-8b5a-6747-8835-b4fa9d8d0c42"},"readOnly"]}
2017-09-01 15:04:51 DEBUG Selenium      > {"Accept"=>"application/json", "Content-Type"=>"application/json; charset=utf-8", "Content-Length"=>"6725"}
2017-09-01 15:04:51 INFO Selenium <- {"value":null}
2017-09-01 15:04:51 INFO Selenium -> POST session/02500e7f-0c52-1e40-b151-39b2d857d17f/element/cae111e7-8b5a-6747-8835-b4fa9d8d0c42/clear
2017-09-01 15:04:51 INFO Selenium <- {"value": {}}
2017-09-01 15:04:51 INFO Selenium -> POST session/02500e7f-0c52-1e40-b151-39b2d857d17f/element/cae111e7-8b5a-6747-8835-b4fa9d8d0c42/value
2017-09-01 15:04:51 INFO Selenium    >>> http://127.0.0.1:4444/session/02500e7f-0c52-1e40-b151-39b2d857d17f/element/cae111e7-8b5a-6747-8835-b4fa9d8d0c42/value | {"value":["s","a","n","d","e","e","p",".","k","u","m","a","r","@","v","o","c","u","s",".","c","o","m",".","a","u"],"text":"sandeep.kumar@vocus.com.au"}
2017-09-01 15:04:51 DEBUG Selenium      > {"Accept"=>"application/json", "Content-Type"=>"application/json; charset=utf-8", "Content-Length"=>"151"}
2017-09-01 15:04:51 INFO Selenium <- {"value":{"error":"invalid argument","message":"Expected [object Undefined] undefined to be a string","stacktrace":"stack backtrace:\n   0:        0x10f2b179e - backtrace::backtrace::trace::h5d936e38aaf1110e\n   1:        0x10f2b1edc - backtrace::capture::Backtrace::new::h90c05c8c72e0f6cd\n   2:        0x10f1f5ca0 - geckodriver::marionette::MarionetteSession::response::h08aa31b0bbd51dd7\n   3:        0x10f1f3655 - _$LT$geckodriver..marionette..MarionetteHandler$u20$as$u20$webdriver..server..WebDriverHandler$LT$geckodriver..marionette..GeckoExtensionRoute$GT$$GT$::handle_command::h5bcbc41bc7c51981\n   4:        0x10f1c1830 - std::panicking::try::do_call::h532e0d8672b70b60\n   5:        0x10f33270a - __rust_maybe_catch_panic\n   6:        0x10f1d2896 - _$LT$F$u20$as$u20$alloc..boxed..FnBox$LT$A$GT$$GT$::call_box::h4a379663166b1095\n   7:        0x10f330ba4 - std::sys::imp::thread::Thread::new::thread_start::hf410a68837ea407b\n   8:     0x7fffcbbff93a - _pthread_body\n   9:     0x7fffcbbff886 - _pthread_start"}}
  Scenario: QB Ethernet UI validations # features/ui_validations_vocusone.feature:13
    Given QB Ethernet UI validations   # features/step_definitions/ui_validations_vocusone.rb:61
      Expected [object Undefined] undefined to be a string (Selenium::WebDriver::Error::InvalidArgumentError)
      ./features/support/pages/page.rb:35:in `block (3 levels) in generate'
      ./features/step_definitions/ui_validations_vocusone.rb:63:in `/^QB Ethernet UI validations$/'
      features/ui_validations_vocusone.feature:14:in `Given QB Ethernet UI validations'
2017-09-01 15:04:51 INFO Selenium -> DELETE session/02500e7f-0c52-1e40-b151-39b2d857d17f
1504242291281   Marionette      INFO    New connections will no longer be accepted
2017-09-01 15:04:51 INFO Selenium <- {"value": {}}

1 个答案:

答案 0 :(得分:0)

我查看了我发布的问题以及我的代码。意识到我提到了bundle update搞砸了可执行代码,我看了看Gemfile。我发现罪魁祸首是geckodriver-helper,这违反了我通过geckodriver安装的homebrew

获得的经验:通过自制软件或gemfile安装,但不能同时安装