I'm having a little trouble following this, but I think one thing that will 
make your life much easier is if you define the browser object with a 
different scope.  That way you don't have to keep passing it around.  So 
you can use $browser or you might be able to get away with @browser. 
 That'll make the code much simpler I believe.

Read up on variable scope here : 
http://www.techotopia.com/index.php/Ruby_Variable_Scope#Ruby_Global_Variables

The problem you're having is that it's not actually a browser object by the 
time it gets to checkinAsset.  At some point it's being redefined to an 
array.

On Wednesday, January 15, 2014 12:00:05 PM UTC-5, Matt Caldwell wrote:
>
> Below are all the moving parts... 
>
> implementation:
>
> require 'rubygems'
> require_relative 'WatirToolbox'
>
> # Create a new WatirToolbox object
> toolbox = WatirToolbox.new
>
> # Initialize the browser using the toolbox
> browser = toolbox.init
>
> # Tell the toolbox to navigate to "prod"
> browser = toolbox.navigateTo(browser, "prod")
>
> # Tell the toolbox to login as inputUsernameHere and click the contributor 
> site
> browser = toolbox.loginAs(browser, "inputUsernameHere", 
> "inputPasswordHere", "Contributor")
>
> # Tell the toolbox to create new content of the type Article
> browser = toolbox.createNewContent(browser, "Article")
>
> # Tell the toolbox to check in the asset with a comment of 'Test Publish'
> #browser = toolbox.checkinAsset(browser, 'Test Publish') # *fails on this 
> line*
>
> Definitions:
> def init()
> browser = Watir::Browser.new
> return browser
> end
>
> def navigateTo(browser, env)
> case env.upcase
> when "PROD"
>   browser.goto "test.com"
> else
>   puts "You passed in #{env} -- I have no idea what to do with that."
>   puts "Valid parameters are:"
>   puts "Prod; Rest to be determined"
> end
> return browser
> end
>
> def loginAs(browser, username, password, appID)
> browser.text_field(:name => 'username').set username
> sleep 1
> browser.text_field(:name => 'password').set password
> sleep 1
> browser.form(:id, 'fm1').submit
> sleep 1
> browser.text_field(:class => 'dijitInputInner').wait_until_present
> browser.text_field(:class => 'dijitInputInner').set "News\n"
>
> sleep 1
> begin
> browser.div(:xpath, '//*[@id="appBar"]').when_present.focus
> browser.div(:xpath, '//*[@id="appBar"]').div.div.link(:title, 
> appID).when_present.fire_event("onmousedown")
> browser.div(:xpath, '//*[@id="appBar"]').div.div.link(:title, 
> appID).when_present.fire_event("onmouseup")
> rescue => e
> p e.message
> p e.backtrace
> puts "appID #{appID} may not be a valid input. Please review WatirToolbox 
> documentation for valid input for this field."
> end
> return browser
> end
>
> def createNewContent(browser, type)
> sleep 5
> #Click on Content
> until browser.frame(:src, 
> '../../ContentServer?pagename=fatwire/wem/integration/processWemRequest&application=uc1').frame(:id,
>  
> 'contentPane_view-3').text_field(:name => 'flexassets:name').present?
> browser.frame(:src, 
> '../../ContentServer?pagename=fatwire/wem/integration/processWemRequest&application=uc1').div(:text,
>  
> 'Content').wait_until_present
> browser.frame(:src, 
> '../../ContentServer?pagename=fatwire/wem/integration/processWemRequest&application=uc1').div(:text,
>  
> 'Content').hover
> sleep 1
>
> #Click on New
> if browser.frame(:src, 
> '../../ContentServer?pagename=fatwire/wem/integration/processWemRequest&application=uc1').td(:text,
>  
> 'New').present?
> browser.frame(:src, 
> '../../ContentServer?pagename=fatwire/wem/integration/processWemRequest&application=uc1').td(:text,
>  
> 'New').hover
> browser.frame(:src, 
> '../../ContentServer?pagename=fatwire/wem/integration/processWemRequest&application=uc1').td(:text,
>  
> 'New').click
> sleep 1
> end
>
> #Click on New #{type} where type is a valid WCM Asset type
> begin
> if browser.frame(:src, 
> '../../ContentServer?pagename=fatwire/wem/integration/processWemRequest&application=uc1').td(:text,
>  
> "New #{type}").present?
> browser.frame(:src, 
> '../../ContentServer?pagename=fatwire/wem/integration/processWemRequest&application=uc1').td(:text,
>  
> "New #{type}").hover
> browser.frame(:src, 
> '../../ContentServer?pagename=fatwire/wem/integration/processWemRequest&application=uc1').td(:text,
>  
> "New #{type}").click
> end
> rescue => e
> p e.message
> p e.backtrace
> puts "type #{type} may not be a valid input. Please review WatirToolbox 
> documentation for valid input for this field."
> end
> end
> if browser.frame(:src, 
> '../../ContentServer?pagename=fatwire/wem/integration/processWemRequest&application=uc1').frame(:id,
>  
> 'contentPane_view-3').text_field(:name => 'flexassets:name').present?
> return browser
> else
> createNewContent(browser, type)
> end
> end
>
> def checkinAsset(browser, comment)
> sleep 10
> #Wait for the frame containing the checkin button to load
> browser.frame(:src, 
> '../../ContentServer?pagename=fatwire/wem/integration/processWemRequest&application=uc1').wait_until_present
>  
> #*Fails here*
> browser.frame(:src, 
> '../../ContentServer?pagename=fatwire/wem/integration/processWemRequest&application=uc1').div(:id,
>  
> 'edit').wait_until_present
>
> #Click checkin icon
> checkin = browser.frame(:src, 
> '../../ContentServer?pagename=fatwire/wem/integration/processWemRequest&application=uc1').span(:xpath,
>  
> "//div[@id='edit']/span[position()=7]")
> checkin.click
> end
>
> On Wednesday, January 15, 2014 11:05:10 AM UTC-5, Dan wrote:
>>
>> Can you show some of that code?
>>
>> On Wednesday, January 15, 2014 9:33:10 AM UTC-5, Matt Caldwell wrote:
>>>
>>> I suppose that is ambiguous -- sorry about that. It is a Watir::Browser 
>>> object, it has been instantiated and has been used in lines preceding that 
>>> line that are also referencing frames.
>>>
>>> On Wednesday, January 15, 2014 9:25:03 AM UTC-5, Dan wrote:
>>>>
>>>> What are you passing into the method?
>>>>
>>>> On Wednesday, January 15, 2014 7:57:35 AM UTC-5, Matt Caldwell wrote:
>>>>>
>>>>> Update/clarification. I am using Firefox 17 as my base for this and 
>>>>> Watir 1.9.3.
>>>>>
>>>>> On Tuesday, January 14, 2014 2:27:05 PM UTC-5, Matt Caldwell wrote:
>>>>>>
>>>>>> Hello all,
>>>>>>
>>>>>> I have been struggling with this issue and was hoping to get some 
>>>>>> insight. I have a method in a helper class that I wrote that is using 
>>>>>> code 
>>>>>> that has worked in the past that is no longer working.
>>>>>>
>>>>>> def checkinAndApproveAsset(browser, comment)
>>>>>> browser.frame(:src, '../../pageSourcePath').wait_until_present  # 
>>>>>> This line throws "Undefined Method 'frame' for []:Array (NoMethodError)"
>>>>>> #.
>>>>>> #. additional irrelevant code
>>>>>> #.
>>>>>> return browser
>>>>>> end
>>>>>>
>>>>>> The method is called by the following method.
>>>>>> browser = toolbox.checkinAndApproveAsset(browser, 'comment')
>>>>>>
>>>>>> Any insights? Thanks in advance.
>>>>>>
>>>>>

-- 
-- 
Before posting, please read http://watir.com/support. In short: search before 
you ask, be nice.

[email protected]
http://groups.google.com/group/watir-general
[email protected]

--- 
You received this message because you are subscribed to the Google Groups 
"Watir General" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to