# -*- coding: utf-8
'''
---------------------------------------------------------
ID : JB0101-01
アプリケーションを操作するデモ
クラウド型の基幹システムやEC管理サイトをイメージしている
1.WEBアプリケーションへのログイン
2.メニューを操作
3.日付入力して売上データをダウンロードする
4.WEBアプリケーションの終了
---------------------------------------------------------
'''
import os
import sys
import webbrowser
import datetime
reload(sys)
sys.setdefaultencoding('utf-8')
def OpenSystem():
'''
デモサイトを直接開く
'''
type("m",KEY_WIN) #全画面を最小化する
#デモサイトを立ち上げる
url = "http://marukentokyo.jp/topdemo/"
webbrowser.open(url)
#ログイン画面が立ち上がるのを待ちます
try:
wait(
,30)
sleep(1)
#最大化する
if exists(Pattern(
).similar(0.80)):
click(Pattern(
).similar(0.80))
except FindFailed, e:
popup(u"エラーが発生しました" + unicode(e))
exit()
def LoginApplication():
'''
デモアプリケーションにログインする
'''
try:
type(Pattern(
).targetOffset(129,2), "test")
sleep(1)
type(Key.TAB)
type("00001")
sleep(1)
click(
)
except FindFailed, e:
popup(u"エラーが発生しました" + unicode(e))
exit()
def OperateMenu():
'''
デモアプリケーションのメニューを操作する
'''
wait(
,10)
click(
)
try:
region1 = Region(323,523,1100,489)
while not region1.exists(Pattern(
).similar(0.83),0.1):
type(Key.DOWN)
sleep(1)
click(Pattern(
).similar(0.80))
sleep(1)
wait(
,10)
except FindFailed, e:
popup(u"エラーが発生しました" + unicode(e))
exit()
def OperateMenu2():
'''
デモアプリケーションのメニューを操作する
'''
try:
click(
)
#sleep(1)
wait(
,10)
except FindFailed, e:
popup(u"エラーが発生しました" + unicode(e))
exit()
def DownloadData():
'''
ダウンロード画面の処理
'''
try:
#月初から昨日までの日付を入れる
today = datetime.datetime.today() #当日
#昨日の日付
yesterday = today + datetime.timedelta(days=-1)
#月初の日付
FirstDate = datetime.datetime(yesterday.year,yesterday.month,1)
click(Pattern(
).targetOffset(91,-3))
s1 = FirstDate.strftime("%Y/%m/%d")
paste(s1)
type(Key.TAB)
sleep(1)
s2 = yesterday.strftime("%Y/%m/%d")
paste(s2)
sleep(1)
click(
)
sleep(1)
wait(
,10)
sleep(1)
except FindFailed, e:
popup(u"エラーが発生しました" + unicode(e))
exit()
def DownloadData2():
'''
ダウンロード画面の処理
'''
try:
#ダウンロード画面を操作する
click(
)
#全回ダウンロードしたデータがあれば消しておく
file1 = os.path.join(os.environ['USERPROFILE'],"Downloads","SalesData.csv")
if (os.path.isfile(file1)):
os.remove(file1)
sleep(2)
click(
)
sleep(2)
except FindFailed, e:
popup(u"エラーが発生しました" + unicode(e))
exit()
def CloseApplication():
'''
デモアプリケーションを終了する
'''
try:
click(
)
sleep(1)
popup(u"デモプログラムを終了します")
except FindFailed, e:
popup(u"エラーが発生しました" + unicode(e))
exit()
if __name__ == "__main__":
OpenSystem()
LoginApplication()
OperateMenu()
OperateMenu2()
DownloadData()
DownloadData2()
CloseApplication()