User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2003
    Post Thanks / Like
    0 Post(s)
    0 Thread(s)
    Total Downloaded

    Objects and classes

    A general coding question really from someone with a lot of scripting experience but without having to create classes myself. I understand the basic principles of OOP (animal - dog examples etc) but still struggle a bit regarding what to make/put in a class although it makes it easier when I think what I would put in a function for code reuse in non OO scripting but then wondering if not real OO.
    Someone has mentioned thinking of everything as an object which is an easy statement (okay, everything is an object) but I then thought "should everything be an object?"

    So I have a GUI Windows Form application that I wanted to invoke and will later want to do a lot more with. It's a large application. Using C# I initially created a class called InvokeApplicationAndLogin which is not the best name as I later realised when I found the application can linger around so I might want to kill it, and the name itself does not really reflect an object? I haven't renamed the class yet but have ended up with two methods - one to invoke the application and log in, another method that finds the process of the application and then kills it if it is in an unusable state. This second kill method is called by the first method (Invoke)before it tries to invoke the application because the invoke will fail otherwise. Also having the kill method separate means I can call it from elsewhere if I need to (such as from main method in test), so I'm sure I have done the right thing here.

    So the invoke method takes a few params (location of app, username,password). The second method takes none as it just searches through the running processes for a process with the correct name to kill. Something else I have realised here is that I could change this so that I have code in future that can be used to kill any application runninng process (rather than hard coding the process name) and this method should also be moved out of this class.

    Also note that I may wish to use a lot of functionality the large application provides during testing but not testing the application itself because this application is used to confirm test results/create data for the web apps that will be tested..

    How would you go about the above regarding classes and objects? I was thinking I could separate out the invoke application and login method to separate methods of the same class but not sure it's needed especially as it's an odd application that is invoked from a browser but is a Windows Form application (it's a Windows .net non web app - a client application) but doing this I think would make the main test more readable (as Invoke, Login methods would be called separately from the test). And of course changing "kill" application to make the kill process more generic so it could be used in future to kill others apps I will definitely do, as well as moving this to a "utilities" library.

    How would you name my class above?I thought just calling it "Application<Name>" (where<Name> is the name of the app) but I will need to do a lot with this application that probably shouldn't be in the same class? I can think of an appropriate name but just wondering if I'm actually doing this the right way and not stuck back in my non-OO "function" writing days .

    Thanks for any thoughts. I realise what I am doing is probably not wrong but any thoughts would be good.
    Last edited by DSM; 07-04-2015 at 12:05 AM.

  2. #2
    SQA Knight
    Join Date
    May 2006
    Playa Del Rey, California, United States
    Post Thanks / Like
    17 Post(s)
    1 Thread(s)
    Total Downloaded
    I like to think of ways to avoid retyping many things as possible.

    For example, let's say something common is registration, how can you make that much easier?

    I might do something like,
    class Credentials {
      string Username;
      string Password;
    class AddressInfo {
      string StreetAddress;
      string ZipCode;
      string City;
      string State;
      string Country;
    class TelePhoneInfo {
      string CountryCode;
      string AreaCode;
      string PhoneNumber;
    class PersonalInfo {
      string FirstName;
      string LastName;
      AddressInfo Address;
      TelephoneInfo Telephone;
    class RegistrationInfo {
      PersonalInfo Personal;
      Credential Credentials;
    Then when you write the test with page objects, they read at a very high level.

    var expectedRegistrationInfo = LoadRegistrionInfoFromDisk();
    var registrationFrom = PageFactory.Init<RegistrationPage>(driver);
    driver.GoToUrl("...login page...");
    var loginPage = PageFactory.Init<LoginPage>(driver);
    What you get is code that reads like high level concepts, hiding away the details, that makes it much easier to maintain.
    David Lai
    SDET / Consultant
    LinkedIn profile



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 11.54%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 01:47 PM.

Copyright BetaSoft Inc.