def createTagForLessonTextlesson(self): try : obj2= CreateTagLessonTextLesson() obj2.createLessonTextLessontag() finally: print "clicking on Home" book=xlrd.open_workbook(os.path.join('TestData.xlsx')) first_sheet = book.sheet_by_name('Login_Credentials') print("Fetching the Attribute Name from Excel Sheet\n") # read a cell cell = first_sheet.cell(1,1) HomeURL = cell.value print HomeURL driver.get(HomeURL) wait=WebDriverWait(driver, 80) wait.until(EC.visibility_of_element_located((By.ID,"global-header-search"))) print "Home Page Loaded"
def parse_single_file(file_path ): book = xlrd.open_workbook(file_path) sheet_count = book.nsheets if ( sheet_count < 1): raise Exception( "%s has no sheet!" % (file_path, ) ) # 获得第一个sheet sh = book.sheet_by_index(0) if ( sh.name != DAILY_REPORT_SHEET_NAME ): raise Exception( "%s 的第一个sheet不是 '%s'" % (file_path,DAILY_REPORT_SHEET_NAME ) ) # 确认是'逐日盯市' title = sh.cell_value(colx=0 , rowx=1) if (REPORT_TITLE != title): raise Exception( "%s 的不是 '%s'" % (file_path,REPORT_TITLE ) ) # 获得'成交明细' sheet sh_tr_details = book.sheet_by_name("成交明细") if (sh_tr_details is None ): raise Exception( "%s 里找不到'成交明细'sheet" % (file_path) ) # 获得交易日 t_day_cv = sh.cell_value( colx = T_DAY_COL, rowx = T_DAY_ROW ) #print "Yes, T_day is %s" % ( t_day_cv, ) t_day = datetime.strptime( t_day_cv , '%Y-%m-%d').date() result = SingleFileResult( t_day ) # 定位'期货期权账户资金状况' row_walker = 7 found = False while row_walker < sh.nrows: header_balance = sh.cell_value(colx = 0 , rowx = row_walker) if ('期货期权账户资金状况' == header_balance): found = True break row_walker = row_walker +1 if not found: raise Exception ("%s 找不到'期货期权账户资金状况'" % (file_path, ) ) base_row_num = row_walker # 前日结存 result.prev_balance = sh.cell_value( colx = 2, rowx = base_row_num + 1) # 当日盈亏 result.profit = sh.cell_value( colx = 2, rowx = base_row_num + 3) # 当日手续费 result.fee = sh.cell_value( colx = 2, rowx = base_row_num + 5) # 当日结存 result.balance = sh.cell_value( colx = 2, rowx = base_row_num + 6) # 保证金占用 result.margin = sh.cell_value( colx = 7, rowx = base_row_num + 6) # 准备处理 期货成交汇总 row_walker = TRADE_RECORD_HEADER_ROW found = False while row_walker < sh.nrows: header_cv = sh.cell_value(colx = TRADE_RECORD_HEADER_COL , rowx = row_walker) if ('期货成交汇总' == header_cv): found = True break row_walker = row_walker +1 if not found: raise Exception ("%s 找不到'期货成交汇总'区域" % (file_path, ) ) row_walker = 2 + row_walker col0 = sh.cell_value (colx = TRADE_RECORD_HEADER_COL , rowx = row_walker) while ( '合计' != col0): #print "processing row %d" % ( row_walker, ) #one_tr_entry = parse_1_tr_row( sh.row( row_walker), row_walker ) #if ( one_tr_entry is not None): # #one_tr_entry.dump() # result.aggregated_tr_arr.append( one_tr_entry) # # 之后会解析 '成交明细' sheet,这里一概跳过即可 # row_walker = row_walker + 1 col0 = sh.cell_value (colx = TRADE_RECORD_HEADER_COL , rowx = row_walker) #准备处理 持仓记录 row_walker = row_walker + 3 header_cv = sh.cell_value(colx = TRADE_RECORD_HEADER_COL , rowx = row_walker) if ('合约' != header_cv and '日期'!= header_cv): raise Exception ("%s 找不到'期货持仓汇总'区域" % (file_path, ) ) row_walker = row_walker + 1 col0 = sh.cell_value (colx = POS_RECORD_HEADER_COL , rowx = row_walker) while ( '合计' != col0): #print "processing row %d" % ( row_walker, ) if '合约' == header_cv: one_pos_entry = parse_1_pos_row_until2018( sh.row( row_walker), row_walker ) else: one_pos_entry = parse_1_pos_row_2019( sh.row( row_walker), row_walker ) if ( one_pos_entry is not None): #one_pos_entry.dump() result.aggregated_pos_arr.append( one_pos_entry) row_walker = row_walker + 1 col0 = sh.cell_value (colx = POS_RECORD_HEADER_COL , rowx = row_walker) # 成交明细 result.aggregated_tr_arr = parse_tr_details_sheet(file_path, sh_tr_details ) result.verify() scan_tr_detail(result.aggregated_tr_arr) #result.dump() return result
def createLessonTextLessontag(self): print "Reading data from excel sheet" book=xlrd.open_workbook(os.path.join('TestData.xlsx')) first_sheet = book.sheet_by_name('CreateTag') print("Fetching the Attribute Name from Excel Sheet\n") # read a cell cell = first_sheet.cell(25,2) TagName = cell.value print TagName cell = first_sheet.cell(25,3) ExpectedSuccessMessage = cell.value print ExpectedSuccessMessage wait=WebDriverWait(driver, 80) wait.until(EC.visibility_of_element_located((By.XPATH,"html/body/div/div/div[3]/div[1]/div/nav/div/div[2]/div[6]/a"))) driver.find_element_by_xpath("html/body/div/div/div[3]/div[1]/div/nav/div/div[2]/div[6]/a").click() print "Clicked on admin icon" wait.until(EC.visibility_of_element_located((By.XPATH,"html/body/div/div/div[3]/div[1]/div/nav/div/div[2]/div[6]"))) driver.find_element_by_xpath("html/body/div/div/div[3]/div[1]/div/nav/div/div[2]/div[6]").click() print "Clicked on Admin" driver.find_element_by_xpath("html/body/div/div/div[3]/div[1]/div/nav/div/div[2]/div[6]/div/ul/li[5]").click() print "Clicked on Tag" wait.until(EC.visibility_of_element_located((By.XPATH,"html/body/div/div/div[3]/div[2]/div/header/h1"))) print "Tag Page Loaded" driver.find_element_by_xpath("html/body/div/div/div[3]/div[2]/div/header/div/div/button").click() print "Clicked on Create Tag Button" wait.until(EC.visibility_of_element_located((By.XPATH,"html/body/div/div/div[3]/div[2]/div/div/section[1]/div[1]/div/div[1]/div/input"))) print "Verifying Create Tag Name field " if driver.find_element_by_id("add-tag-input").is_displayed(): print("Enter Tag name field is displayed") else: print "" raise Exception print "Verified Tag Name field" ele = driver.find_element_by_xpath("html/body/div/div/div[3]/div[2]/div/div/section[1]/div[1]/div/div[1]/div/input") webdriver.ActionChains(driver).move_to_element(ele).send_keys(TagName).perform() print "Entered Tag Name :"+TagName time.sleep(6) driver.find_element_by_xpath("html/body/div/div/div[3]/div[2]/div/div/section[1]/div[1]/div/div[2]/button[1]").click() time.sleep(6) wait.until(EC.visibility_of_element_located((By.XPATH,"html/body/div/div/div[3]/div[2]/div/div/section[1]/div[1]/div"))) ActualMessage = driver.find_element_by_xpath("html/body/div/div/div[3]/div[2]/div/div/section[1]/div[1]/div") ExpectedMessage = TagName+ExpectedSuccessMessage print "ExpectedMessage "+ExpectedMessage print("Expected Success Message and Actual Success Message is Matching,Success Message Verified") print "Searching for the created Tag" wait.until(EC.visibility_of_element_located((By.XPATH,"html/body/div/div/div[3]/div[2]/div/div/section[1]/div[2]/div/div/input"))) time.sleep(6) element =driver.find_element_by_name("tag-index-search") element.clear() element.send_keys(TagName) driver.find_element_by_name("tag-index-search").send_keys(Keys.ENTER) time.sleep(6) print "Entered Tag Name for Search" wait.until(EC.visibility_of_element_located((By.XPATH,"html/body/div/div/div[3]/div[2]/div/div/section[2]/div/ul/li[1]"))) print "Verifying the created Tag in the list" ele =driver.find_element_by_xpath("html/body/div/div/div[3]/div[2]/div/div/section[2]/div/ul/li[1]") print ele.text if driver.find_element_by_xpath("html/body/div/div/div[3]/div[2]/div/div/section[2]/div/ul/li[1]").is_displayed(): print("Created Tag in the list") else: print "" raise Exception