1

I am currently using webdriver io via nodejs with selenium standalone, which all works fine until I try to do CORS based requests. I am currently using firefox as the test browser and it throws an error due to the CORS request to another domain.

The server is configured to return the correct headers for CORS and the XHR object is configured to allow CORS. I know these work as when I am manually using the site via firefox/chrome it works as expected, however when I am testing it just seems to blow up, which baffles me as the server and client are configured for CORS, and there is no HTTPS involved in the current tests.

So is there anything special I have to do to get CORS working in the test browsers? I know Selenium boots the browsers up in its own profile but I cannot find any details relating to cors in the configuration for the browser settings, nor can I find any dependentFeatures related to the CORS implementations.

I am happy to provide more information if it would help yield an answer.

4

1 回答 1

3

First, CORS is working in your browsers, but due to how Selenium works and due to your application logic they could conflict a bit.

I would advice to turn CORS check off only for Selenium.

For Chrome it will be easy to turn off CORS checks by adding "disable-web-security" to capabilities. For Firefox it will be "security.fileuri.strict_origin_policy" preference (NOT a capability). For example using https://github.com/saadtazi/firefox-profile-js

var FirefoxProfile = require('firefox-profile'),
    webdriverjs = require('webdriverjs');

var fp = new FirefoxProfile();
fp.setPreference("security.fileuri.strict_origin_policy", false);

fp.encoded(function(prof) {

    var client = webdriverjs.remote({
        desiredCapabilities: {
            browserName: 'firefox',
            firefox_profile: prof
        }
    });

    client
        .init()
        .url('http://stackoverflow.com/')
        .end();

});
于 2015-04-05T12:29:12.927 回答