Forums | Admin

Discussion Forums: help

Start New Thread Start New Thread

 

By: Mike Watkins
RE: Button.click_and_attach not working for me [ reply ]  
2011-04-19 20:47
I was actually able to work around this by digging into how HtmlUnit works a little more. Here is a snippet that adds an event listener for the CHANGE event on the popup window that seems to work pretty well:

# You have to include/import the Celerity library
require "rubygems"
require "celerity"

browser = Celerity::Browser.new

browser.goto('file:///Users/mwatkins/Desktop/TestPage.html')
@popupBrowser = nil

# Hook up event handler to capture when a window opens.
browser.add_listener(:web_window_event) { |window|
begin
if (window.getEventType == Java::ComGargoylesoftwareHtmlunit::WebWindowEvent::CHANGE && @popupBrowser == nil)
@popupBrowser = Celerity::Browser.new
@popupBrowser.goto(window.getNewPage().getUrl.to_s)
window.getNewPage().getEnclosingWindow().getWebClient.closeAllWindows()
end
rescue Exception => e
puts(e.to_s)
end
}

browser2 = browser.button(:id, "loginButton").click

puts("******************** Browser 1 Text: *************************")
puts(browser.text)
puts("**************************************************************")

puts("******************** Browser 2 Text: *************************")
puts(@popupBrowser.text)
puts("**************************************************************")

I think I can work with this to solve my problem now.

Thanks Again

~Mike

By: Mike Watkins
RE: Button.click_and_attach not working for me [ reply ]  
2011-04-19 19:49
That makes perfect sense - thanks for your help with this Jari. I will investigate further with HtmlUnit.

~Mike

By: Jari Bakken
RE: Button.click_and_attach not working for me [ reply ]  
2011-04-19 18:26
To be honest, these all seem like bugs in HtmlUnit to me. We simply take the page returned from calling click() and wrap it in a new Browser instance. If the click returns the wrong page, something isn't right on the HtmlUnit side.

Here's a script that will reproduce the problem using the HtmlUnit API directly: https://gist.github.com/929131 - that should be sufficient to file a bug report with them.

Jari

PS. If you'd ever want to do testing in a real browser, the leap is short from Celerity to watir-webdriver (https://github.com/jarib/watir-webdriver) :)

By: Mike Watkins
RE: Button.click_and_attach not working for me [ reply ]  
2011-04-19 18:06
Hi Jari - yes sorry, I am using 0.8.9. Also sorry because I meant to mention that it seems to be working better in my test, but not correct (at least not that I can see).

It seems that the wrong page is being attached to. When I run the test web page and look at the URL of the window that opens, it is:

https://www.facebook.com/dialog/permissions.request?api_key=219977654685618&app_id=219977654685618&display=popup&fbconnect=1&locale=en_US&method=permissions.request&next=http%3A%2F%2Fstatic.ak.fbcdn.net%2Fconnect%2Fxd_proxy.php%3Fversion%3D0%23cb%3Dfabff665c8a494%26origin%3Dfile%253A%252F%252F%252Ff3015cc6c7bb7ce%26relation%3Dopener%26transport%3Dpostmessage%26frame%3Df36bbedd141fcc4%26result%3D%2522xxRESULTTOKENxx%2522&perms=publish_stream%2Cmanage_pages%2Coffline_access&return_session=1&sdk=joey&session_version=3

But if I change the test code to dump out the url instead of the text, I get the following URL:

https://www.facebook.com/common/gzip_detect.php/gzip.html

I am thinking that this is possibly a race condition or related to the way the window is being popped up??

By: Jari Bakken
RE: Button.click_and_attach not working for me [ reply ]  
2011-04-19 16:37
Hi,

I created this script based on your code (output attached to the same gist): Seems like the output from the two Browser instances are not the same.

https://gist.github.com/928722

I'm not sure why the text of the second window is empty though.

(By the way, the latest version of Celerity is 0.8.9, I strongly recommend always upgrading to the latest version before reporting issues.)

By: Mike Watkins
RE: Button.click_and_attach not working for me [ reply ]  
2011-04-19 15:33
Hi Jari,

Thanks for the quick response. Sorry my reply is a little late but I had to get my environment setup and a sample app written. This is what I have found:

My first test was a very simple test using a Button and a simple javascript snippet that uses window.open to open a new popup window. This worked fine, celerity attached to the browser as expected.

My second test more closely mimics the AUT and did not work entirely correctly. In this test I have a test html page that uses the Facebook API to launch a login window (this is what the AUT is doing). In this test I found that Celerity attaches to a different browser, however the URL, Text and HTML that gets returned is in-correct.

Here is my test HTML page:

******************************************************************
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"; xmlns:fb="http://www.facebook.com/2008/fbml";>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>CelerityTestFoo</title>
</head>
<body>
<h1>CelerityTestFoo</h1>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js";></script>
<script>
FB.init({
appId : '219977654685618',
status : true, // check login status
cookie : false, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});

function loginToFacebook()
{
FB.login(handleLoginResponse, {perms:'publish_stream,manage_pages,offline_access'});
}

function handleLoginResponse(response)
{
}

</script>

<script src="http://connect.facebook.net/en_US/all.js#appId=219977654685618&amp;xfbml=1";></script>
<button id="loginButton" onClick="loginToFacebook()">Login</button>

</body>
</html>

******************************************************************

And here is my Celerity test:
# You have to include/import the Celerity library
require "rubygems"
require "celerity"

browser = Celerity::Browser.new

browser.goto('file:///Users/mwatkins/Desktop/TestPage.html')
begin

puts("Button Text: " + browser.button(:id, "loginButton").text)
browser2 = browser.button(:id, "loginButton").click_and_attach

puts("***************************************************************")
puts("Browser 1 Text")
puts(browser.text)
puts("***************************************************************")

puts("***************************************************************")
puts("Browser 2 Text")
puts(browser2.text)
puts("***************************************************************")

rescue Exception => e
puts ("Exception: " + e.to_s)
end


Something else to note is that we are running version 0.0.76 of Celerity for our test environment and I am running version 0.0.86 locally.

Thanks,
Mike

By: Jari Bakken
RE: Button.click_and_attach not working for me [ reply ]  
2011-04-18 13:42
Could you provide a minimal test case (Ruby,HTML/JS) that reproduces the problem?

For future reference: you're more likely to get a quick response on the celerity-users list [1] than in this forum.

[1] http://rubyforge.org/mailman/listinfo/celerity-users

By: Mike Watkins
Button.click_and_attach not working for me [ reply ]  
2011-04-18 13:17
Hello,

We are using Cucumber/Celerity and have a problem I have not yet been able to figure out. When we use the click_and_attach method from a link, it seems to work fine; however we are experiencing a problem when trying to use the same method from a button object.

When we call:
$browser.button(:id, button_id).click_and_attach

We get no error and we do get a browser object back, however the browser object appears to be the same browser that the button exists on. We expect to get back the new browser instance that the button opened up. Any ideas on troubleshooting this would be greatly appreciated.