Ask a Question

Python conditional statements

aafreen_jamadar
Occasional Contributor

Python conditional statements

Hi! Has anyone been facing an issue with conditional statements using python?

I am to execute a code which checks for a file in a particular folder and deletes it if found. Also, I have been having issues using inputs from the keyboard. The code terminates whenever an input from the keyboard is required.

 

PS: any examples with if-else statements (python only) would be appreciated.

16 REPLIES 16
rraghvani
Champion Level 3

Do you have example code of it not working?

 

What version of TestComplete are you using?

aafreen_jamadar
Occasional Contributor

I am currently on version 15.52.2.7. 

Following is the code with the keyboard input:

  def start():
      hwndSource = Aliases.I_Software.HwndSource_LogonWindow
      comboBox = hwndSource.LogonWindow.ProfilesComboBox
      comboBox.DropDown()
      hwndSource. Keys("a[Enter]")
      comboBox.Keys("[Enter]")
      time.sleep(30)

As far as conditional statements go, I haven't been able to figure out a way to script it.

(I am assuming testcomplete has a different syntax/ built in functions that I'm not used to)

rraghvani
Champion Level 3

I would like to see the "Python conditional statements" that is not working for you, as you started your first sentence with this question.

 

In the coding you have provided, you are clicking on the dropdown of comboBox, then entering 'a' followed by 'return' on the hwndSource, then entering 'return' on the comboBox. This doesn't deem to be consistent.

 

 

aafreen_jamadar
Occasional Contributor

Here's the code for the conditional statements:

def Test2():
  I_Software = Aliases.I_Software
  button = I_Software.HwndSource_HomeScreenWindow.HomeScreenWindow_.RemoveImagesButton
  if aqObject.CheckProperty(button.Image, "Enabled", cmpEqual, True):
    imageSelector = I_Software.HwndSource_ImageSelector.ImageSelector
    button.ClickButton()
    imageSelector.SelectAllButton.ClickButton()
    imageSelector.OKButton.ClickButton()
  else:
    pass
  homeScreen = I_Software.HwndSource_HomeScreenWindow.HomeScreenWindow_
  homeScreen.ImportImageButton.ClickButton()
  I_Software.dlgImportImage.OpenFile("C:\\Users\\Test Complete\\Desktop\\Samples\\Samples\\Indian.jpg")
  I_Software.HwndSource_MessageBox.MessageBox.OKYesButton.ClickButton()
  listView = homeScreen.GalleryList
  listView.HScroll.Pos = 0
  listView.DblClickItem(0)

rraghvani
Champion Level 3

If the property value of "Enabled" is True for button.Image, then the statement is true. Which means it will perform the following,

imageSelector = I_Software.HwndSource_ImageSelector.ImageSelector
button.ClickButton()
imageSelector.SelectAllButton.ClickButton()
imageSelector.OKButton.ClickButton()

else, pass.

 

What's the exact issue with the conditional statement?

aafreen_jamadar
Occasional Contributor

The problem here is that it performs the statements mentioned above if the button is enabled, but terminates the code if it is not.

rraghvani
Champion Level 3

If you get the following appearing,

rraghvani_0-1689600077188.png

Then change the project settings, on error to continue running,

rraghvani_1-1689600155748.png

The results will look like this afterwards,

rraghvani_2-1689600238060.png

 

This reason it fails - "If the verification succeeds, the method posts a success message to the test log; otherwise it posts a failure message."

aafreen_jamadar
Occasional Contributor

MicrosoftTeams-image (12).png

This is what I see now. the digital import object is present in the object browser and the image was imported before I changed the settings to 'continue running'.

Suddenly, it does not recognize the object.

rraghvani
Champion Level 3

Because the checkpoint has failed, it's not performing the condition in the if statement.

 

If you debug, and step through your coding. You will see exactly what it's doing.

cancel
Showing results for 
Search instead for 
Did you mean: