 |
Forums |
Admin Discussion Forums: help 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 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&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: 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.
|
|
 |