实习生WebDriver和PhantomJS [英] Intern WebDriver and PhantomJS

查看:138
本文介绍了实习生WebDriver和PhantomJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在浏览器(client.html)中进行测试时编写了我的主要单元测试,现在我可以通过Node设置测试自动化了,但是我还没有Selenium服务器设置,因此管理也许永远不会允许使用像Sauce Labs这样的第三方服务,所以我试图使用PhantomJS的webdriver模式通过PhantomJS运行Intern测试.

I've written my main unit tests while testing in the browser (client.html), and now I'm ready to setup test automation through Node, however I don't have a Selenium server setup yet, and management will probably never give the okay to use a third party service like Sauce Labs, so I'm trying to run Intern test through PhantomJS using it's webdriver mode.

我正在使用以下选项运行PhantomJS:

I'm running PhantomJS with these options:

$ phantomjs --ignore-ssl-errors=true --web-security=false --webdriver=8910

我的实习生配置如下:

define({
  proxyPort: 9000,
  proxyUrl: 'http://localhost:9000/',
  environments: [
    {
      browserName: 'phantom',
      version: '1.9.0',
      platform: 'Linux'
    }
  ],
  webdriver: {
    host: 'localhost',
    port: 8910
  },
  maxConcurrency: 3,
  useSauceConnect: false,
  // ...
});

这似乎在大多数情况下都有效,但是我在测试中遇到了有关AJAX请求的问题.由于测试是通过Intern自己的服务器运行的,因此我添加了AJAX过滤器,以确保将请求发送到正确的位置:

It seems to work for the most part, however my I am having issues with AJAX requests in my tests. Since tests are run through Intern's own server, I've added an AJAX filter to make sure requests are sent to the correct place:

$.ajaxPrefilter(function (options) {
  options.url = serverName + options.url;
});

我仍然发现我的AJAX请求失败.经过进一步检查,我发现请求没有被发送(AJAX失败,readyState为0). PhantomJS似乎没有提供更多的信息. phantomjs--web-security=false标志应确保可以进行跨域请求,因此我不确定原因.

I'm still finding that my AJAX requests are failing however. Upon further inspection I've found that the requests aren't being sent (AJAX fails with a readyState of 0). PhantomJS doesn't seem to provide any more information than this. The --web-security=false flag for phantomjs should ensure that cross-domain requests are possible, so I'm unsure of the cause.

PhantomJS中不会引发任何特定的错误,唯一提供给失败处理程序的信息是错误"状态.

No specific error is thrown in PhantomJS, the only information given to the fail handler is a status of "error".

我尝试过在没有jQuery的情况下执行手动XMLHttpRequest,并且成功完成了工作.很显然,这是jQuery的目的.启用crossDomain不能解决该问题.

I've tried doing a manual XMLHttpRequest without jQuery, and it works successfully. So clearly this is something on jQuery's end. Enabling the crossDomain doesn't fix it.

推荐答案

因此,由于我尚未弄清楚的原因,在AJAX配置中使用method而不是type解决了该问题(我偶然发现了那是偶然的).我不太清楚为什么,因为method只是jQuery中type的别名:

So, for reasons I haven't quite figured out yet, using method instead of type in the AJAX config resolved the issue (I stumbled upon that by accident). I can't quite see why, since method is just an alias for type in jQuery:

s.type = options.method || options.type || s.method || s.type;

无论如何,这确实为我解决了这个问题.

Regardless, this did fix the issue for me.

这篇关于实习生WebDriver和PhantomJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆