Exemplo n.º 1
0
def exec_script(driver,testpage,teststep,testdata):
    # 定义测试用例执行函数状态标志位
    exec_script = True
    try:
        # 登录功能测试
        if testpage == "登录":
            url = driver.current_url
            url = GetUrl(url)+'login'
            if driver.current_url != url:
                driver.get(url)
            login = LoginPage(driver,testdata)
            if teststep == '用户名':
                login.input_username(testdata)
            if teststep == '密码':
                login.input_password(testdata)
            if teststep == '登录':
                login.click_submit()
                time.sleep(5)
        if testpage == "主页":
            time.sleep(3)
            url = driver.current_url
            major = MainPage(driver,url)
            if teststep == '退出':
                userid = major.show_userid()
                major.exit_sys(driver)
                time.sleep(3)
        if testpage == "其他主页":
            pass
    except:
        exec_script =False
        url = GetUrl(driver.current_url)
        driver.get(url)
    return exec_script
Exemplo n.º 2
0
def exec_script(driver, testpage, teststep, testdata):
    #定义测试用例执行函数状态标志位
    exec_script = True
    try:
        #登陆功能测试
        if testpage == '登录':
            url = driver.current_url
            url = geturl(url) + 'user.php'
            if driver.current_url != url:
                driver.get(url)
            login = LoginPage(driver, testdata)
            if teststep == '用户名':
                login.input_username(testdata)

            if teststep == '密码':
                login.input_password(testdata)

            if teststep == '登录':
                login.click_submit()
                time.sleep(5)

        #注册功能测试
        if testpage == '注册':
            url = driver.current_url
            url = geturl(url) + 'user.php?act=register'
            if driver.current_url != url:
                driver.get(url)
            userreg = RegistePage(driver, testdata)
            if teststep == '用户名':
                userreg.input_username(testdata)

            if teststep == 'email':
                userreg.input_email(testdata)

            if teststep == '密码':
                userreg.input_password(testdata)

            if teststep == '确认密码':
                userreg.input_comfirpwd(testdata)

                time.sleep(8)
            if teststep == '注册':
                userreg.click_submit()
                time.sleep(5)

        if testpage == '主页':
            time.sleep(3)
            url = driver.current_url
            mainpage = MainPage(driver, url)
            if teststep == '退出':
                mainpage.exit_sys()
                time.sleep(3)
        if testpage == '其他主页':
            pass
    except:
        exec_script = False
        url = geturl(driver.current_url)
        driver.get(url)
    return exec_script
def test_login():

    driver = webdriver.Chrome()
    # driver.get("https://opensource-demo.orangehrmlive.com/")

    login_page = LoginPage(driver)
    login_page.open_page(url="https://opensource-demo.orangehrmlive.com/")
    login_page.input_username(username="******")
    login_page.input_password(password="******")
    login_page.click_login_btn()
Exemplo n.º 4
0
def execStep(driver, testpage, teststep, testdata, testmsg, mylog):

    exec_step = True
    try:
        if testpage == 'login':
            # url = driver.current_url
            # url = getUrl(url) + '/require_login'
            # if driver.current_url != url:
            #     driver.get(url)

            userlogin = LoginPage(driver)
            if teststep == 'username':
                userlogin.input_username(mylog, testdata)
            if teststep == 'password':
                userlogin.input_password(mylog, testdata)
            if teststep == 'login':
                userlogin.submit_click(mylog)
                time.sleep(3)

                if driver.current_url == testdata:
                    assert (userlogin.show_errormessage(mylog) == testmsg)

                    url = getUrl(driver.current_url)
                    mylog.info("current url %s" % url)
                    driver.get(url)

                    # userlogin.go_to_indexpage(mylog)
                    # time.sleep(3)
                    # indexpage = IndexPage(driver)
                    # indexpage.go_to_login(mylog)

                time.sleep(1)

        if testpage == 'login_success':
            mylog.info("now in login_success page")
            mainpage = MainPage(driver)
            if teststep == 'logout':

                assert (mainpage.show_usermessage(mylog)).startswith(testdata)
                mainpage.logout_from_login(mylog)
                assert driver.title == "login"
                mylog.info("current page has title %s" % driver.title)
                time.sleep(3)
######################################################################################################
        if testpage == 'register':
            # url=driver.current_url
            # url=getUrl(url) + '/require_register'
            # if driver.current_url != url:
            #     driver.get(url)

            userreg = RegisterPage(driver)
            if teststep == 'username':
                userreg.input_username(mylog, testdata)
            if teststep == 'email':
                userreg.input_email(mylog, testdata)
            if teststep == 'password':
                userreg.input_password(mylog, testdata)
            if teststep == 'confirmation':
                userreg.input_password2(mylog, testdata)
            if teststep == 'register':
                userreg.submit_click(mylog)
                time.sleep(3)

                if driver.current_url == testdata:
                    assert (userreg.show_errormessage(mylog) == testmsg)

                    url = getUrl(driver.current_url)
                    mylog.info("current url %s" % url)
                    driver.get(url)

                    # userreg.go_to_indexpage(mylog)
                    # time.sleep(3)
                    # indexpage = IndexPage(driver)
                    # indexpage.go_to_register(mylog)

                time.sleep(1)

        if testpage == 'register_success':
            mylog.info("now in register_success page")
            #url=driver.current_url

            mainpage = MainPage(driver)
            if teststep == 'home':
                assert (mainpage.show_usermessage(mylog)).startswith(testdata)
                mainpage.go_to_indexpage(mylog)
                assert driver.title == "myuser"

                mylog.info("in index page to click register button")
                indexpage = IndexPage(driver)
                indexpage.go_to_register(mylog)
                # mylog.info("go to index page to click register button")
                #     indexpage=IndexPage(driver)
                #     if teststep == 'register':
                #         indexpage.go_to_register(mylog)
                #         assert driver.title == "index"
                #         mylog.info("current page has title %s" % driver.title)
                #         time.sleep(3)
                mylog.info("current page has title %s" % driver.title)
                time.sleep(3)
                result = removeUser(
                    testdata)  # cleanup for signup related test cases
                mylog.info("remove ")

        # if testpage == 'index':
        #     mylog.info("go to index page to click register button")
        #     indexpage=IndexPage(driver)
        #     if teststep == 'register':
        #         indexpage.go_to_register(mylog)
        #         assert driver.title == "index"
        #         mylog.info("current page has title %s" % driver.title)
        #         time.sleep(3)

        if testpage == 'other page':
            pass

    except:
        exec_step = False
        cappic(driver)
        url = getUrl(driver.current_url)
        mylog.info("current url %s" % url)
        driver.get(url)

    return exec_step