• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Wrapper classes in pattern which I use it

 
Greenhorn
Posts: 13
1
  • Number of slices to send:
    Optional 'thank-you' note:
Hello,
I trying to accomplish my framework for testing. I'm still at the beginning and I miss lackunderstanding of how to do this what I want it. It has Selenium and TestNG. I use a factory pattern to instantiate objects (I won't copy-paste full code, I will only what I think is unnecessary to be understandable) :






BaseTest page which has to extend every Test class:



As you can see I want to get the full potential and to use parallel testing.
This code above is ok, I mean it works but if you have any suggestions I would like to hear everything to learn better.

Then I decided it will have my own wrapper Driver and Element class which I will call where I need it and it will have override methods with little boost .



I won't copy-paste all abstract methods. I just added to see what I really want to do it. Anyway, I have a lot of work to do in those methods.



Element class:





First I wanted to create for Driver and Element to be decorators. But I am not sure do I really need it in overridden methods to call something new, before or after from CoreElement/Driver classes. Now I'm wondering do Driver and Element will stay in SRP because I think it will have a lot of abstract methods.

But the main question of this topic is if I let my wrapper Driver and Element how to implement them in factory pattern and to call my Driver instead of WebDriver? That is the part that I can understand to continue to work on it.

Please, help me.

 
Saloon Keeper
Posts: 15625
366
  • 1
  • Number of slices to send:
    Optional 'thank-you' note:
So if I understand correctly, you want to achieve two things:

  • Decorate WebElement and WebDriver with your own methods.
  • Create factory of driver managers, where a driver manager wraps around a specific type of (decorated) driver.

  • First, make sure you have interfaces for your driver manager, driver and element types. Providing only abstract classes is a real pain if you decide later that you want to use a different base implementation.

    You can easily solve your problem by having your manager return instances of your custom driver interface, instead of WebDriver:

    Now all of this is massively overengineered and I don't think you need it all. Just take the bits that help.

    I also made Driver and DriverManager extend AutoCloseable. That means you'll be able to do something like this:

    This will automatically make the driver quit when the test finishes.
     
    Deyan Perov
    Greenhorn
    Posts: 13
    1
    • Number of slices to send:
      Optional 'thank-you' note:
    First, thank you very much! You showed me a new level for me how to think about implementation.

    Decorate WebElement and WebDriver with your own methods.


    Yes and no. When I researched I thought it will be useful. I am in dilemma do I need a decorator pattern here. What do you think? I want to achieve this project (skeleton of the project) can use for mobile testing too (Appium) because of that my goal is to wrap Element and Driver.
    How do I look at a decorator? Some methods for Elements may not be applicable in some situations and then I want to override them over decorator. if I really need that then am I making a mistake somewhere?

    Create factory of driver managers, where a driver manager wraps around a specific type of (decorated) driver.


    Yes.

    I am going to implement these codes.
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 15625
    366
    • 1
    • Number of slices to send:
      Optional 'thank-you' note:

    Deyan Perov wrote:I am in dilemma do I need a decorator pattern here. What do you think?


    Honestly, I don't know. What problem are you trying to solve? As far as I can tell, once you have setup a driver for a specific browser, using the driver to perform your tests is the same regardless of the browser. If you don't like the API provided by WebDriver and WebElement, you can of course provide your own façade that wraps around those classes, but you wouldn't need a custom subclass for every different type of browser. In that case, just rename WebDriverDecorator to SeleniumDriverFacade and make it final. You can then also get rid of Element and all its subtypes, and just return WebElement.

    I want to achieve this project (skeleton of the project) can use for mobile testing too (Appium) because of that my goal is to wrap Element and Driver.


    I'm not familiar with that framework, but if there is overlap with the drivers and elements used by Selenium, then yes it makes sense to write your own Element and Driver interfaces and have façades for Selenium and Appium implement those interfaces by wrapping around the classes that Selenium/Appium provide.

    How do I look at a decorator? Some methods for Elements may not be applicable in some situations and then I want to override them over decorator.


    You need to explain this a little bit better. What methods may not be applicable? In what situations?
     
    Deyan Perov
    Greenhorn
    Posts: 13
    1
    • Number of slices to send:
      Optional 'thank-you' note:
    Maybe I’m not on the right track and I don't know how to understand better. I think the decorator is not what I am looking for.
    My idea is I want to create my own methods for any Element and those methods I will use for locators to interact with it. The driver will have his own methods too.
    This is one of example which probably I will use:





    Before it clicks on an element it has something to happen to be sure there is an element I am looking for, for example above to wait for elementToBeClickable, to be presented in DOM, stale element, or anything else to help me to avoid possible exceptions. I don't want just to call Selenium's WebDriver and to click() on an element. In a similar direction, it will work with other Element's methods.
    I thought decorator pattern can be useful if some methods in some situation for some element on a page doesn't work jobs well to override over ElementDecorator and to use it in that specific situation. I didn't try this in practice. That was on my mind when I start to explore how to do this. I don't have enough experience to resolve is this good or not.
    I hope I have explained a little better what I want to achieve.

    If you don't like the API provided by WebDriver and WebElement, you can of course provide your own façade that wraps around those classes, but you wouldn't need a custom subclass for every different type of browser. In that case, just rename WebDriverDecorator to SeleniumDriverFacade and make it final. You can then also get rid of Element and all its subtypes, and just return WebElement.


    Could you please show me this in a small example to be sure I understood you?
     
    Deyan Perov
    Greenhorn
    Posts: 13
    1
    • Number of slices to send:
      Optional 'thank-you' note:
    I did refactoring, I avoid the decorator pattern. The main problem is in BaseTest class where I need to use ThreadLocal class and to set the driver which I will use in a multi-thread. Every Test class has to extend BaseTest class.

    I have to initialize DefaultDriverManagerFactory in this class but I don't see the point to put in BaseTest Duration, Clock and Sleeper attributes which have to be put in constructor DefaultDriverManagerFactory(Duration timeout, Duration sleep, Clock clock, Sleeper sleeper). That codes haven't to be part of BaseTest.
    If I use the static method (from my first post) then I have to put static for interface DriverManagerFactory method DriverManager createManager(WebDriverType driverType); with the body. Is that good practice in this situation?
























    Can anyone help me how to do this?
     
    Deyan Perov
    Greenhorn
    Posts: 13
    1
    • Number of slices to send:
      Optional 'thank-you' note:
    This topic has over 1500 views. Did I explain badly what I need? I just need some guidelines. I don't have a lot of knowledge and I hoped I will find help here. I think this question isn't for StackOverflow because I need directions on how to do and finish.
    it was shown to me in one way but in a way, I don’t know how to finish unlike mine originally.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic
    vceplus-200-125    | boson-200-125    | training-cissp    | actualtests-cissp    | techexams-cissp    | gratisexams-300-075    | pearsonitcertification-210-260    | examsboost-210-260    | examsforall-210-260    | dumps4free-210-260    | reddit-210-260    | cisexams-352-001    | itexamfox-352-001    | passguaranteed-352-001    | passeasily-352-001    | freeccnastudyguide-200-120    | gocertify-200-120    | passcerty-200-120    | certifyguide-70-980    | dumpscollection-70-980    | examcollection-70-534    | cbtnuggets-210-065    | examfiles-400-051    | passitdump-400-051    | pearsonitcertification-70-462    | anderseide-70-347    | thomas-70-533    | research-1V0-605    | topix-102-400    | certdepot-EX200    | pearsonit-640-916    | itproguru-70-533    | reddit-100-105    | channel9-70-346    | anderseide-70-346    | theiia-IIA-CIA-PART3    | certificationHP-hp0-s41    | pearsonitcertification-640-916    | anderMicrosoft-70-534    | cathMicrosoft-70-462    | examcollection-cca-500    | techexams-gcih    | mslearn-70-346    | measureup-70-486    | pass4sure-hp0-s41    | iiba-640-916    | itsecurity-sscp    | cbtnuggets-300-320    | blogged-70-486    | pass4sure-IIA-CIA-PART1    | cbtnuggets-100-101    | developerhandbook-70-486    | lpicisco-101    | mylearn-1V0-605    | tomsitpro-cism    | gnosis-101    | channel9Mic-70-534    | ipass-IIA-CIA-PART1    | forcerts-70-417    | tests-sy0-401    | ipasstheciaexam-IIA-CIA-PART3    | mostcisco-300-135    | buildazure-70-533    | cloudera-cca-500    | pdf4cert-2v0-621    | f5cisco-101    | gocertify-1z0-062    | quora-640-916    | micrcosoft-70-480    | brain2pass-70-417    | examcompass-sy0-401    | global-EX200    | iassc-ICGB    | vceplus-300-115    | quizlet-810-403    | cbtnuggets-70-697    | educationOracle-1Z0-434    | channel9-70-534    | officialcerts-400-051    | examsboost-IIA-CIA-PART1    | networktut-300-135    | teststarter-300-206    | pluralsight-70-486    | coding-70-486    | freeccna-100-101    | digitaltut-300-101    | iiba-CBAP    | virtuallymikebrown-640-916    | isaca-cism    | whizlabs-pmp    | techexams-70-980    | ciscopress-300-115    | techtarget-cism    | pearsonitcertification-300-070    | testking-2v0-621    | isacaNew-cism    | simplilearn-pmi-rmp    | simplilearn-pmp    | educationOracle-1z0-809    | education-1z0-809    | teachertube-1Z0-434    | villanovau-CBAP    | quora-300-206    | certifyguide-300-208    | cbtnuggets-100-105    | flydumps-70-417    | gratisexams-1V0-605    | ituonline-1z0-062    | techexams-cas-002    | simplilearn-70-534    | pluralsight-70-697    | theiia-IIA-CIA-PART1    | itexamtips-400-051    | pearsonitcertification-EX200    | pluralsight-70-480    | learn-hp0-s42    | giac-gpen    | mindhub-102-400    | coursesmsu-CBAP    | examsforall-2v0-621    | developerhandbook-70-487    | root-EX200    | coderanch-1z0-809    | getfreedumps-1z0-062    | comptia-cas-002    | quora-1z0-809    | boson-300-135    | killtest-2v0-621    | learncia-IIA-CIA-PART3    | computer-gcih    | universitycloudera-cca-500    | itexamrun-70-410    | certificationHPv2-hp0-s41    | certskills-100-105    | skipitnow-70-417    | gocertify-sy0-401    | prep4sure-70-417    | simplilearn-cisa    |
    http://www.pmsas.pr.gov.br/wp-content/    | http://www.pmsas.pr.gov.br/wp-content/    |