| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 | # -*- coding: utf-8 -*-import unittestimport requestsfrom selenium import webdriverfrom time import sleepfrom selenium.webdriver.common.keys import Keysfrom selenium.webdriver.support.wait import WebDriverWaitfrom selenium.webdriver.support import expected_conditions as ECfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.common.desired_capabilities import DesiredCapabilitiesclass Ssgdfs(object):	def setUp(self):		#self.driver = webdriver.Chrome('E:\chromedriver_win32/chromedriver')		self.driver = webdriver.Remote(command_executor='http://192.168.15.10:8910/', desired_capabilities=DesiredCapabilities.PHANTOMJS)		self.config = {}		self.config['id'] = 1		self.config['login'] = 'http://cn.ssgdfs.com/shop/login/loginPopupForm';		self.config['username'] = 'weiweizhou'		self.config['password'] = 'P4220887'		self.config['product'] = 'http://cn.ssgdfs.com/shop/product/productDetail?recopick=25&prdtCode=79519000009';		self.config['chuguo'] = '3239636'	def test_start(self):		# 登录		self.login()		# 下单		self.buy()		# 支付		self.pay()		# 支付截图		self.crop()	def check():		r = requests.get(self.config['product'])		# 缺货标识		string = 'http://image2.ssgdfs.com/images/shop/cn/renewal/content/btn_soldout.gif'		data = r.text		if string in data:			return False		else:			return True	def login(self):		self.driver.get(self.config['login'])		self.driver.find_element_by_id('login-id').send_keys(self.config['username'])		self.driver.find_element_by_id('login-password').send_keys(self.config['password'])		self.driver.find_element_by_xpath('//input[@alt="login"]').click()		self.driver.implicitly_wait(5)	def buy(self):		self.driver.get(self.config['product'])		# 立刻购买		self.driver.execute_script('directOrderProduct()')		# 等待加载页面完成		self.wait('long-sub')		# 等待弹层关闭		self.waitNot('pay_popup')		# 输入下单信息		self.buy_content()		# 确认订单		self.driver.execute_script('goPaymentCheck()')		# 等待加载页面完成		self.wait('order-agree2')	def buy_content(self):		# 选择护照信息		self.driver.execute_script('setExitInfoHistory("' + self.config['chuguo'] + '")')		# 使用优惠券		# 使用积分		self.driver.find_element_by_xpath('//input[@name="nowUse" and @value="0"]').click()	def pay(self):		# 等待弹层关闭		self.waitNot('loding_popup')		# 输入支付信息		self.pay_content()		# 确认按钮		self.driver.execute_script('window.confirm = function(msg) { return true; }');		# 同意付款		self.driver.execute_script('$("a.goPayment").click()')		#self.driver.switch_to_alert().accept()		#self.wait('qrcode-img-wrapper')		self.wait('qrcode')		sleep(2)		link = self.driver.execute_script('return location.href')		print link	def pay_content(self):		# 确认取货处		self.driver.find_element_by_id('exitDestInfo').click()		# 同意收集个人信息		self.driver.find_element_by_id('agree').click()		# 同意订购		self.driver.find_element_by_id('agree01').click()		# 选择支付方式:支付宝21 微信00		self.driver.find_element_by_xpath('//input[@id="pymntMeansCode" and @value="00"]').click()	def crop(self):		pic_path = 'test.png'		self.driver.save_screenshot(pic_path)	def waitNot(self, name):		WebDriverWait(self.driver, 100).until_not(lambda x: x.find_element_by_class_name(name).is_displayed())	def wait(self, name):		WebDriverWait(self.driver, 100).until(lambda x: x.find_element_by_class_name(name).is_displayed())	def tearDown(self):		self.driver.close()		#passif __name__ == "__main__":    unittest.main()
 |