Button "Click" issue with Rails/Capybara/Webkit (tests pass in Selenium) - javascript

I'm working on a Rails App and we've started using capybara for our functional tests. Our tech lead has had us writing tests and using Selenium, but then wants to switch to webkit for final testing prior to a deploy.
I've written a set of functional tests that mimic a user clicking through a tree menu, clicking a button to open a modal, clicking a few buttons within the modal (eventually opening a form), and then submitting the button.
These tests pass with flying colors in selenium. Firefox pops open and it whips through the complete test suite.
Switch over to webkit, and there is a consistent point at which the tests fail. When the modal is open, and it attempts to "click" a button to switch from a "Interaction History Form" to a "New Interaction Form"
The following is a list of the various command attempts I've done at "clicking" the New Interaction Button.
With selenium, this is simple and works:
click_button('New Interaction')
and some of these work in selenium, some don't, but none of them work with WebKit.
# page.execute_script %Q{ $('.btn.btn-default.toggle-interaction').css('display, inline-block'); }
# page.execute_script %Q{ $('.fa.fa-plus').click(); }
# page.find('.btn.btn-default.toggle-interaction').click
# within('#interaction-history') { find_button('New Interaction').click }
click_button('New Interaction')
# find_button('New Interaction').trigger('click')
# within(".btn.toggle-interaction") do
# click_on("New Interaction")
# end
# find('.btn.toggle-interaction').trigger('click')
# find_button('New Interaction').click
# within('.insight-wrapper') { find_button('New Interaction').click }
We decided to try and use the capybara-screenshot gem, so that we could get a snapshot of the HTML and the "rendered" page during headless test failure.
I don't have a good photo editing app so I can't scrub out the protected info to post a screenshot, but in the saved snapshots (and saved html files), the images look right.
One idiosyncrasy in the screenshots is the location of the mouse cursor in the screenshot. Sometimes it's on the button it attempted to click, and other's it isn't.
One other idea we entertained is the idea that it could be a timing issue, and that it's trying to click the button before it has been successfully rendered. To mitigate that we added a pause method that forced the tests to wait. That didn't resolve the issue.
We looked at switching to a headless selenium using poltergeist/phantomJS, but a lot of the comments on that route seem to indicate a higher quantity of "random JS errors" than with webkit. Would there be an alternative headless selenium solution that could be worth investigating?
Thank you for your time and help,
Alex

Related

Closing OS App Selector For Selenium on Mac

I'm trying to automate joining a zoom meeting via browser (not with the actual zoom application) using selenium and chromedriver (via node.js), and have run into some issues with MacOS. Currently the program navigates to the join link, waits a second for the OS App Selector popup to appear, then presses Escape to close the popup (using node-key-sender package and then node-keys-simulator), clicks the LAUNCH MEETING button, then presses escape again, and finally presses the new Join From Your Browser link.
This process works on Windows, but for some reason Mac doesn't register the escape key. The same issue occurs when using tab and enter to navigate to the cancel button and press it.
Other posts suggest to modify the chrome setup to block the popup, but none of those have been able to work for me (which one post suggested was because Google had disabled the feature).
Does anyone have any suggestions how to bypass the OS App Selector popup, either with key presses or potentially via another modification to the chromedriver options?
Realised that I could just completely avoid this screen by replacing the /j/ in the url with /wc/join/, which then gets redirected (with the password hashed and updated in the redirect) to point to the web-client join page

Popup window unrecognized by Selenium

Using Java, selenium and xpaths. I am verifying a Citrix project. Really all I have to do is login, show the favorites and apps buttons and that they are there. I get this window, which blocks everything:
And I can't do Selenium clicks until it is closed. Problem is, inspect does not show it, there is not a new windowhandle to locate it, and trying to find any xpaths does not work.
I can continue by using javascript clicks to click items blocked by this view, but it gets annoying and they may not accept it.
Before you suggest it, we are not allowed to use Robot. I looked for a Javascriptexecutor to just hit "ENTER" (since manually you can hit ENTER to download it) but couldn't find one. Uasing Actions(driver) does not work either because I think the window is not recognized.
There is a link "already installed" which I can click (with javascriptexecutor) and continue, but the popup window stays visible. Perhaps use Javascriptexecutor to open a link in a new window? But I tried some things which didn't work, although perhaps I did not have the right idea.
Any suggestions? BTW another solution that won't work is to do it manually the first time, because no matter how many times it runs and how many times the download button was clicked manually, the next time it comes up I get the window again.
Any ideas? (I scribbled out personal company info). Oh, and it is not an Alert. At least none recognized.

Why did IE JavaScript breakpoints stop working from Visual Studio 2013?

Until two weeks ago I was able to set a breakpoint in JavaScript code by adding a debugger; statement. For Internet Explorer, when this statement was hit, this would cause me to automatically go back to the Visual Studio debugger.
I could optionally toggle a breakpoint for the line in Visual Studio, but this wasn't necessary, and it wouldn't set a breakpoint on its own without the debugger; statement. When a breakpoint was set in this way, it would show a red filled in circle on the line of JavaScript code.
On April 4th this stopped working.
Now if I add a debugger; statement nothing happens. If I try to toggle a breakpoint in Visual Studio, I get a red open circle. Hovering over the circle gives me the error that "The breakpoint will not currently be hit. No symbols have been loaded for this document."
I've searched for that error message, but what I have found has been about C#, not JavaScript.
I thought the problem might be something we did to our source code, so I checked out a much older version, but I still had the same problem. Our other developer started having the same problem on his main machine at the same time I did. But he has a laptop he uses less often that didn't see the problem. It was a bit behind our source control and he ran it forward one commit at a time until the present version and never saw the problem.
How do we get our breakpoints to work again? How do we get Visual Studio to load the JavaScript symbols? (or is that even really the problem?)
I've been relying on Firebug for two weeks, but I need to go back to IE because of the VS integration.
Stuff I've already looked at:
In Visual Studio, Tools -> Options -> Debugging -> Just-In-Time, Script is already checked.
In IE Tools -> Internet Options, Advanced tab, Browsing section, Disable script debugging is not checked, either for Internet Explorer or for Other.
In VS, Properties menu after right-clicking on the solution, Common Properties -> Startup project, selected Multiple startup projects, set start action on the project with our JS code. The result of this was my "Internet Explorer" button turned into a Start button that couldn't run the project - it just gave the error message "The debugger cannot continue running the process. Unable to start debugging."
Right click on the project, select Properties, go to Web -> Debuggers. The options I get are ASP.NET, Native Code, SQL Server, and Silverlight. Only ASP.NET is checked. Enabled all of the others, but nothing changed.
Cleaned and rebuilt the whole solution.
Project properties -> Build: Define DEBUG constant and Define TRACE constant are checked. On the Advanced dialog, Debug info is set to full. Not sure if that even has anything to do with JavaScript.
Debug -> Options and Settings -> Debugging -> General: uncheck Enable Just My Code
In the end after a lot of changes, I saw this error message "Ignored debugger statement in eval code at line 2600. To stop at this statement, disable Just My Code."
I had already tried the Just My Code fix, but I tried it again, and my breakpoints came back:
Debug -> Options and Settings -> Debugging -> General: uncheck Enable Just My Code
When breakpoints are triggered they show up in a special eval'ed code window that includes a copy of the code where I put the debugger statement. I think that's how it was working before. Apparently there are a few places in our code where breakpoints work no matter what - those didn't need this fix, and they don't show up in the special eval window.
I rolled back all the other changes I had made today one by one, and in the end it looks like disabling Just My Code fixes it. I had even messed with creating a _references.js because I was seeing an error from JavaScript Language Service about it, but that doesn't seem to be necessary.
Thank you to those who pitched in with suggestions, including those who posted answers and deleted them because you realized I'd already tried it. Obviously trying things more than once can sometimes be a good idea.

Selenium IDE automation seems to break JavaScript window

I'm using selenium IDE (currently available only on firefox) to do some automated testing of a site I'm coding. When selenium navigates to, a form filling page, and fills in the info - a 'window.alert()' is called by a button.
When using selenium my set of commands look like this:
open /
clickAndWait document.form1.Action[1]
select stuff
type stuff
etc, etc
click name=myPreview
When I click through recording this the first time, it works no problem. When I rerun the script window.alert and alert don't work from the console or anything. I've debugged it, and its not working.
When a window.alert() is called as part of a selenium script (I'm talking at least in the IDE), it is called even though a user watching does not see an alert pop up. According to the documentation:
Under Selenium, JavaScript alerts will NOT pop up a visible alert
dialog.
Selenium does NOT support JavaScript alerts that are generated in a
page's onload() event handler. In this case a visible dialog WILL be
generated and Selenium will hang until someone manually clicks OK.
Both assertAlert and verifyAlert are both based off getAlert(), all of which do the alert 'stuff' in the background. So try adding these functions to ensure that the alert is working, run the script, and then check to see if it works.
A note: this only works if you ensure the test fails before you put in the alert (basic idea of testing, fail first - make test pass).

Powershell Website Automation: Javascript Popup Box Freeze

I am trying to automate a process in which the user downloads a file extract from a website. My issue is that once the 'export' button in clicked, a javascript popup window comes up with various date parameters for the extract along with the final 'DOWNLOAD' button that needs to be clicked. The problem arises during this javascript popup window. Once the export button is clicked and the popup window opens, powershell seems to freeze up during the script and will not allow any further commands to be executed.
I have tried using the WASP module along with SELECT-WINDOW in order to grab the correct IE process window, however the 'Select-Window -Title "NAME OF POPUP WINDOW - Windows Internet Explorer" | Select -First 1 | Set-WindowActive' command will not execute as Powershell gets stuck 'Running script' immediately after the initial 'export' button is clicked (right when the popup window opens). Is there a way I can either 'refresh' Powershell after the popup box is opened in order to execute further commands, or any ideas on a way to break out of the continuous 'Running script' loop that I get stuck in with this Javascrip popup window?
# Set access URL and Credentials
$WebU='username'
$WebP='password'
$URLlogin='http://websiteurl.com'
$IEwait="1000"
# Execute IE and navigate to URL
$ie = New-Object -com "InternetExplorer.application";
$ie.visible = $True;
$ie.navigate($URLlogin);
Try{
# Login steps
while ($ie.Busy ) { Start-Sleep -Milliseconds $IEwait; }
if ($ie.Document.getElementByID("txtLogin"))
{ $ie.Document.getElementByID("txtLogin").value = $WebU }
while ($ie.Busy ) { Start-Sleep -Milliseconds $IEwait; }
if ($ie.Document.getElementByID("txtPassword"))
{ $ie.Document.getElementByID("txtPassword").value = $WebP }
while ($ie.Busy ) { Start-Sleep -Milliseconds $IEwait; }
if ($ie.Document.getElementByID("btnLogin"))
{ $ie.Document.getElementByID("btnLogin").Click() }
# Navigate through website to find the 'Export' button
while ($ie.Busy ) { Start-Sleep -Milliseconds $IEwait; }
if ($ie.Document.getElementByID("managementMenu_btnLearningResults"))
{ $ie.Document.getElementByID("managementMenu_btnLearningResults").Click() }
while ($ie.Busy ) { Start-Sleep -Milliseconds $IEwait; }
# This is the part that freezes the script. Once the 'btnExport' button is clicked, a JS popup keeps Powershell from executing any additional commands
if ($ie.Document.getElementByID("btnExport"))
{ $ie.Document.getElementByID("btnExport").Click() }
# Once the popoup box opens, sending the 'ENTER' key should automatically download the export file
Select-Window -Title "NAME OF POPUP WINDOW - Windows Internet Explorer" | Select -First 1 | Set-WindowActive
Select-Window -Title "NAME OF POPUP WINDOW - Windows Internet Explorer" | Select-childwindow | Send-Keys "{ENTER}"
}
# These won't execute because the JS popup window confuses Powershell and keeps it in a continuous 'Running Script' process
Catch {
"Error" }
Finally {
"Now able to execute further commands" }
This problem comes up a lot when automating GUI browsers - modal dialogs like the JS popup you describe will block your script from finishing until someone dismisses it. This is because the call you made into browser itself (which caused the modal dialog to appear) is also blocking, waiting for interaction from the user.
In my experience the easiest way to deal with this scenario is to launch a separate process just to handle the modal dialog. It takes two steps:
Write a small standalone script/program that will wait for the modal dialog to appear, then dismiss it. This is easy to test by launching the popup-handling script manually, then manually performing the steps that make the dialog appear.
Once you have that working, in your main program that automates the browser, launch your separate dialog-handling script just before you execute the line of code that creates the modal dialog.
And that's it. It feels clunky but it will work in pretty much any case I've seen (unless the modal dialog requires elevated security privileges, which brings up other issues).
Also, if you're using a programming language that has native thread support, you can launch a separate thread (instead of a process) to handle modal dialogs.
Some test automators feel it's actually cheaper (in terms of script development and maintenance time) to simply bypass modal dialogs like this if possible, assuming you can get around it and still feel confident in your testing. Sometimes this might require modifying the application to give your test code a special interface into the system.
The IE object model is actually kind of treacherous. It often says things are ready when they aren't, because an underlying resource hasn't yet loaded. I got annoyed rewriting this code each time I had to interact with a page, so I wrote a module called AutoBrowse to deal with it:
http://autobrowse.start-automating.com/
Use this instead, and you will sidestep the issue.
Hope this helps
While ( $ie.busy -eq $true){
[System.Threading.Thread]::Sleep(2000);
$wshell = New-Object -ComObject wscript.shell;
if($wshell.AppActivate('Message from webpage'))
{
[System.Threading.Thread]::Sleep(1000);
[System.Windows.Forms.SendKeys]::SendWait('{Enter}')
}
}

Categories

Resources