|
@@ -1,8 +1,11 @@
|
|
|
+# -*- coding: utf-8 -*-
|
|
|
+
|
|
|
from selenium import webdriver
|
|
|
from error import error
|
|
|
import logging
|
|
|
import time
|
|
|
from selenium.common import exceptions
|
|
|
+from selenium.webdriver.common.by import By
|
|
|
|
|
|
|
|
|
class Ctrip:
|
|
@@ -10,6 +13,83 @@ class Ctrip:
|
|
|
self.index = "http://www.ctrip.com/" # 初始化携程的首页地址
|
|
|
self.driver = webdriver.Chrome() # 浏览器对象,之后所有自动化测试操作都会用到该对象
|
|
|
|
|
|
+ def login(self):
|
|
|
+ # 进入登录页
|
|
|
+ print('----------------进入登录页')
|
|
|
+ time.sleep(2)
|
|
|
+ login_btn = self.driver.find_element(By.XPATH, '//*[@id="hp_nfes_accountbar"]/li[1]/div/button/div')
|
|
|
+ if not login_btn:
|
|
|
+ err = '找不到登录按钮'
|
|
|
+ logging.error(err)
|
|
|
+ return err
|
|
|
+ login_btn.click()
|
|
|
+
|
|
|
+ time.sleep(2)
|
|
|
+ code_btns = self.driver.find_elements(By.CLASS_NAME, 'login-entry-dynamic')
|
|
|
+ if len(code_btns) > 0:
|
|
|
+ code_btn = code_btns[0]
|
|
|
+ else:
|
|
|
+ err = '找不到切换手机验证码按钮'
|
|
|
+ logging.error(err)
|
|
|
+ return err
|
|
|
+
|
|
|
+ # 切换到手机号登录
|
|
|
+ time.sleep(2)
|
|
|
+ code_btn.click()
|
|
|
+
|
|
|
+ # 输入账号和发送验证码
|
|
|
+ dyphone = self.driver.find_element(By.ID, 'dyphone')
|
|
|
+ if not dyphone:
|
|
|
+ err = '找不到电话输入框'
|
|
|
+ logging.error(err)
|
|
|
+ return err
|
|
|
+
|
|
|
+ time.sleep(2)
|
|
|
+ dyphone.send_keys('15626215750')
|
|
|
+
|
|
|
+ # 发送验证码按钮
|
|
|
+ sdy = self.driver.find_element(By.ID, 'sdy')
|
|
|
+ if not sdy:
|
|
|
+ err = '找不到发送验证码按钮'
|
|
|
+ logging.error(err)
|
|
|
+ return err
|
|
|
+
|
|
|
+ time.sleep(2)
|
|
|
+ sdy.click()
|
|
|
+
|
|
|
+ # 关闭滑动验证码
|
|
|
+ time.sleep(2)
|
|
|
+ slider = self.driver.find_element(By.XPATH, '//*[@id="sliderdddynamic"]/div/div[1]/div[2]/div')
|
|
|
+ if not slider:
|
|
|
+ err = '找不到验证码关闭按钮'
|
|
|
+ logging.error(err)
|
|
|
+ return err
|
|
|
+ slider.click()
|
|
|
+
|
|
|
+ # 切换到账号密码登录
|
|
|
+ time.sleep(3)
|
|
|
+ go_prev_step = self.driver.find_element(By.XPATH, '/html/body/div[1]/div[2]/div[2]/div[2]/div/div[1]/div[3]/form/a')
|
|
|
+ if not go_prev_step:
|
|
|
+ err = '找不到返回账号登录按钮'
|
|
|
+ logging.error(err)
|
|
|
+ return err
|
|
|
+
|
|
|
+ time.sleep(2)
|
|
|
+ go_prev_step.click()
|
|
|
+
|
|
|
+ # 输入账号密码
|
|
|
+ time.sleep(2)
|
|
|
+ nloginname = self.driver.find_element(By.ID, 'nloginname')
|
|
|
+ npwd = self.driver.find_element(By.ID, 'npwd')
|
|
|
+
|
|
|
+ nloginname.send_keys('15626215750')
|
|
|
+ time.sleep(1)
|
|
|
+ npwd.send_keys('SFPbP3iW')
|
|
|
+ time.sleep(2)
|
|
|
+
|
|
|
+ nsubmit = self.driver.find_element(By.ID, 'nsubmit')
|
|
|
+ nsubmit.click()
|
|
|
+
|
|
|
# 测试机票
|
|
|
def air_ticket(self):
|
|
|
self.close_advert()
|
|
@@ -74,16 +154,22 @@ class Ctrip:
|
|
|
|
|
|
self.driver.get(self.index)
|
|
|
|
|
|
- self.close_advert()
|
|
|
+ # self.close_advert()
|
|
|
+ print('----------------打开了页面')
|
|
|
|
|
|
- err = self.air_ticket()
|
|
|
- if err is not None:
|
|
|
- logging.error("Ctrip test air_ticket with index(%s) error: %s", self.index, err.to_string())
|
|
|
+ err = self.login()
|
|
|
+ if err:
|
|
|
+ logging.error('Ctrip login err', err)
|
|
|
return err
|
|
|
|
|
|
- err = self.railway_ticket()
|
|
|
- if err is not None:
|
|
|
- logging.error("Ctrip test railway_ticket with index(%s) error: %s", self.index, err.to_string())
|
|
|
- return err
|
|
|
+ # err = self.air_ticket()
|
|
|
+ # if err is not None:
|
|
|
+ # logging.error("Ctrip test air_ticket with index(%s) error: %s", self.index, err.to_string())
|
|
|
+ # return err
|
|
|
+ #
|
|
|
+ # err = self.railway_ticket()
|
|
|
+ # if err is not None:
|
|
|
+ # logging.error("Ctrip test railway_ticket with index(%s) error: %s", self.index, err.to_string())
|
|
|
+ # return err
|
|
|
|
|
|
return None
|