Watir with webdriver, proxy, Firefox

前端 未结 3 848
小鲜肉
小鲜肉 2021-01-17 01:15

I am able to use watir-webdriver with IE, but I would prefer to use Firefox. Problem: I need a proxy. By googling around, I found some code snippets, but I am not able to pu

相关标签:
3条回答
  • 2021-01-17 01:53

    The base problem in your original question is right in the error message

    webdrivertest.rb:3: syntax error, unexpected tCONSTANT, expecting keyword_do or '{' or '('
    

    The ruby interpreter is seeing something on the third line of your script that looks like a constant, in a place it's expecting something else.

    I suspect it's the start of the line where ruby expects a variable name, and you have a classname. Ruby expects variables named starting with an uppercase to be a constant. which is fine for defining a class, but not creating an instance of one, since the instance won't be a constant.

    It also looks like you are trying to do a new invocation using a 'new' keyword ala some other language, instead of using a .new method on whatever object you want to make a new one of, the ruby way.

    Compare the code in the answer by Mike where he does

    profile = Selenium::WebDriver::Firefox::Profile.new
    

    verses what you were trying to do on line 3

    FirefoxProfile profile = new FirefoxProfile();
    

    See how different they are? His is the way to do it.

    0 讨论(0)
  • 2021-01-17 01:59

    Call the underlying Selenium WebDriver.

    I've used this technique to set a path to Firefox 3.6 so I can test with both Firefox 4 and 3.6:

    Selenium::WebDriver::Firefox.path = ENV['FIREWATIRPATH']
    browser = Watir::Browser.new :firefox
    

    So to do what you're trying to do:

    profile = Selenium::WebDriver::Firefox::Profile.new
    proxy = Selenium::WebDriver::Proxy.new(:http => "http://proxy.org:8080")
    profile.proxy = proxy
    
    # You have to do a little more to use the specific profile
    driver = Selenium::WebDriver.for :firefox, :profile => profile
    browser = Watir::Browser.new(driver)
    

    Look at: Selenium Ruby Bindings and Webdriver FAQ for more info.


    What problem are you having with the Proxy line?

    You could try this:

    profile = Selenium::WebDriver::Firefox::Profile.new
    profile["network.proxy.type"] = 1
    profile["network.proxy.http"] = "proxy.myplace.com"
    profile["network.proxy.http_port"] = 8080
    

    The idea is to see what your settings are in about:config and duplicating them in code.

    0 讨论(0)
  • 2021-01-17 02:12
    profile = Selenium::WebDriver::Firefox::Profile.new
    profile.proxy = Selenium::WebDriver::Proxy.new :http => '12.12.12.12:8888', :ssl => '15.15.15.15:443'
    browser = Watir::Browser.new :firefox, :profile => profile
    
    0 讨论(0)
提交回复
热议问题