Run Capybara without opening browser - ruby

I wrote simple console script for scraping with capybara (selenium driver) but doesn't want browser to appear. I just wan't text to be written on console.
Is possible to run capybara wihout opening browser?

There is a headless-webkit driver for Capybara that would avoid opening a browser window.
If you are not tied to the Capybara API and don't need to worry about JavaScript then mechanize would probably be a simpler way to interact with Web sites.

Related

Mechanize can't find form

I'm having some problem accessing the form element on a page I'm getting using Mechanize.
username_page = agent.get 'https://member.carefirst.com/mos/#/home'
username_form = username_page.form_with(name: 'soloLoginForm')
username_form is nil. (username_page does have the page). The page definitely has a form and the field is #soloLoginForm, but username_page.body has no form element.
I'm guessing this is some async or dynamic issue. I'm able to grab the form with poltergeist, and I'm looking into doing all my form filling with capybara/poltergeist, but I wonder if there's something simple I'm missing that will allow me to use mechanize, as I'd planned.
It seems to be that 'https://member.carefirst.com/mos/#/home' uses Angular to render elements of the page and AngularJS requires Javascript support in the browser or in your case Capybara needs a driver with Javascript support.
Mechanize doesn't support Javascript, check this old SO thread. This is probably the reason why it works when you try with poltergeist.
Check: https://github.com/teamcapybara/capybara#drivers
As stated in the answer by #hernanvicente the page is using Angular and requires JS (which mechanize does not support). However, you really want to be using selenium with headless Chrome rather than Poltergeist nowadays. Poltergeist is equivalent to about a 7 year old version of Safari (due to PhantomJS, which it uses for rendering, being abandoned) so it doesn't support a lot of JS and CSS used in modern sites. Another advantage of using Selenium with Chrome is that you can easily swap between headless and headed to see what's happening when you need to debug things.

Can watir-webdriver submit a form without opening a GUI browser like Chrome?

Can I set values for input fields and submit a form using watir-webdriver without opening a browser display?
If you install the headless gem (and its system dependencies) it should be easy to start the browser in headless scope:
Headless.ly do
# start your browser
end

Watir Selenium see if ajax request made

Is there any way in Watir to check if a ajax call is made?
I mean when testing manually the tester would open Firebug or an equivalent program and check under the network tab and see that the request appears there.
How could this be automated using Watir?

How to catch an opened Coded UI browser session with watIN?

I'm working with Coded UI but found many issues trying to recognize many of the site components. So I'm trying with watIN but need to catch the already opened browser session in CodedUI, in watIN so I can start looking up for the site components.
i.e:
This is the way I open a browser session when working with CodedUI
HtmlDocument browser = LoginScreen.NavigateToLogin(Url);
This just loads the URL -> BrowserWindow.Launch(url) and returns the HtmlDocument already logged in the system
I'm using the CodedUIExtention (http://www.incyclesoftware.com/2013/03/build-a-coded-ui-test-without-a-ui-map/) to avoid using UImaps.
Now I need to catch that opened browser session with watIN instead of opening a new watIN session, that will cause all progress to get lost and open a watIN session from the very beginning is not an option.
Same basic answer as here: How to use WebAii and WatiN with Same Browser
Open browser via coded UI
do stuff with coded UI
attach to browser
in WatiN using .AttachTo() do stuff with WatiN
More on browser attachto is here: http://watinandmore.blogspot.com/2010/01/browserattachto-and-iattachto.html

can mechanize read ajax? (ruby)

can I get the correct data/text that is displayed via AJAX using mechanize in ruby?
Or is there any other scripting gem that would allow me to do so?
Mechanized cannot read data displayed by JavaScript, because it does not implement a JavaScript engine (in other words, it can't run it). You'll need a browser to do that, or a program that automates a browser to do it for you. WATIR is one such program.
You can use WATIR with webdriver which is a console only, headless browser.

Resources