Forum Discussion

Dave1's avatar
Dave1
New Contributor
8 years ago

Writing Python scripts, composed of several methods

Hi All,

I have problem with writing Python scripts. I want to write one test , composed of several methods. Splitting the script into methods is intended to increase versatility. For example When I have 100 tests, I would have to change 100 scripts when updating the app. However, making a script from a method would save time, because I can change one method, not 100 scripts.

Is it feasible? Knows someone how to do it?

 

I have whole script:

 

def Test():
  TestedApps.XXX.Run()
  XXX = Aliases.XXX
  panel = XXX.WizardFrame.RootPane.null_layeredPane.wizardPanel.Panel
  panel.z.Panel.Panel.Box.Panel.Box.Box.next.ClickButton()
  panel2.Panel.SystemScreen_DefaultPanel.RadioButton.ClickButton()
  panel2.Panel2.Box.Panel.Box.Box.next.ClickButton()
  panel2 = panel.z3.Panel
  scrollablePanel = panel2.Panel2.SystemScreen_DefaultPanel.FormPanel.ScrollPane.FormPanel_1.ScrollablePanel
  scrollablePanel.z2.ClickButton()


 I would like to split him

 

def Test1():
  TestedApps.XXX.Run()
  XXX = Aliases.XXX
  panel = XXX.WizardFrame.RootPane.null_layeredPane.wizardPanel.Panel
  panel.z.Panel.Panel.Box.Panel.Box.Box.next.ClickButton()
  panel2 = panel.z2.Panel
  return panel2

 and

 

def Test2(method):
  panel2=method
  panel2.Panel.SystemScreen_DefaultPanel.RadioButton.ClickButton()
  panel2.Panel2.Box.Panel.Box.Box.next.ClickButton()
  panel2 = panel.z3.Panel
  scrollablePanel = panel2.Panel2.SystemScreen_DefaultPanel.FormPanel.ScrollPane.FormPanel_1.ScrollablePanel
  scrollablePanel.z2.ClickButton()

 

In my main script:

 

def testmain():
  Unit5.Test1()
  Unit5.Test2(Unit5.Test1)

This example does not work properly. Only Test1 passes, but Test2 does not start. Someone knows what`s wrong ?

 

  • Hi,

     

    I'm not python-scripter, but looking at your testmain method

     

    def testmain():
      Unit5.Test1()
      Unit5.Test2(Unit5.Test1)

    I guess Unit5.Test1 is going to run two times. Instead of doing above , what happens when you do like below

     

    def testmain():
      Unit5.Test2(Unit5.Test1)

    Or

     

    def testmain():
      panel =  Unit5.Test1()
      Unit5.Test2(panel)
  • shankar_r's avatar
    shankar_r
    Community Hero

    Hi,

     

    I'm not python-scripter, but looking at your testmain method

     

    def testmain():
      Unit5.Test1()
      Unit5.Test2(Unit5.Test1)

    I guess Unit5.Test1 is going to run two times. Instead of doing above , what happens when you do like below

     

    def testmain():
      Unit5.Test2(Unit5.Test1)

    Or

     

    def testmain():
      panel =  Unit5.Test1()
      Unit5.Test2(panel)
  • baxatob's avatar
    baxatob
    Community Hero

    If method is a function, it should be invoked as a function()

     

    def Test2(method):
        panel2=method() 
    • sanj's avatar
      sanj
      Super Contributor

      When it comes to design

      you need to ask yourself

      Should I use an object oriented approach

      Are there common functions - your base class

      Then is each test doing some variance of that?

      That can be part of an inherited class.

      Also one rule of thumb avoid duplicate code whenever possible if you are trying to do similar things.