Mac App question about testing for whether a window is visible.

39 views
Skip to first unread message

Brant Merryman

unread,
Mar 20, 2015, 12:39:51 PM3/20/15
to frank-...@googlegroups.com
Hi. I'm trying to write my first Frank Cucumber test for my Mac app. I have successfully added an accessibility label to my About box. I can now see that label show up in symbiote. I have the following test:

Feature: I want to test opening the about window.

Scenario: Choose About VyprVPN menu item, open the about box.

Given I launch the app
Then the About VyprVPN menu item should exist

When I choose About VyprVPN menu item
Then I should be on the About VyprVPN screen


which uses the following step definition file:

Then /^the About VyprVPN menu item should exist$/ do
check_element_exists "view: marked:'About VyprVPN'"
end


When(/^I choose About VyprVPN menu item$/) do
simulate_click "view:  marked:'About VyprVPN'"
end


Then /^I should be on the About VyprVPN screen$/ do
check_element_exists_and_is_visible "view:'NSWindow' marked:'My About Box Frank Accessibility Label'"
end




This test passed, so then I modified my app so that when the menu item is chosen the about window does not show. When I did this and re-ran the test, cucumber still reported that the test passed. So, then I looked into the method check_element_exists_and_is_visible to see if I could figure out if I was using it wrong. I found the following in the documentation: http://www.rubydoc.info/gems/frank-cucumber/Frank/Cucumber/FrankHelper#check_element_exists_and_is_visible-instance_method

It appears from looking at the source that it is checking to see if the item is "hidden". In MacOS, windows are not hidden, views are hidden. The window is shown using - NSWindow makeKeyAndOrderFront:


So, it appears that I'm using the wrong method. What method should I be using instead to test whether a window is visible?

Thanks!




Michael Buckley

unread,
Mar 20, 2015, 9:48:36 PM3/20/15
to frank-...@googlegroups.com
The check_element_exists_and_is_visible function does check if the window is "hidden", but does so by calling -isVisible on NSWindow (which is deprecated as of 10.10, but should currently still work). If -isVisible returns YES, Frank will consider your Window to be visible.

The documentation for this method says it returns "YES when the window is onscreen (even if it’s obscured by other windows); otherwise, NO."

Not mentioned by the documentation, it also returns YES when the window is minimized.

If you can't get that to work, as a workaround, Frank defines an -FEX_isFullyVisible method on NSWindow, but doesn't seem to call it from ruby. You could create a ruby function to call it like so

def window_is_fully_visible(selector)
   matches = frankly_map( selector, 'FEX_isFullyVisible' )
   matches.delete(false)
   !matches.empty?
end

The -FEX_isFullyVisible method works by getting the window's content view's visible rect, and comparing it to the content view's frame. If they're the same size, the window is considered fully visible, otherwise it is not.


--
You received this message because you are subscribed to the Google Groups "Frank" group.
To unsubscribe from this group and stop receiving emails from it, send an email to frank-discus...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Brant Merryman

unread,
Mar 23, 2015, 3:31:01 PM3/23/15
to frank-...@googlegroups.com
Hi Michael,

I added some debug output to print the result of the .isVisible property for my About Box. It was returning "NO". Then I checked the frank source code and did a search for "check_element_exists_and_is_visible". I'm looking at the master branch of frank.

LP-3275:frank_src brantm$ git status
On branch master
Your branch is up-to-date with 'origin/master'.

nothing to commit, working directory clean
LP-3275:frank_src brantm$ grep -r "check_element_exists_and_is_visible" *
example/Controls/features/step_definitions/table_deletion_steps.rb:    check_element_exists_and_is_visible("view:'UITableViewCellDeleteConfirmationButton'")
example/Controls/features/step_definitions/table_deletion_steps.rb:    check_element_exists_and_is_visible("button marked:'#{button_mark}'")
gem/lib/frank-cucumber/frank_helper.rb:  def check_element_exists_and_is_visible( selector )
LP-3275:frank_src brantm$ mate gem/lib/frank-cucumber/frank_helper.rb



Then I looked at the file gem/lib/frank-cucumber/frank_helper.rb. I don't know ruby, but it says:

On branch master

Your branch is up-to-date with 'origin/master'.

nothing to commit, working directory clean

LP-3275:frank_src brantm$ grep -r "check_element_exists_and_is_visible" *

example/Controls/features/step_definitions/table_deletion_steps.rb:    check_element_exists_and_is_visible("view:'UITableViewCellDeleteConfirmationButton'")

example/Controls/features/step_definitions/table_deletion_steps.rb:    check_element_exists_and_is_visible("button marked:'#{button_mark}'")

gem/lib/frank-cucumber/frank_helper.rb:  def check_element_exists_and_is_visible( selector )


Then I looked at the file gem/lib/frank-cucumber/frank_helper.rb. I don't know ruby, but it says:

element_is_not_hidden( selector ).should be_true, "Could not find visible element matching selector (#{selector})"

which I'm guessing means that it calls "element_is_not_hidden" and then has an assertion on the result. So, then I looked at the following:

  def element_is_not_hidden(selector)
     matches = frankly_map( selector, 'FEX_isVisible' )
     matches.delete(false)
     !matches.empty?
  end

So, then I added the following method to my window class where I had previously added a "FEX_accessibilityLabel" method:

- (BOOL)FEX_isVisible
{
    GFLog(@"FEX_isVisible called. Result: %@", self.isVisible ? @"YES" : @"NO");
    return self.isVisible;
}

Then I checked my log file and found the following line:

FEX_isVisible called. Result: NO

However, my test is still passing and the window isn't opened. I'm not really sure what the next step would be.

Brant

Michael Buckley

unread,
Mar 23, 2015, 5:33:43 PM3/23/15
to frank-...@googlegroups.com
Hi Brant,

You are correct in assuming what that line does.

I apologize, I should have looked at your testing code more closely. One of the most people have when starting with Frank is that, for various reasons, marked: is a fuzzy match, not an exact match. You may want to change "marked:'My About Box Frank Accessibility Label'" to 'markedExactly:'My About Box Frank Accessibility Label'".

If you still are having difficulties after changing to markedExactly:, I recommend starting frank console from the command-line and running frankly_dump. It will dump out your UI hierarchy, and you can command-F to look for any window objects that Frank might be finding. Hopefully that will help you track down what's going on.

Brant Merryman

unread,
Mar 25, 2015, 11:35:46 AM3/25/15
to frank-...@googlegroups.com
I used the markedExactly:'My About Box Frank Accessibility Label' and I had the same problem. It continued to have the test pass even though the window was not on the screen. 

I then tried changing the name of the label so that it would not match at all. This caused the test to fail (which is correct).

Then I tried doing a "frankly_dump" as you suggested and I did locate the window in question and I did see that it had "My About Box Frank Accessibility Label" as its accessibility label property.

This confirms to me that it is correctly finding the window in question. That part also seemed true from my previous analysis. I think frank is seeing the window as visible when it is not visible. It is calling my FEX_isVisible method and I have confirmed that I am correctly returning NO from this method. Somehow frank is turning "NO" into "YES" somewhere further down the line. 

I have started digging into the guts of how frank works. If I identify a bug, I'll fix it.
Reply all
Reply to author
Forward
0 new messages