When I do js: true test (rspec+capybara+selenium) it runs the browser and all steps are visible. I wish to be able to stop in some point and look around the page. Is there a way to do that? For non js: true tests save_and_open_page from gem launchy works well but here it's useless.
Nothing is better than putting a sleep or a debugger breakpoint where you want to stop, then you can look around the page.
Also note that your browser will be loaded by capybara without extensions, so you cannot use firebug or other tools (but perhaps the native developer tools of firefox remain available I'm not sure)
Related
I'm using watir to load a page the following way:
Watir.default_timeout = Rails.cache.read(:wati_timeout) || 5
options = Selenium::WebDriver::Chrome::Options.new
options.headless!
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument("--disable-blink-features")
options.add_argument("--disable-blink-features=AutomationControlled")
browser = Watir::Browser.new :chrome, options: options
browser.goto(url)
This loads a captcha page with "Please wait... we are checking your browser. and contains a "I am human" checkbox.
I there a way to prevent the website from triggering the captcha?
The Captchas were invented in order to prevent bots and crawlers(like selenium). They are made to be done manually.
You might work around this by automating everything except the Captcha.
You might also want to pause the selenium program if it detects a captcha, so you can solve it and then continue manually.
"I there a way to prevent the website from triggering the captcha?"
You can make it more unlikely to appear by not using a VPN and allowing selenium to use and keep cookies(don't know if this is on by default).
I have a Rails app with a suite of Cucumber tests that run via Capybara on a headless Chrome browser. I'd like to find a way of running these tests (or at least a subset of them) on IE11, and have turned to Browserstack as it seems they offer the means to do this.
I've successfully configured Browserstack to tunnel into my machine and run my tests but they fail on the one browser I care about - IE11.
My suite is currently falling over at the login page. I'm able to do a screenshot and establish that the page is in fact rendered. I'm able to execute:
fill_in 'Email', with: 'mr.jones#example.com'
without error, although a screenshot then shows nothing to have been filled in. Executing
click_on 'Sign in'
yields:
'Selenium::WebDriver::Error::ElementNotInteractableError: Received a JavaScript error
attempting to click on the element using synthetic events. We are assuming this is
because the element isn't displayed, but it may be due to other problems with executing
JavaScript.'
I briefly experimented with send_keys to try and fill in the form, but to no avail. In short, it seems I can navigate to pages and find elements, but I can't interact with them.
Does anyone know of a way to achieve what I'm attempting here? I'm hoping there's e.g. some setting on the driver that will make it work.
I only need to be able to test a few key workflows against IE, so even if a radically different approach is needed in my testing, I won't need to rewrite the entire suite.
Here is my current Capybara configuration:
caps = Selenium::WebDriver::Remote::Capabilities.new
caps['browser'] = 'IE'
caps['browser_version'] = '11.0'
caps['os'] = 'Windows'
caps['os_version'] = '10'
caps['resolution'] = '1024x768'
caps['browserstack.local'] = 'true'
Capybara.register_driver :browserstack_ie do |app|
Capybara::Selenium::Driver.new(
app,
:browser => :remote,
:url => "http://#{ENV['BROWSERSTACK_USER']}:#{ENV['BROWSERSTACK_KEY']}#hub-cloud.browserstack.com/wd/hub",
:desired_capabilities => caps
)
end
Capybara.javascript_driver = :browserstack_ie
UPDATE:
I found some useful information here
It sounds like the issue may be that Selenium is clicking in the wrong place, and that it can be fixed by changing the zoom settings in IE. Not clear to me how I would do this on a browser running in Browserstack though.
I also discovered my Browserstack subscription doesn't support more than 100 minutes of automated testing time per month, which was a bit of a blow, so I can't immediately do anything further with this.
I think I may end up running my own IE instance on a Windows machine on my local network and hook my tests up to that instead. I will update this card if/when I discover anything useful.
Finally, I'd invite anyone who reads this to consider how many hours of their life they have wasted on supporting the many incarnations of IE. It is a blight upon the industry and Microsoft should be ashamed of it.
Sometimes, when running automated tests in PhantomJS using Cucumber for Rails 4, it would be really, really useful to actually sit in front of my screen, look in a window, and see exactly what the browser is doing.
There are times when your code is right and your test is right, but testing fails intermittently nonetheless. It's often because of a script, or an animation, or some CSS that gets in the way. But seeing a screenshot, drilling into a DOM inspector, or using the debugger is not enough to catch those edge cases.
Is there any way to have a window looking at what PhantomJS is doing in the background? It could be something in X Window, or running in a VNC Server, etc. Anything visual would greatly help with debugging, especially in with those finicky details.
I found a little program called PhantomVNC, but it's not telling me much on how it works. It looks like something just feeding a series of screenshots through VNC.
I tried PhantomJS and Capybara-WebKit, but neither of those headless browsers other a "head" option. Selenium-WebDriver seems complicated to set up and only seems to work with a full browser like Firefox, and that may cause more problems than it solves.
If you have any ideas, please let me know. Thank you in advance.
Not sure specifically about Cuc/Rails - but I specifically have a second chrome/webdriver Virtual Machine for this. I use PhantomJS specifically for the headless automatic acceptance testing, but when there is an issue with the tests and I'm trying to diagnose it can be helpful to view the browser live.
In other words, spin up a Ubuntu desktop VM, install chrome, install selenium server and the chrome webdriver. Log in to the VM, open chrome, make sure selenium is running, then configure your test suite to connect to the selenium webdriver service (usually port :4444) of this instance. Run your tests and you should be able to watch the chrome instance on the VM.
Running a Rails test suite with Selenium often opens Firefox with the "Start in Safe Mode?" dialog. Is there a way to either 1) disable this, or 2) add a script that will answer "No" if the dialog appears?
It appears to be related to some open Firefox issues. Please see here:
Disable/Change Firefox Safe Mode Hotkey (Shift)
If you're looking for an alternative to selenium and Firefox, I've had success with PhantomJS (a headless WebKit browser) and the poltergeist gem.
For 1)Disable this:
You can create your own custom profile.
For 2)Add a script to answer 'NO'
Use Autoit to write a script for answering NO and use that in your selenium program.
I'm testing a scenario in Rails with Cucumber, and it comes back saying it can't find the edit link to click on. If I go to the page myself, it's there. Obviously I'm doing something wrong, but I can't see it.
If I add the #selenium tag before my scenario, it executes the tests in Firefox. But it I see the browser open and close, and unless it needs interaction from me (like to confirm a delete), it passes by before I can see what it's doing.
Is there a way to see what it's seeing in the browser and move through step-by-step?
To see what is displayed in the browser at a specific point in time, add this step to your scenario:
Then show me the page
You might not get all the styling, it depends.
There's another thing you could try too: add a step that looks something like this:
Then /^I pause for a while$/ do
sleep 30
end
That should give you 30 seconds to look at the page while its displayed in the browser.
Check this page: "Pausing Cucumber Scenarios to Debug"
I solved it by implementing Cucumber step
Then /^Wait for keypress$/ do
STDIN.getc
end
Very similar to tags solution, but less noisy. This way I am able to halt test execution at any time.
When you want to see what selenium sees add the following to your feature:
#leave_the_window_open
#javascript
Feature: The failing feature you want to click through
(...)
To make it work. you need the following Afterdefinition somewhere in your cucumber load path:
After('#leave_the_window_open') do |scenario|
if scenario.respond_to?(:status) && scenario.status == :failed
print "Step Failed. Press Return to close browser"
STDIN.getc
end
end
see an example here
Voilá: Now the browser window stays open until you hit enter in the console. You can click around and inspect everytthing.
Why not set up a screen recording tool and run it against whatever display web driver is on? Seems like a good low tech solution to me.
I usually use the ask method to pause the action so I can see what is going on. I will use Firebug to explore the issue while everything is paused. See here for a gem that allows you to use Firebug with Cucumber to look at CSS/JS, etc.
Example of ask method:
res = ask('Where is that error coming from??')
You can also write the ask line to actually end the test if something does not look right but acting on the return value.
Another option is to use the ruby debugger and inspect everything running. Here is a SO question explaining how this works.
With Ruby you can add the pry-nav gem - https://github.com/nixme/pry-nav
Add the following to your gemfile:
gem 'pry'
gem 'pry-remote'
gem 'pry-nav'
Then add the line 'binding.pry' to your step definition, where you want to break
Then you can use step, next, continue from the command line to step through your code. You also get console functionality eg. you can evaluate expressions