Did not get a chance to dive into creating my first Class but I will do asap. I quite understand the concept of the Page Object (I will still need practice to get to the understanding of where exactly should I use it and how) and that is why I was looking into Classes yesterday.
I guess what I am still confused about is what makes the difference? To me it looks like by doing so (create class Login) I would only do a translation of my problem to a sub-level. Why would I be able to use more easily (from anywhere) an instance of "Login" than an instance of "Browser"? I mean, I understand I can use the instance from where it's been instantiated, but how do I use it from elsewhere ? (I hope my question makes sense) Things are starting to make sense as I am typing and trying to even myself understand my problem. So now, I would turn my question in a different angle: why is my Browser instance @b declared in my *** ENVR.RB *** file known to my *** STEPDEF.RB *** file? Does it mean that Modules or Class are segregated from the "rest of the world" (== ENVR, STEPDEFS...) and that the "rest of the world" can be seen as a unique big Class? Thanks for helping me thru the process of sorting things out! Titus thanks for the advice on BDD, when I started I did not know about RSpec and spec_helper, but I will definitely take your advice ! On Thursday, December 7, 2017 at 10:38:59 AM UTC-5, Titus Fortner wrote: > > He isn't referring to a class for browser creation, but creating a page > object class for using the browser, instead of using a module. > > Classes and modules are very similar in Ruby, but classes can be > instantiated with instance variables, like a specific instance of a Browser > object. > > Also, I typically recommend people do not use Cucumber unless they are > actively doing Behavior Driven Development with a company. using RSpec and > spec_helper are overall much more straightforward. > > > On Wednesday, December 6, 2017 at 11:27:53 PM UTC+1, Jeff Fagot wrote: >> >> Thanks Oscar for your input. >> I was just trying to learn about CLASS today and see how I could >> implement Class Objects...I guess you will get me started on it => I will >> try it out tonight >> >> But isn't Browser already a default Class Object of Watir? >> By following blogs, posts...I do not recall seeing others creating a >> specific class for the Browser creation? >> >> Jeff F >> >> On Wednesday, December 6, 2017 at 5:04:34 PM UTC-5, Oscar.Rieken wrote: >>> >>> why not just create a class and pass the instance of the browser to that >>> class or something like that its been a while since i have written ruby >>> >>> ###Somewhere >>> Before do >>> @browser = Watir::Browser.new :firefox >>> end >>> >>> ###login.rb >>> class Login >>> def initialize(browser) >>> @browser = browser >>> end >>> >>> def open_browser_at(destination="www.google.com") >>> @browser.goto destination >>> end >>> end >>> >>> ### Usage >>> login = Login.new(@browser) >>> login.open_browser_at >>> >>> >>> >>> >>> On Wed, Dec 6, 2017 at 4:04 PM, Jeff Fagot <[email protected]> wrote: >>> >>>> Hello all, >>>> >>>> Main question == How to share the same browser instance across all my >>>> modules? >>>> Sub question 1 == What do you recommend between using hook.rb vs ruby >>>> module to instantiate a new Browser? >>>> Sub question 2 == Where do you store your modules? >>>> >>>> >>>> I explain: (I am using Cucumber+Watir) >>>> 1) Before, when it was fine: >>>> I first had one stepdef file with one module containing all my methods >>>> (including creation of new browser...). >>>> Now with everything I am reading and learning, I am trying to separate >>>> things in a more organized / re-usable / maintainable way, so: >>>> >>>> 2) After, where I am stuck: >>>> I created myself both the "envr,rb" && a new Module "Login_module" >>>> files (I also tried within hook.rb) to create my instance of @browser, >>>> then >>>> it seems to only be recognized to my stepdef but not by the other >>>> module...?? >>>> >>>> I am trying to make things right from start, therefore as I read about >>>> it, I am running away from using global variables at all. >>>> >>>> >>>> *Files overview:* >>>> >>>> *** ENVR.RB *** >>>> browser = Watir::Browser.new :firefox >>>> >>>> Before do >>>> @b = browser >>>> # @b = Watir::Browser.new :chrome >>>> # @b = Watir::Browser.new :ie >>>> end >>>> *********************************************** >>>> >>>> >>>> *** STEPDEF.RB *** >>>> Given (/^I am navigating to the testsite$/) do >>>> Login_module.open_browser_at *#### Here if instead I pass >>>> directly @b.goto "www.google.com <http://www.google.com>" => it works ###* >>>> end >>>> ****************************************************** >>>> >>>> *** LOGIN.RB *** >>>> module Login_module >>>> def self.open_browser_at >>>> @b.goto "www.google.com" >>>> end >>>> end >>>> ****************************************************** >>>> I would appreciate any help in sorting things out. >>>> >>>> Thanks in advance. >>>> Jeff Fagot >>>> >>>> -- >>>> -- >>>> 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/d/optout. >>>> >>> >>> On Thursday, December 7, 2017 at 10:38:59 AM UTC-5, Titus Fortner wrote: > > He isn't referring to a class for browser creation, but creating a page > object class for using the browser, instead of using a module. > > Classes and modules are very similar in Ruby, but classes can be > instantiated with instance variables, like a specific instance of a Browser > object. > > Also, I typically recommend people do not use Cucumber unless they are > actively doing Behavior Driven Development with a company. using RSpec and > spec_helper are overall much more straightforward. > > > On Wednesday, December 6, 2017 at 11:27:53 PM UTC+1, Jeff Fagot wrote: >> >> Thanks Oscar for your input. >> I was just trying to learn about CLASS today and see how I could >> implement Class Objects...I guess you will get me started on it => I will >> try it out tonight >> >> But isn't Browser already a default Class Object of Watir? >> By following blogs, posts...I do not recall seeing others creating a >> specific class for the Browser creation? >> >> Jeff F >> >> On Wednesday, December 6, 2017 at 5:04:34 PM UTC-5, Oscar.Rieken wrote: >>> >>> why not just create a class and pass the instance of the browser to that >>> class or something like that its been a while since i have written ruby >>> >>> ###Somewhere >>> Before do >>> @browser = Watir::Browser.new :firefox >>> end >>> >>> ###login.rb >>> class Login >>> def initialize(browser) >>> @browser = browser >>> end >>> >>> def open_browser_at(destination="www.google.com") >>> @browser.goto destination >>> end >>> end >>> >>> ### Usage >>> login = Login.new(@browser) >>> login.open_browser_at >>> >>> >>> >>> >>> On Wed, Dec 6, 2017 at 4:04 PM, Jeff Fagot <[email protected]> wrote: >>> >>>> Hello all, >>>> >>>> Main question == How to share the same browser instance across all my >>>> modules? >>>> Sub question 1 == What do you recommend between using hook.rb vs ruby >>>> module to instantiate a new Browser? >>>> Sub question 2 == Where do you store your modules? >>>> >>>> >>>> I explain: (I am using Cucumber+Watir) >>>> 1) Before, when it was fine: >>>> I first had one stepdef file with one module containing all my methods >>>> (including creation of new browser...). >>>> Now with everything I am reading and learning, I am trying to separate >>>> things in a more organized / re-usable / maintainable way, so: >>>> >>>> 2) After, where I am stuck: >>>> I created myself both the "envr,rb" && a new Module "Login_module" >>>> files (I also tried within hook.rb) to create my instance of @browser, >>>> then >>>> it seems to only be recognized to my stepdef but not by the other >>>> module...?? >>>> >>>> I am trying to make things right from start, therefore as I read about >>>> it, I am running away from using global variables at all. >>>> >>>> >>>> *Files overview:* >>>> >>>> *** ENVR.RB *** >>>> browser = Watir::Browser.new :firefox >>>> >>>> Before do >>>> @b = browser >>>> # @b = Watir::Browser.new :chrome >>>> # @b = Watir::Browser.new :ie >>>> end >>>> *********************************************** >>>> >>>> >>>> *** STEPDEF.RB *** >>>> Given (/^I am navigating to the testsite$/) do >>>> Login_module.open_browser_at *#### Here if instead I pass >>>> directly @b.goto "www.google.com <http://www.google.com>" => it works ###* >>>> end >>>> ****************************************************** >>>> >>>> *** LOGIN.RB *** >>>> module Login_module >>>> def self.open_browser_at >>>> @b.goto "www.google.com" >>>> end >>>> end >>>> ****************************************************** >>>> I would appreciate any help in sorting things out. >>>> >>>> Thanks in advance. >>>> Jeff Fagot >>>> >>>> -- >>>> -- >>>> 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/d/optout. >>>> >>> >>> On Thursday, December 7, 2017 at 10:38:59 AM UTC-5, Titus Fortner wrote: > > He isn't referring to a class for browser creation, but creating a page > object class for using the browser, instead of using a module. > > Classes and modules are very similar in Ruby, but classes can be > instantiated with instance variables, like a specific instance of a Browser > object. > > Also, I typically recommend people do not use Cucumber unless they are > actively doing Behavior Driven Development with a company. using RSpec and > spec_helper are overall much more straightforward. > > > On Wednesday, December 6, 2017 at 11:27:53 PM UTC+1, Jeff Fagot wrote: >> >> Thanks Oscar for your input. >> I was just trying to learn about CLASS today and see how I could >> implement Class Objects...I guess you will get me started on it => I will >> try it out tonight >> >> But isn't Browser already a default Class Object of Watir? >> By following blogs, posts...I do not recall seeing others creating a >> specific class for the Browser creation? >> >> Jeff F >> >> On Wednesday, December 6, 2017 at 5:04:34 PM UTC-5, Oscar.Rieken wrote: >>> >>> why not just create a class and pass the instance of the browser to that >>> class or something like that its been a while since i have written ruby >>> >>> ###Somewhere >>> Before do >>> @browser = Watir::Browser.new :firefox >>> end >>> >>> ###login.rb >>> class Login >>> def initialize(browser) >>> @browser = browser >>> end >>> >>> def open_browser_at(destination="www.google.com") >>> @browser.goto destination >>> end >>> end >>> >>> ### Usage >>> login = Login.new(@browser) >>> login.open_browser_at >>> >>> >>> >>> >>> On Wed, Dec 6, 2017 at 4:04 PM, Jeff Fagot <[email protected]> wrote: >>> >>>> Hello all, >>>> >>>> Main question == How to share the same browser instance across all my >>>> modules? >>>> Sub question 1 == What do you recommend between using hook.rb vs ruby >>>> module to instantiate a new Browser? >>>> Sub question 2 == Where do you store your modules? >>>> >>>> >>>> I explain: (I am using Cucumber+Watir) >>>> 1) Before, when it was fine: >>>> I first had one stepdef file with one module containing all my methods >>>> (including creation of new browser...). >>>> Now with everything I am reading and learning, I am trying to separate >>>> things in a more organized / re-usable / maintainable way, so: >>>> >>>> 2) After, where I am stuck: >>>> I created myself both the "envr,rb" && a new Module "Login_module" >>>> files (I also tried within hook.rb) to create my instance of @browser, >>>> then >>>> it seems to only be recognized to my stepdef but not by the other >>>> module...?? >>>> >>>> I am trying to make things right from start, therefore as I read about >>>> it, I am running away from using global variables at all. >>>> >>>> >>>> *Files overview:* >>>> >>>> *** ENVR.RB *** >>>> browser = Watir::Browser.new :firefox >>>> >>>> Before do >>>> @b = browser >>>> # @b = Watir::Browser.new :chrome >>>> # @b = Watir::Browser.new :ie >>>> end >>>> *********************************************** >>>> >>>> >>>> *** STEPDEF.RB *** >>>> Given (/^I am navigating to the testsite$/) do >>>> Login_module.open_browser_at *#### Here if instead I pass >>>> directly @b.goto "www.google.com <http://www.google.com>" => it works ###* >>>> end >>>> ****************************************************** >>>> >>>> *** LOGIN.RB *** >>>> module Login_module >>>> def self.open_browser_at >>>> @b.goto "www.google.com" >>>> end >>>> end >>>> ****************************************************** >>>> I would appreciate any help in sorting things out. >>>> >>>> Thanks in advance. >>>> Jeff Fagot >>>> >>>> -- >>>> -- >>>> 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/d/optout. >>>> >>> >>> On Thursday, December 7, 2017 at 10:38:59 AM UTC-5, Titus Fortner wrote: > > He isn't referring to a class for browser creation, but creating a page > object class for using the browser, instead of using a module. > > Classes and modules are very similar in Ruby, but classes can be > instantiated with instance variables, like a specific instance of a Browser > object. > > Also, I typically recommend people do not use Cucumber unless they are > actively doing Behavior Driven Development with a company. using RSpec and > spec_helper are overall much more straightforward. > > > On Wednesday, December 6, 2017 at 11:27:53 PM UTC+1, Jeff Fagot wrote: >> >> Thanks Oscar for your input. >> I was just trying to learn about CLASS today and see how I could >> implement Class Objects...I guess you will get me started on it => I will >> try it out tonight >> >> But isn't Browser already a default Class Object of Watir? >> By following blogs, posts...I do not recall seeing others creating a >> specific class for the Browser creation? >> >> Jeff F >> >> On Wednesday, December 6, 2017 at 5:04:34 PM UTC-5, Oscar.Rieken wrote: >>> >>> why not just create a class and pass the instance of the browser to that >>> class or something like that its been a while since i have written ruby >>> >>> ###Somewhere >>> Before do >>> @browser = Watir::Browser.new :firefox >>> end >>> >>> ###login.rb >>> class Login >>> def initialize(browser) >>> @browser = browser >>> end >>> >>> def open_browser_at(destination="www.google.com") >>> @browser.goto destination >>> end >>> end >>> >>> ### Usage >>> login = Login.new(@browser) >>> login.open_browser_at >>> >>> >>> >>> >>> On Wed, Dec 6, 2017 at 4:04 PM, Jeff Fagot <[email protected]> wrote: >>> >>>> Hello all, >>>> >>>> Main question == How to share the same browser instance across all my >>>> modules? >>>> Sub question 1 == What do you recommend between using hook.rb vs ruby >>>> module to instantiate a new Browser? >>>> Sub question 2 == Where do you store your modules? >>>> >>>> >>>> I explain: (I am using Cucumber+Watir) >>>> 1) Before, when it was fine: >>>> I first had one stepdef file with one module containing all my methods >>>> (including creation of new browser...). >>>> Now with everything I am reading and learning, I am trying to separate >>>> things in a more organized / re-usable / maintainable way, so: >>>> >>>> 2) After, where I am stuck: >>>> I created myself both the "envr,rb" && a new Module "Login_module" >>>> files (I also tried within hook.rb) to create my instance of @browser, >>>> then >>>> it seems to only be recognized to my stepdef but not by the other >>>> module...?? >>>> >>>> I am trying to make things right from start, therefore as I read about >>>> it, I am running away from using global variables at all. >>>> >>>> >>>> *Files overview:* >>>> >>>> *** ENVR.RB *** >>>> browser = Watir::Browser.new :firefox >>>> >>>> Before do >>>> @b = browser >>>> # @b = Watir::Browser.new :chrome >>>> # @b = Watir::Browser.new :ie >>>> end >>>> *********************************************** >>>> >>>> >>>> *** STEPDEF.RB *** >>>> Given (/^I am navigating to the testsite$/) do >>>> Login_module.open_browser_at *#### Here if instead I pass >>>> directly @b.goto "www.google.com <http://www.google.com>" => it works ###* >>>> end >>>> ****************************************************** >>>> >>>> *** LOGIN.RB *** >>>> module Login_module >>>> def self.open_browser_at >>>> @b.goto "www.google.com" >>>> end >>>> end >>>> ****************************************************** >>>> I would appreciate any help in sorting things out. >>>> >>>> Thanks in advance. >>>> Jeff Fagot >>>> >>>> -- >>>> -- >>>> 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/d/optout. >>>> >>> >>> On Thursday, December 7, 2017 at 10:38:59 AM UTC-5, Titus Fortner wrote: > > He isn't referring to a class for browser creation, but creating a page > object class for using the browser, instead of using a module. > > Classes and modules are very similar in Ruby, but classes can be > instantiated with instance variables, like a specific instance of a Browser > object. > > Also, I typically recommend people do not use Cucumber unless they are > actively doing Behavior Driven Development with a company. using RSpec and > spec_helper are overall much more straightforward. > > > On Wednesday, December 6, 2017 at 11:27:53 PM UTC+1, Jeff Fagot wrote: >> >> Thanks Oscar for your input. >> I was just trying to learn about CLASS today and see how I could >> implement Class Objects...I guess you will get me started on it => I will >> try it out tonight >> >> But isn't Browser already a default Class Object of Watir? >> By following blogs, posts...I do not recall seeing others creating a >> specific class for the Browser creation? >> >> Jeff F >> >> On Wednesday, December 6, 2017 at 5:04:34 PM UTC-5, Oscar.Rieken wrote: >>> >>> why not just create a class and pass the instance of the browser to that >>> class or something like that its been a while since i have written ruby >>> >>> ###Somewhere >>> Before do >>> @browser = Watir::Browser.new :firefox >>> end >>> >>> ###login.rb >>> class Login >>> def initialize(browser) >>> @browser = browser >>> end >>> >>> def open_browser_at(destination="www.google.com") >>> @browser.goto destination >>> end >>> end >>> >>> ### Usage >>> login = Login.new(@browser) >>> login.open_browser_at >>> >>> >>> >>> >>> On Wed, Dec 6, 2017 at 4:04 PM, Jeff Fagot <[email protected]> wrote: >>> >>>> Hello all, >>>> >>>> Main question == How to share the same browser instance across all my >>>> modules? >>>> Sub question 1 == What do you recommend between using hook.rb vs ruby >>>> module to instantiate a new Browser? >>>> Sub question 2 == Where do you store your modules? >>>> >>>> >>>> I explain: (I am using Cucumber+Watir) >>>> 1) Before, when it was fine: >>>> I first had one stepdef file with one module containing all my methods >>>> (including creation of new browser...). >>>> Now with everything I am reading and learning, I am trying to separate >>>> things in a more organized / re-usable / maintainable way, so: >>>> >>>> 2) After, where I am stuck: >>>> I created myself both the "envr,rb" && a new Module "Login_module" >>>> files (I also tried within hook.rb) to create my instance of @browser, >>>> then >>>> it seems to only be recognized to my stepdef but not by the other >>>> module...?? >>>> >>>> I am trying to make things right from start, therefore as I read about >>>> it, I am running away from using global variables at all. >>>> >>>> >>>> *Files overview:* >>>> >>>> *** ENVR.RB *** >>>> browser = Watir::Browser.new :firefox >>>> >>>> Before do >>>> @b = browser >>>> # @b = Watir::Browser.new :chrome >>>> # @b = Watir::Browser.new :ie >>>> end >>>> *********************************************** >>>> >>>> >>>> *** STEPDEF.RB *** >>>> Given (/^I am navigating to the testsite$/) do >>>> Login_module.open_browser_at *#### Here if instead I pass >>>> directly @b.goto "www.google.com <http://www.google.com>" => it works ###* >>>> end >>>> ****************************************************** >>>> >>>> *** LOGIN.RB *** >>>> module Login_module >>>> def self.open_browser_at >>>> @b.goto "www.google.com" >>>> end >>>> end >>>> ****************************************************** >>>> I would appreciate any help in sorting things out. >>>> >>>> Thanks in advance. >>>> Jeff Fagot >>>> >>>> -- >>>> -- >>>> 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/d/optout. >>>> >>> >>> -- -- 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/d/optout.
