示例#1
0
文件: index_page.py 项目: pylk/jinbi
class IndexPage(object):
    def __init__(self):
        self.driver = GetSeleniumDriver().driver

    def click_login_link(self):
        try:
            click_login_link = self.driver.find_element_by_link_text("请登录")
            return click_login_link
        except Exception:
            assert False, "未成功点击登录"

    def click_goods14_link(self):
        try:
            click_goods14_link = self.driver.find_element_by_link_text(
                RES.goods14_link)
            return click_goods14_link
        except Exception:
            assert False, "未能成功点击商品"

    #点击会员中心
    def click_member_center(self):
        try:
            click_member_center = self.driver.find_element_by_link_text(
                RES.member_center_link)
            return click_member_center
        except Exception:
            assert False, "未能成功点击会员中心"
示例#2
0
class AddShoppingCart(unittest.TestCase):
    def setUp(self):
        self.driver = GetSeleniumDriver().driver
        CommonDef().login(u"http://pftest.ecgci.com/index.html", u"test0135",
                          u"aaaaaa")

    def tearDown(self):
        CommonDef().quit()

    def test_add_shoppingcart(self):
        count1 = 0
        count2 = 0

        for i in range(1, 1100):
            self.driver.get(
                "http://itemtest.ecgci.com/product_detail_%d.html" % i)
            #time.sleep(1)
            try:
                self.driver.find_element_by_id("gwc").click()
            except Exception as error:
                print "%d未能成功加入购物车" % i
                count1 += 1
            count2 += 1
            count = count2 - count1
            while count > 50:
                break
示例#3
0
class CancleOrder(unittest.TestCase):
    def setUp(self):
        self.driver = GetSeleniumDriver().driver
        CommonDef().login(u"http://pftest.ecgci.com/index.html", u"test0135",
                          u"aaaaaa")

    def tearDown(self):
        CommonDef().quit()

    def testcase_cancle_order(self):
        self.driver.find_element_by_link_text(u'我的订单').click()
        time.sleep(1)
        #self.driver.find_element_by_class_name("cancel_order").click()
        self.driver.find_element_by_xpath(
            "//*[@id='list_box']/tr[1]/td[9]/div/div[4]/a").click()
        time.sleep(1)
示例#4
0
 def setUp(self):
     self.driver = GetSeleniumDriver().driver
     url = ReadExcelData().returnExcelData('data.xlsx', 'index', 0, 1)
     self.driver.get(url)
     time.sleep(1)
     self.driver.maximize_window()
     time.sleep(1)
     #点击请登录
     IndexPage().click_login_link().click()
     #输入用户名
     username = ReadExcelData().returnExcelData('data.xlsx', 'index', 2, 1)
     LoginPage().click_username().send_keys(username)
     #输入密码
     password = ReadExcelData().returnExcelData('data.xlsx', 'index', 3, 1)
     LoginPage().click_password().send_keys(password)
     #点击登录按钮
     LoginPage().click_login_submit().click()
     #判断是否登录成功
     '''
     def is_login_sucess(cls):
        #判断是否获取到登录账户名称
        try:
             text = cls.driver.find_element_by_id("lnk_current_user").text
             print text
             return True
         except:
             return False
     '''
     #获取当前窗口句柄
     nowhandle = self.driver.current_window_handle
     time.sleep(2)
     #点击首页-会员中心
     IndexPage().click_member_center().click()
     mylogger.debug("点击首页-会员中心")
     self.driver.implicitly_wait(5)
     #获取所有handle
     allhandles = self.driver.window_handles
     #循环,当句柄不等于首页句柄时,转换为现在的窗口句柄
     for handle in allhandles:
         if handle != nowhandle:
             self.driver.switch_to_window(handle)
     time.sleep(2)
     #点击会员中心-收货地址
     MemberCenter().clink_address_link().click()
     mylogger.debug("点击会员中心-收货地址")
     self.driver.implicitly_wait(5)
示例#5
0
 def setUp(self):
     self.driver = GetSeleniumDriver().driver
     self.driver.get("http://pftest.ecgci.com/index.html")
     time.sleep(1)
     self.driver.maximize_window()
     time.sleep(1)
     #点击请登录
     IndexPage().click_login_link().click()
     time.sleep(1)
     #输入用户名
     LoginPage().click_username().send_keys(u"test0135")
     time.sleep(1)
     #输入密码
     LoginPage().click_password().send_keys("aaaaaa")
     time.sleep(3)
     #点击登录按钮
     LoginPage().click_login_submit().click()
     time.sleep(3)
示例#6
0
class GoodsDetail(object):
    def __init__(self):
        self.driver=GetSeleniumDriver().driver
    def click_buy_id(self):
        try:
            click_buy_id=self.driver.find_element_by_id(RES().buy_id)
            return click_buy_id
        except Exception:
            assert False,"未能成功点击立即购买"
    time.sleep(2)
示例#7
0
class OrderSubmitPage(object):
    def __init__(self):
        self.driver = GetSeleniumDriver().driver

    def input_question_id(self):
        try:
            input_question_id = self.driver.find_element_by_id(RES.question_id)
            return input_question_id
        except Exception:
            assert False, "未定位到问题框"
        time.sleep(2)

    def click_order_submit(self):
        try:
            click_order_submit = self.driver.find_element_by_id(
                RES.order_submit_button_id)
            return click_order_submit
        except Exception:
            assert False, "未能成功点击提交订单按钮"
        time.sleep(2)
示例#8
0
class MemberCenter(object):
    def __init__(self):
        self.driver = GetSeleniumDriver().driver

    #点击收货地址
    def clink_address_link(self):
        try:
            click_address_link = self.driver.find_element_by_link_text(
                RES().address_link)
            return click_address_link
        except Exception:
            assert False, "未能成功点击收货地址"
示例#9
0
文件: login_page.py 项目: pylk/jinbi
class LoginPage(object):
    def __init__(self):
        self.driver = GetSeleniumDriver().driver

    def click_username(self):  #定位到用户名
        try:
            click_username = self.driver.find_element_by_id(RES.username_id)
            return click_username
        except Exception:
            assert False, "未定位到用户名"

    def click_password(self):
        try:
            click_password = self.driver.find_element_by_id(RES.passwords_id)
            return click_password
        except Exception:
            assert False, "未定位到密码框"

    def click_password(self):
        try:
            click_password = self.driver.find_element_by_id(RES.passwords_id)
            return click_password
        except Exception:
            assert False, "未定位到密码框"

    def input_code(self):
        try:
            click_code = self.driver.find_element_by_id(RES.code_id)
            return click_code

        except Exception:
            assert False, "未定位到验证码"

    def click_login_submit(self):
        try:
            click_login_submmit = self.driver.find_element_by_id(
                RES.login_submit_button_id)
            return click_login_submmit
        except Exception:
            assert False, "未定位到登录按钮"
示例#10
0
 def setUpClass(cls):
     cls.driver = GetSeleniumDriver().driver
示例#11
0
class TestAddress(unittest.TestCase):
    #继承unnittest初始化方法
    @classmethod
    def setUpClass(cls):
        cls.driver = GetSeleniumDriver().driver

    @classmethod
    def tearDownClass(cls):
        cls.driver.quit()

    def setUp(self):
        self.driver = GetSeleniumDriver().driver
        url = ReadExcelData().returnExcelData('data.xlsx', 'index', 0, 1)
        self.driver.get(url)
        time.sleep(1)
        self.driver.maximize_window()
        time.sleep(1)
        #点击请登录
        IndexPage().click_login_link().click()
        #输入用户名
        username = ReadExcelData().returnExcelData('data.xlsx', 'index', 2, 1)
        LoginPage().click_username().send_keys(username)
        #输入密码
        password = ReadExcelData().returnExcelData('data.xlsx', 'index', 3, 1)
        LoginPage().click_password().send_keys(password)
        #点击登录按钮
        LoginPage().click_login_submit().click()
        #判断是否登录成功
        '''
        def is_login_sucess(cls):
           #判断是否获取到登录账户名称
           try:
                text = cls.driver.find_element_by_id("lnk_current_user").text
                print text
                return True
            except:
                return False
        '''
        #获取当前窗口句柄
        nowhandle = self.driver.current_window_handle
        time.sleep(2)
        #点击首页-会员中心
        IndexPage().click_member_center().click()
        mylogger.debug("点击首页-会员中心")
        self.driver.implicitly_wait(5)
        #获取所有handle
        allhandles = self.driver.window_handles
        #循环,当句柄不等于首页句柄时,转换为现在的窗口句柄
        for handle in allhandles:
            if handle != nowhandle:
                self.driver.switch_to_window(handle)
        time.sleep(2)
        #点击会员中心-收货地址
        MemberCenter().clink_address_link().click()
        mylogger.debug("点击会员中心-收货地址")
        self.driver.implicitly_wait(5)

    def tearDown(self):
        self.driver.delete_all_cookies()
#编辑收货地址

    def test01(self):
        mylogger.debug("开始编辑地址")
        #点击编辑
        mylogger.debug("点击编辑")
        try:
            AddressPage().click_edit_address().click()
        except Exception:
            assert False, "未能成功点击编辑按钮"
        self.driver.implicitly_wait(5)
        #清空收货人原有内容
        mylogger.debug("清空收货人原有内容")
        AddressPage().input_edit_name_id().clear()
        try:
            AddressPage().input_edit_name_id().clear()
        except Exception:
            assert False, "未能成功清空收货人原有信息"
        time.sleep(4)
        #编辑收货人
        mylogger.debug("编辑收货人")
        try:
            edit_name = ReadExcelData().returnExcelData(
                'data.xlsx', 'address', 0, 1)
            AddressPage().input_edit_name_id().send_keys(edit_name)
        except Exception:
            assert False, "未能成功编辑收货人"
        self.driver.implicitly_wait(5)
        #选择地址_省
        mylogger.debug("选择地址_省")
        try:
            AddressPage().select_edit_province_id().click()
        except Exception:
            assert False, "未能成功选择地址_省"
        time.sleep(2)
        #选择地址_市
        mylogger.debug("选择地址_市")
        try:
            AddressPage().select_edit_city_id().click()
        except Exception:
            assert False, "未能成功选择地址_省"
        time.sleep(2)
        #选择地址_区
        mylogger.debug("选择地址_区")
        try:
            AddressPage().select_edit_county_id().click()
        except Exception:
            assert False, "未能成功选择地址_区"
        time.sleep(2)
        #清空详细地址原有内容
        mylogger.debug("清空详细地址原有内容")
        try:
            AddressPage().input_edit_detailaddress_id().clear()
        except Exception:
            assert False, "未能成功清空详细地址原有内容"
        #编辑详细地址
        mylogger.debug("编辑详细地址")
        try:
            edit_address = ReadExcelData().returnExcelData(
                'data.xlsx', 'address', 1, 1)
            AddressPage().input_edit_detailaddress_id().send_keys(edit_address)
        except Exception:
            assert False, "未能成功编辑详细地址"
        self.driver.implicitly_wait(5)
        #清空手机号原有内容
        mylogger.debug("清空手机号原有内容")
        try:
            AddressPage().input_edit_mobile_id().clear()
        except Exception:
            assert False, "未能成功清空手机号原有内容"
        #编辑手机号
        mylogger.debug("编辑手机号")
        try:
            edit_mobile = ReadExcelData().returnExcelData(
                'data.xlsx', 'address', 2, 1)
            AddressPage().input_edit_mobile_id().send_keys(str(edit_mobile))
        except Exception:
            assert False, "未能成功编辑手机号"
        time.sleep(5)
        #截屏
        CommonDef().get_windows_img()
        #点击保存收货地址
        mylogger.debug("点击保存收货地址")
        # JavascriptExecutor executor = (JavascriptExecutor) driver;
        # executor.executeScript("arguments[0].click();",AddressPage().click_edit_button());
        try:
            AddressPage().click_edit_button().click()
        except Exception:
            assert False, "未能成功点击确认修改按钮"
        time.sleep(2)
        #截屏
        CommonDef().get_windows_img()
        time.sleep(2)


#新增收货地址

    def test02(self):
        mysql_host = ReadExcelData().returnExcelData('data.xlsx', 'mysql', 0,
                                                     1)
        mysql_user = ReadExcelData().returnExcelData('data.xlsx', 'mysql', 1,
                                                     1)
        mysql_password = ReadExcelData().returnExcelData(
            'data.xlsx', 'mysql', 2, 1)
        mysql_port = ReadExcelData().returnExcelData('data.xlsx', 'mysql', 3,
                                                     1)
        mysql_database = ReadExcelData().returnExcelData(
            'data.xlsx', 'mysql', 4, 1)
        _sql1 = ReadExcelData().returnExcelData('data.xlsx', 'mysql', 6, 1)
        _sql2 = ReadExcelData().returnExcelData('data.xlsx', 'mysql', 7, 1)
        count = MysqlConnection().count_mysql(mysql_host, int(mysql_port),
                                              mysql_user, mysql_password,
                                              mysql_database, "utf8", _sql1)
        print count[0]
        time.sleep(3)
        if count[0] == 10:
            MysqlConnection().del_mysql(mysql_host, int(mysql_port),
                                        mysql_user, mysql_password,
                                        mysql_database, "utf8", _sql2)
        else:
            pass
        time.sleep(3)
        count = MysqlConnection().count_mysql(mysql_host, int(mysql_port),
                                              mysql_user, mysql_password,
                                              mysql_database, "utf8", _sql1)
        print count[0]
        mylogger.debug("开始新增地址")
        #点击新增
        AddressPage().click_add_address_class().click()
        time.sleep(3)
        #输入收货人
        add_name = ReadExcelData().returnExcelData('data.xlsx', 'address', 3,
                                                   1)
        AddressPage().click_add_name().send_keys(add_name)
        self.driver.implicitly_wait(5)
        mylogger.debug("输入收货人")
        #选择省
        AddressPage().click_add_province().click()
        time.sleep(2)
        mylogger.debug("选择省")
        #选择市
        AddressPage().click_add_city().click()
        time.sleep(2)
        mylogger.debug("选择市")
        #选择区
        AddressPage().click_add_county().click()
        time.sleep(2)
        mylogger.debug("选择区")
        #S输入详细地址
        add_address = ReadExcelData().returnExcelData('data.xlsx', 'address',
                                                      4, 1)
        AddressPage().click_add_detailaddress().send_keys(add_address)
        self.driver.implicitly_wait(5)
        mylogger.debug("输入详细地址")
        #输入手机号
        add_mobile = ReadExcelData().returnExcelData('data.xlsx', 'address', 5,
                                                     1)
        AddressPage().click_add_mobile().send_keys(str(add_mobile))
        self.driver.implicitly_wait(5)
        self.driver.implicitly_wait(5)
        mylogger.debug("输入手机号")
        #点击提交按钮
        AddressPage().click_add_button().click()
        self.driver.implicitly_wait(5)
        mylogger.debug("点击提交按钮")
        #截屏
        CommonDef().get_windows_img()
        # CreateConnectionMysql().connection_mysql(mysql_host,int(mysql_port),mysql_user,mysql_password,mysql_database,"utf8")
        # CreateConnectionMysql().cureors() #数据库游标
        _sql = ReadExcelData().returnExcelData('data.xlsx', 'mysql', 5, 1)
        MysqlConnection().connection_mysql(mysql_host, int(mysql_port),
                                           mysql_user, mysql_password,
                                           mysql_database, "utf8", _sql)
示例#12
0
 def setUp(self):
     self.driver = GetSeleniumDriver().driver
     CommonDef().login(u"http://pftest.ecgci.com/index.html", u"test0135",
                       u"aaaaaa")
示例#13
0
class OrderSubmit(unittest.TestCase):
    # #继承unnittest初始化方法
    # @classmethod
    # def setUpClass(cls):
    #     cls.driver = GetSeleniumDriver().driver
    #     cls.driver.get("http://pftest.ecgci.com/index.html")
    #     time.sleep(1)
    #     cls.driver.maximize_window()
    #     time.sleep(1)
    #     #点击请登录
    #     IndexPage().click_login_link().click()
    #     time.sleep(1)
    #     #输入用户名
    #     LoginPage().click_username().send_keys(u"test0135")
    #     time.sleep(1)
    #     #输入密码
    #     LoginPage().click_password().send_keys("aaaaaa")
    #     time.sleep(3)
    #     #点击登录按钮
    #     LoginPage().click_login_submit().click()
    #     time.sleep(3)
    #
    # @classmethod
    # def tearDownClass(cls):
    #     cls.driver.quit()
    #继承unnittest初始化方法
    def setUp(self):
        self.driver = GetSeleniumDriver().driver
        self.driver.get("http://pftest.ecgci.com/index.html")
        time.sleep(1)
        self.driver.maximize_window()
        time.sleep(1)
        #点击请登录
        IndexPage().click_login_link().click()
        time.sleep(1)
        #输入用户名
        LoginPage().click_username().send_keys(u"test0135")
        time.sleep(1)
        #输入密码
        LoginPage().click_password().send_keys("aaaaaa")
        time.sleep(3)
        #点击登录按钮
        LoginPage().click_login_submit().click()
        time.sleep(3)

    def tearDown(self):
        self.driver.quit()

    def test_order_submit(self):
        #下滑滚动条
        #for i in (0,28):
        action = ActionChains(self.driver).move_to_element(
            self.driver.find_element_by_id("keyval"))
        action.send_keys(Keys.ARROW_DOWN)  #点击键盘向下箭头
        time.sleep(3)
        #获取当前窗口句柄
        nowhandle = self.driver.current_window_handle
        #点击纪念币楼层第一行第4个商品
        IndexPage().click_goods14_link().click()
        time.sleep(3)
        #获取所有handle
        allhandles = self.driver.window_handles
        #循环,当句柄不等于首页句柄时,转换为现在的窗口句柄
        for handle in allhandles:
            if handle != nowhandle:
                self.driver.switch_to_window(handle)
        #点击立即购买
        GoodsDetail().click_buy_id().click()
        time.sleep(1)
        #滑动滚动条
        CommonDef().huadong_gundongtiao()
        #点击提交订单
        OrderSubmitPage().click_order_submit().click()
        time.sleep(1)
示例#14
0
 def __init__(self):
     self.driver=GetSeleniumDriver().driver
示例#15
0
class AddressPage(object):
    def __init__(self):
        self.driver = GetSeleniumDriver().driver

    ############################################# 编辑收货地址框 #######################################################
    #点击编辑
    def click_edit_address(self):
        click_edit_address = self.driver.find_element_by_link_text(
            RES.edit_address_link)
        return click_edit_address

    #编辑收货人
    def input_edit_name_id(self):
        input_edit_name_id = self.driver.find_element_by_id(RES.edit_name_id)
        return input_edit_name_id

    #编辑省
    def select_edit_province_id(self):
        select_edit_province_id = self.driver.find_element_by_id(
            RES.edit_province_id).find_element_by_xpath(
                "//option[@value='002004']")
        return select_edit_province_id

    #选择市
    def select_edit_city_id(self):
        select_edit_city_id = self.driver.find_element_by_id(
            RES.edit_city_id).find_element_by_xpath(
                "//option[@value='002004002']")
        return select_edit_city_id

    #选择区
    def select_edit_county_id(self):
        select_edit_county_id = self.driver.find_element_by_id(
            RES.edit_county_id).find_element_by_xpath(
                "//option[@value='002004002008']")
        return select_edit_county_id

    #定位详细地址
    def input_edit_detailaddress_id(self):
        input_edit_detailaddress_id = self.driver.find_element_by_id(
            RES.edit_detailaddress_id)
        return input_edit_detailaddress_id

    def input_edit_mobile_id(self):
        input_edit_mobile_id = self.driver.find_element_by_id(
            RES.edit_mobile_id)
        return input_edit_mobile_id

    #定位手机号
    def click_edit_button(self):
        #click_edit_button=self.driver.find_element_by_xpath("//*[@id='viewAddress1']/td/table/tbody/tr[9]/td[2]/input")
        #click_edit_button=self.driver.find_element_by_xpath("/html/body/div[10]/div/form/div/div[2]/table/tbody").find_element_by_xpath(RES.edit_button_xpath)
        #click_edit_button=self.driver.find_element_by_xpath("/html/body/div[10]/div/form/div/div[2]/table/tbody/tr/td/table/tbody/tr[9]/td[2]/input")
        #click_edit_button=self.driver.find_element_by_id("viewAddress1").find_element_by_css_selector("[onclick='memberAddressSave('1','2');']")
        click_edit_button = self.driver.find_element_by_link(
            RES.edit_button_link)
        return click_edit_button

    ############################################# 新增收货地址框 #######################################################
    def click_add_address_class(self):
        click_add_address = self.driver.find_element_by_class_name(
            RES.add_address_class)
        return click_add_address

    def click_add_address(self):
        click_add_address = self.driver.find_element_by_class_name(
            RES.add_address_class)
        return click_add_address

    def click_add_name(self):
        click_add_name = self.driver.find_element_by_id(RES.add_name_id)
        return click_add_name

    def click_add_province(self):
        click_add_province = self.driver.find_element_by_id(
            RES.add_province_id).find_element_by_xpath(
                "//option[@value='002004']")
        return click_add_province

    def click_add_city(self):
        click_add_city = self.driver.find_element_by_id(
            RES.add_city_id).find_element_by_xpath(
                "//option[@value='002004002']")
        return click_add_city

    def click_add_county(self):
        click_add_county = self.driver.find_element_by_id(
            RES.add_county_id).find_element_by_xpath(
                "//option[@value='002004002008']")
        return click_add_county

    def click_add_detailaddress(self):
        click_add_detailaddress = self.driver.find_element_by_id(
            RES.add_detailaddress_id)
        return click_add_detailaddress

    def click_add_mobile(self):
        click_add_mobile = self.driver.find_element_by_id(RES.add_mobile_id)
        return click_add_mobile

    def click_add_button(self):
        click_add_button = self.driver.find_element_by_id(RES.add_button_id)
        return click_add_button