sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #47951
Re: [Question #671416]: Script attempts to run then immediately stops, but provides no error msg
Question #671416 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/671416
Ron Turrentine gave more information on the question:
I made some big changes to my script and got it working after I stripped
out the class and changed the class properties to global variables.
This is the working script, however I would love to get it working with
the functions as methods within a class:
#######################
import os
import shutil
import datetime
def takescreenshot():
# import global variables
global sscount
global mypath
global formatssname
# increment screenshot count
sscount += 1
# format out filename using the SS count
nextname = formatssname()
# get our main full screen coords defined
screen = (SCREEN.getX(), SCREEN.getY(), SCREEN.getW(), SCREEN.getH())
# capture the defined screen
img = capture(*screen)
# put the pieces of our new filename into a list
strjoin = (mypath, nextname)
# concatenate the path with the filename (putting a backslash between them)
newFile = "\\".join(strjoin)
# save the screenshot
shutil.copy(img, newFile)
def formatssname():
# import global variable
global sscount
strPad = ""
strcount = str(sscount)
# Determine length of our SS Count, then prepend the appropriuate # of zeroes to its number and append a .png
if len(strcount) == 1:
strPad = "0000" + strcount
elif len(strcount) == 2:
strPad = "000" + strcount
elif len(strcount) == 3:
strPad = "00" + strcount
elif len(strcount) == 4:
strPad = "0" + strcount
strPad = strPad + '.png'
return strPad
def setupbrowser():
# import global variables
global browser
global siteurl
# extract browser filename from PDA.browser property
browsername = os.path.basename(browser)
# Close all instances of the aforementioned browser
closeApp(browsername)
wait(5)
# Define our browser object
pdabrowser = App(browser)
wait(2)
# Open the browser
pdabrowser.open()
wait(5)
#Focus on the browser
pdabrowser.focus()
wait(2)
# Access the address bar
type("l", KeyModifier.CTRL)
wait(2)
# Enter Site URL and navigate to it
type(siteurl + Key.ENTER)
def createfolders():
# import global variables
global fullpath
global mypath
# Concatenate full path string
fullpath = backslash.join(pathinfo)
# Store path in dir obj
mypath = os.path.dirname(fullpath)
# Check if path exists. If not, create it
if not os.path.exists(mypath):
os.makedirs(mypath)
# Setup global variables and environment
basepath = "c:\\screenshots\\doesthiswork"
browser = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
testsite = "Test"
testtype = "Default"
sscount = 0
folderdate = str(datetime.date.strftime(datetime.datetime.date(datetime.datetime.now()),'%m-%d-%y'))
fullpath = ""
siteurl = "https://www.google.com/"
backslash = "\\"
pathinfo = (basepath, testsite, folderdate, testtype)
mypath = ""
# Create our folders
createfolders()
# Setup our browser
setupbrowser()
# take screenshot
takescreenshot()
--
You received this question notification because your team Sikuli Drivers
is an answer contact for Sikuli.