Facebook login test

25 views
Skip to first unread message

Кирилл Ширинкин

unread,
Sep 11, 2011, 1:19:36 PM9/11/11
to lebow...@googlegroups.com
My app works only if user is logged in using Facebook. There is "login" button, user clicks it, then facebook login windows appears, user fills in login and pass and then gets back to application. So for my lebowski tests i need somehow click this button, then fill in facebook credentials in new window and then get back to app. How can i do it in lebowski? 
Or may be there is some way to tell lebowski "wait until i fill in login and pass and close facebook window" ?

Кирилл Ширинкин

unread,
Sep 12, 2011, 2:38:10 PM9/12/11
to lebow...@googlegroups.com
I finished with this solution:
    before(:all) do
      # Be fast. Login like a cowboy shoots.
      App.wait_until(30) do | app |
        sleep 30
        true
      end
    end

So i have 30 seconds to press login, fill in login\pass, return to app. Also, did i wrote .wait_until timer right? May be there is some way to avoid additional "sleep 30"? 

MikeC

unread,
Sep 13, 2011, 2:45:50 AM9/13/11
to lebowskifw
From your main application window, you can always access the child
windows via the MainApplication object's opened_windows() method. The
method will return an instance of the OpenedWindows object which will
allow you to access any child window via's a window's location, window
name or window title. Example:

facebook_app = @app.opened_windows.find_by_title('Facebook')

When a window is found, it returns an instance of
OpenedWindowApplication, which behaves like the MainApplication object
except that you don't start anything. Given that the Facebook window
just has a normal web page with some common input fields, you will
need to access those elements via Lebowski's low-level driver that can
be accessed via and application or proxy object. The driver is
actually an extension of the selenium-client driver. To execute in the
driver context call the exec_driver_in_context method on the opened
windows application object, like so:

facebook_app.exec_driver_in_context do |driver|
driver.type 'css=#username'
# ... fill in rest of fields and click the submit button
end

If you need to wait for some kind of response after submitting the
user information then, yes, you can use the wait_until method:

facebook_app.exec_driver_in_context do |driver|
driver.type 'css=#username'
# ... fill in rest of fields and click the submit button

facebook_app.wait_until do |app|
# use the driver to check for info on the response
end
end

For complete details on how to use the driver, refer to the following:
https://github.com/ph7/selenium-client#readme

-Mike

Кирилл Ширинкин

unread,
Sep 13, 2011, 6:36:05 AM9/13/11
to lebow...@googlegroups.com
Biggest thanks, i already started thinking that it's impossible to fill in info on facebook window. Good to hear that i was wrong :)

2011/9/13 MikeC <michael....@gmail.com>



--
С наилучшими пожеланиями,
Fodoj.

Кирилл Ширинкин

unread,
Sep 14, 2011, 11:06:44 AM9/14/11
to lebow...@googlegroups.com
Seems like facebook window is not recognized by OpenedIWindows method.
This is my test:
  it "should be able to login" do
      loginButton = App['loginButton', 'SC.View']
      loginButton.click
      
      facebook = App.opened_windows
      sleep 30
      #.find_by_title("Log In | Facebook")


      facebook.should eql 2
  end

So App.opened_windows returns this: http://pastie.org/2532228

I can't see anything related to facebook. Also App.opened_windows.find_by_title("Log In | Facebook") returns nil (title is correct).

2011/9/13 Кирилл Ширинкин <fodo...@gmail.com>

MikeC

unread,
Sep 16, 2011, 6:52:59 PM9/16/11
to lebowskifw
Unfortunately is looks like with the latest Selenium, opening windows
and accessing them through the framework is not stable.

Basically what is happening is that Selenium overrides the browser's
window.open method and all browsers now get upset when you do that and
end up causing unexpected results. It used to be specific to Safari
but that's no longer the case. Selenium 2 can circumvent this issue by
leveraging its WebDriver component, but to do that will mean having to
do a major refactor of Lebowski since the original Selenium and
WebDriver have very different architectures. It's something I want to
do but haven't had the time as of yet.

One part that is still semi-functional is if you open a window and
provide it an explicit identifier, like so:

var win = window.open('some/url', 'foo', ...);

With 'foo' as the ID of the opened window, you can then access it with
Lebowski like so:

windows = App.opened_windows
win = windows.find_by_name "foo"
win.should_not be_nil
win.should be_opened
# ... do some stuff
win.close

There's one catch: While this works in Firefox, Safari and such, if
you do this operation more than once you end up getting unexpected
results.

I'll spend some time seeing if there's anything i can do to make this
work as expected, but unfortunately this is more to do with Selenium
and browsers just not liking it when you override window.open().

-Mike

On Sep 14, 8:06 am, Кирилл Ширинкин <fodoj...@gmail.com> wrote:
> Seems like facebook window is not recognized by OpenedIWindows method.
> This is my test:
>   it "should be able to login" do
>       loginButton = App['loginButton', 'SC.View']
>       loginButton.click
>
>       facebook = App.opened_windows
>       sleep 30
>       #.find_by_title("Log In | Facebook")
>
>       facebook.should eql 2
>   end
>
> So App.opened_windows returns this:http://pastie.org/2532228
>
> I can't see anything related to facebook.
> Also App.opened_windows.find_by_title("Log In | Facebook") returns nil
> (title is correct).
>
> 2011/9/13 Кирилл Ширинкин <fodoj...@gmail.com>
>
>
>
>
>
>
>
>
>
> > Biggest thanks, i already started thinking that it's impossible to fill in
> > info on facebook window. Good to hear that i was wrong :)
>
> > 2011/9/13 MikeC <michael.lee.co...@gmail.com>

Кирилл Ширинкин

unread,
Sep 17, 2011, 2:48:40 AM9/17/11
to lebow...@googlegroups.com
Facebook login window has long url, and it's different every time user tries to login, so i will use wait_until and login manually :)

Thanks for help =)

2011/9/17 MikeC <michael....@gmail.com>
Reply all
Reply to author
Forward
0 new messages