We are at the start of a project to test a new web application written in jQuery and are planning to do it using WATIR and FireWATIR.
During the proof of concepts test I've discovered differences in how WATIR and FireWATIR represent URLs, for example a script which passes in FireWATIR generates this error in WATIR.
assert_equal(expandImage.src,"../WebToolKit/images/closed.jpg")
testBrowserGadget2(WebClientHomePage) [002_pub_browser.rb:108]:
<"http://172.24.4.125:8081/WebToolKit/images/closed.jpg"> expected but was
<"../WebToolKit/images/closed.jpg">.
Is there any setting in either WATIR or FireWATIR I can enable so that the URL value is consistent between when running against IE and Firefox?
I use the uri module ...
e.g.
require 'uri'
URI.parse("http://google.com/image/path.jpg").path
=> "/image/path.jpg"
i.e.
assert_equal(URI.parse(expandImage.src).path,"../WebToolKit/images/closed.jpg")
you could use assert_match http://en.wikibooks.org/wiki/Ruby_Programming/Unit_testing
Related
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
I am developing a sinatra based web application and I extensively use tests to make sure that everything is working before deployment. As testing frameworks I use minitest::specs and capybara with webkit.
My problem is that after deployment my application runs with a base url like this:
http://cool.server.net/to-the-application/
But during tests capybara assumes a clean base-url with a path to / not to to-the-application/. This means I can't test to find bugs which relate to forgetting to set the base-url within links and actions.
For dry testing I followed Changing the base URL for Rails 3 development and modified my config.ru, but I haven't found any way to get capybara to use a different base.
Any ideas how to solve this?
If using the rack_test driver the hostname is completely ignored so changing it isn't going to do anything. If using a different driver you can specify
Capybara.app_host = "http://cool.server.net"
Note that cool.server.net would generally need to resolve to 127.0.0.1 since thats where Capybara binds the app being tested.
Update: After thinking about this I'm not sure that is what you wanted. If what you want is for Capybara to mount your app under /to-the-application then you're going to have to create your own app object which you assign to Capybara.app - see https://github.com/teamcapybara/capybara/blob/2.13_stable/lib/capybara/rails.rb#L4 for how Capybara currently mounts the app.
I use Capybara as a driver in my auto tests.
I defined a driver as:
Capybara.default_driver = :selenium
But it is impossible to use Selenium methods in usual way (like: #driver.find_element(:xpath, ::Login_button).send_keys("MY_login")).
I saw on some resources that it is possible to call Selenium methods using construction:
page.driver.browser
For instance: element = page.driver.browser.find_element(:id, ell).
But error occurs that says that "page" is not defined method.
The question is how to use Selenium methods with defined Capybara driver?
May be it is necessary to define Capybara driver in another way in order to successfully use "page.driver.browser" construction?
Please provide little instance to see full picture.
page is just a convenience method in the Capybara DSL for Capybara.current_session. You can use 'page' if you've included Capybara::DSL into the scope of your tests - see https://github.com/jnicklas/capybara#using-capybara-with-testunit
If you don't want to include the Capybara DSL into your tests you can also just use
Capybara.current_session.driver.browser ....
although accessing selenium methods directly should only be done when absolutely necessary and there isn't a cross driver way to do what you want provided by Capybara
I have a mountable engine that provides Javascript assets to the main Rails App, but while I try testing AJAX calls (provided by the Javascript I just mentioned) in Capybara and Spec. The database doesn't seem to update.
Because of the cluster nature of testing, I can't have a clear understanding of what exactly is being run and loaded on the Dummy App. I was thinking about running the Dummy App as a standalone app and verify what is being rendered via the web browser (sort of manually checking things out). But that wasn't possible because of a Gemfile not found error every time I try running 'rails s' within the spec/dummy folder.
So my question: is there another way to check why the AJAX calls are not working in my test cases(although when I run the app normally the AJAX calls are working just fine) or does anyone know how to run the dummy app as a standalone rails App?
Thanks
The default settings of Capybara doesn't allow AJAX calls.....I had to modify the driver used by Capybara in the spec_helper.rb by adding the following:
Capybara.default_driver = :selenium
I am using the selenium-client gem with Webrat and Cucumber to test a rails project. I have Cucumber set up pretty much as described here: https://github.com/cucumber/cucumber/wiki/Setting-up-Selenium
My problem is that Selenium is prevented from performing file uploads. Ideally I'd like to be able to replicate webrat's 'attach_file' method. I tried dodging the issue by using selenium-client's 'type' method to type the path to the required file, but this seems to fail.
Does anyone have a sugestion for a workaround using selenium-client (i.e. not the regular Selenium gem)?
The normal selenium can't do this because browser security prevents javascript from writing to input=file elements. This is a security feature so that your password file doesnt get uploaded to hackers if you go to a site thats been hacked.
http://jira.openqa.org/browse/SEL-63 has the details
I finally figured this out.
You need to be using firefox with the chrome backend, and you need to specifiy an absolute filepath.
I ended up creating a helper module to specify the filepath, and a "fixtures" folder containing test content. Here is a gist of the solution I came up with: http://gist.github.com/214185
Therefore it is totally possible to replicate Webrat's attach_file method!