Selenium RC Referer header - selenium-rc

I am using Selenium 2.8 with TestNG. I need to test usecases where I have to set custom referer header? I tried using addCustomHeader, but didnt work. I also tried selenium.start("addCustomHeaders=true") and then selenium.addCustomHeader("Referer", url) in my test. That didnt work either. Should I be using selenium as proxy. If so how to configure using Firefox and selenium java and how does it work. How to set the referer in that case? Does FirefoxDriver ease the job?

You can try using the BrowserMob proxy for this. Probably you can find more info about support in Webdriver at
https://sqa.stackexchange.com/questions/1276/is-there-a-capturenetworktraffic-implementation-in-selenium-2-via-webdriver
Check out the BrowserMob HTTP Request Manipulation section at
https://github.com/lightbody/browsermob-proxy

Related

Can I automate Chrome request blocking using Selenium-webdriver for Ruby?

I am a QA automation analyst responsible for testing a multi-platform online banking application. For our automation testing we use RubyMine suite with Gherkin/Cucumber, Ruby-scripted steps and Selenium-webdriver, Watir and page-object gems/libraries.
I have a number of scripts that I cannot automate completely without manual intervention, and these include blocking certain network calls through Telerik Fiddler to produce warning pages or error messages, etc. The future of our automation would be to do this through RubyMine instead of Fiddler for network blocking. I know there is a way to do this in Chrome using Inspect Element and the Network menu using enable request blocking. However, I cannot figure out a way to force Chrome through Ruby/Selenium to block a given request. The only way is do manually do it myself, and therefore I can't actually automate these as wanted.
So, my question -- is this a possibility to automate request-blocking with Selenium-webdriver? And, if so, where should I begin to look for help with this?
Thanks.
To block URLs from loading with Selenium with the DevTool API:
def send_cmd(driver, cmd, params={})
bridge = driver.send(:bridge)
resource = "session/#{bridge.session_id}/chromium/send_command_and_get_result"
response = bridge.http.call(:post, resource, {'cmd':cmd, 'params': params})
raise response[:value] if response[:status]
return response[:value]
end
send_cmd(driver, "Network.setBlockedURLs", {'urls': ["*"]})
send_cmd(driver, "Network.enable")
It's not very well documented, but you can also implement request blocking by passing the host-resolver-rules option to chrome and mapping the domain to localhost or an invalid IP. Something like this should work for you:
options = Selenium::WebDriver::Chrome::Options.new
options.add_argument('--host-resolver-rules=MAP www.google-analytics.com 127.0.0.1')
driver = Selenium::WebDriver.for :chrome, options: options
For those wanting to know, python version is just:
driver.execute_cdp_cmd('Network.setBlockedURLs', {"urls": ["www.baidu.com"]})
driver.execute_cdp_cmd('Network.enable', {})
Try https://github.com/lightbody/browsermob-proxy
I dont know if it can satisfy your requirement as I am no way a network expert, I do use browsermob-proxy extensively to capture network request along with selenium and there is a method to blacklist certain request
https://browsermob-proxy-py.readthedocs.io/en/stable/client.html#browsermobproxy.Client.blacklist
How to disable loading external urls on seleniumlibrary/robotframework

How to import webservices in Jmeter

I'm trying to import the webservices that are in the WSDL into Jmeter using SOAP/XML-RPC request. But I didn't see anything with the 'Import' or LoadWSDL option. I saw this video https://www.youtube.com/watch?v=IsmrHK6FPjA which has the webservice(SOAP) request which I cant see it in my Jmeter version.
The reason I'm asking is because in each SOAP/XML-RPC Data, I've to open SOAPUI to get blank request and then paste it in the Jmter. We have hundreds of webservices to test and this method is getting very lengthy process.
Is there a way in Jmeter to create blank requests like SOAP UI if I give the wsdl URL and it generates all possible requests for us. Thanks in advance.
There is no such import feature in JMeter.
But a way to do it is to put JMeter as a proxy for SOAP UI using HTTP Test Script Recorder, then you would avoid Copy/paste thing.
Read also this for up to date way of testing webservices:
http://jmeter.apache.org/usermanual/build-ws-test-plan.html
As per the jmeter latest version help WebService(SOAP) Request sampler is DEPRECATED. This sampler is having load WSDL option. Try older version of jmeter..

Selenium profile is getting detected by Google?

Basically I'm trying out Selenium webdriver (using FireFox) and right now I am trying to sign up to a Google account.
However, the strange thing is that whenever I run Selenium and let it use the (empty I assume?) Selenium FireFox profile Google seems to detect it and block me (asking for phone vertification).
This is even the case when I load up the selenium profile and manually sign up.
When I sign up manually (and don't use the selenium profile) I can sign up just fine.
Is the Selenium FireFox profile some how special which enables the servers to detect it?
EDIT: I'm trying to startup selenium with my default FF profile (however it keeps starting up in an empty profile) - here's the code:
OpenQA.Selenium.Proxy proxySetting = new OpenQA.Selenium.Proxy();
proxySetting.HttpProxy = proxy;
proxySetting.FtpProxy = proxy;
proxySetting.SslProxy = proxy;
FirefoxProfile profile = new FirefoxProfile("default");
profile.SetProxyPreferences(proxySetting);
profile.SetPreference("browser.privatebrowsing.autostart", true);
_driver = new FirefoxDriver(profile);
EDIT:
I managed to open the default firefox profile but now it doesn't use my proxy settings. How can I use the normal profile and still customize the profile proxies?
This post talks about an HtmlDriver tag being added to the HTML in the FirefoxDriver which would be a dead giveaway
Google is a strong supporter of Open Source, and even Selenium itself, however I don't think Google would particularly condone a Selenium script creating a bunch of spam accounts that probably would never be used, and just take space.
That being said, I believe that it would be possible potentially.
The only way that Google would be able to know you are using Selenium, is based on the Request Headers. It's possible either the User-Agent has something to do with Selenium, or one of the other Headers.
My solution would be to use something like Fiddler to listen to the requests that Firefox is sending, and then edit your Selenium scripts to account for, and change those requests so Google does not know that you are using Selenium.
This most likely goes against their terms of use, so exercise caution, and use this answer for educational purposes only.
Is there a chance, if you were using the complete path to your firefox profile directory? (e.g. C:\Users\???\AppData\Roaming\Mozilla\Firefox\Profiles\your_profile.default)

Logging frameworks for CasperJS

Is there a way to use winston or bunyan with CasperJS ? I couldn't get either to load correctly.
I tried the proxy method described in Can't require Underscore with CasperJS, but that also didn't work.

Will selenium record firebug and tamper data manipulations?

I am writing an automated test script. So far, Selenium has helped me. Now,I have a test case where I should tamper the request and add a parameter and then submit the request. I did it manually by using tamperdata.
I want to automate this test case now. The problem is, selenium is not recording my actions of adding a parameter and then submitting the request. I understand selenium is a record-playback kind of tool. can some one confirm me if it cannot record tamper data or am doing wrong?
If it cannot, how do you people automate these kind of test cases.
Selenium really is not designed for such a type of work. If a regular user can't make a tampered request (without Firebug etc.), then Selenium usually can't, too. Anyway, you can have FireBug: How do I run Firebug within Selenium WebDriver (Selenium 2)?. Controlling it, that's where the problems come - and I don't think it's worth the research.
One way to do this could be HttpUrlConnection in Java, making and sending the request in Java ... see those SO questions: How to send HTTP request in java?, Using java.net.URLConnection to fire and handle HTTP requests

Resources