Python conditional statements
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Do you have example code of it not working?
What version of TestComplete are you using?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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)
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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)
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The problem here is that it performs the statements mentioned above if the button is enabled, but terminates the code if it is not.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you get the following appearing,
Then change the project settings, on error to continue running,
The results will look like this afterwards,
This reason it fails - "If the verification succeeds, the method posts a success message to the test log; otherwise it posts a failure message."
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
