有没有办法使用RemoteWebDriver

有没有办法使用RemoteWebDriver

本文介绍了有没有办法使用RemoteWebDriver for SauceLabs禁用CORS检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题说明了一切,我试图在SauceLabs上执行一些硒测试,该测试加载了发出跨域请求的网页.我当时在想是否有办法以与平台无关的方式通过代码来禁用CORS.

解决方案

同时使用 ChromeDriver / Chrome 组合禁用


参考文献


Outro

您可以在以下位置找到一些相关的讨论:

Question says it all, I m trying to execute some selenium tests on SauceLabs, the test loads a webpage that makes a cross domain request. I was thinking is there a way to disable CORS, in platform-independent way through code.

解决方案

While using ChromeDriver / Chrome combo to disable cors check you can use the --disable-web-security argument.

which is defined in content_switches.cc as:

// Don't enforce the same-origin policy. (Used by people testing their sites.)
const char kDisableWebSecurity[]            = "disable-web-security";


Code samples:

  • Windows:

    ChromeOptions options = new ChromeOptions();
    options.addArguments("--disable-web-security"); // don't enforce the same-origin policy
    options.addArguments("--disable-gpu"); // applicable to windows os only
    options.addArguments("--user-data-dir=~/chromeTemp"); // applicable to windows os only
    WebDriver driver = new ChromeDriver(options);
    driver.get("https://google.com");
    

  • OSX:

    ChromeOptions options = new ChromeOptions();
    options.addArguments("--disable-web-security"); // don't enforce the same-origin policy
    options.addArguments("--user-data-dir=/tmp/chrome_dev_test");
    WebDriver driver = new ChromeDriver(options);
    driver.get("https://google.com");
    

  • Linux

    ChromeOptions options = new ChromeOptions();
    options.addArguments("--disable-web-security"); // don't enforce the same-origin policy
    WebDriver driver = new ChromeDriver(options);
    driver.get("https://google.com");
    


References


Outro

You can find a couple of relevant discussions in:

这篇关于有没有办法使用RemoteWebDriver for SauceLabs禁用CORS检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 17:33