示例#1
0
class Test_Business(unittest.TestCase):
    '''业务-线路产品管理测试类'''
    def setUp(self):
        self.k, self.user = acquire_user("TestData/user.txt")
        self.driver = SeleniumBase().get_web_driver()

    def tearDown(self):
        release_user(self.k)
        SeleniumBase(self.driver).quit()

    @ddt.unpack
    @ddt.data(*read_txt('TestData/lines_type.txt'))
    def test_add_line_type(self, name, ename, tag_name):
        '''添加线路类别'''
        try:
            username, password = self.user
            se = SeleniumBase(self.driver)
            se.get(url)
            login(self.driver, username, password)
            index = Index_Page(self.driver)
            index.click_business()
            Business = BusinessPage(self.driver)
            Business.click_lines()
            line_type = Lines_Type(self.driver)
            line_type.click_line_type()
            self.driver.switch_to.frame(0)
            self.driver.switch_to.frame(0)
            line_type.click_add_lines()
            se.add_page_screen_shot()
            line_type.add_lines_type_msg(name, ename, tag_name)
            se.add_page_screen_shot()
        except Exception:
            raise ("添加线路类别异常")

    @ddt.unpack
    @ddt.data(*read_txt('TestData/add_trip.txt'))
    def test_add_trip(self, trip, dinner, hotel, traffic, travel):
        '''添加线路行程'''
        try:
            username, password = self.user
            se = SeleniumBase(self.driver)
            se.get(url)
            login(self.driver, username, password)
            index = Index_Page(self.driver)
            index.click_business()
            Business = BusinessPage(self.driver)
            Business.click_lines()
            Journey = Journey_Page(self.driver)
            Journey.click_journey()
            se.add_page_screen_shot()
            self.driver.switch_to.frame(0)
            self.driver.switch_to.frame(0)
            Journey.add_journey(trip, dinner, hotel, traffic, travel)
            se.add_page_screen_shot()
        except Exception:
            raise ('添加线路行程异常')
示例#2
0
class Test_Itinerary_Test(unittest.TestCase):
    '''添加机票行程'''

    def setUp(self):
        self.k, self.user = acquire_user('TestData/user.txt')
        self.driver = SeleniumBase().get_web_driver()

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

    @ddt.unpack
    @ddt.data(*read_txt('TestData/itinerary.txt'))
    def test_add_itinerary(self, itinerary_name, routes, itinerary_day, remark1):
        try:
            username, password = self.user
            se = SeleniumBase(self.driver)
            se.get(url_index)
            login(self.driver, username, password)
            index = Index_Page(self.driver)
            index.click_business()
            Business = BusinessPage(self.driver)
            Business.click_air_ticket()

            Flight = Flight_Mana_Page(self.driver)
            Flight.air_mana()
            self.driver.switch_to.frame(0)
            self.driver.switch_to.frame(0)
            Flight.click_itinerary()
            Flight.add_itnerary(itinerary_name, routes, itinerary_day, remark1)
        except Exception:
            raise ("测试出现异常")
示例#3
0
def acquire_user(file):
    """
    获取用户信息
    :param file:
    :return:
    """
    _get_user_s.acquire()
    try:
        #region 如果文件为空则读取文件
        if len(user_data) == 0:
            count = 0
            for line in read_txt(file):
                user_data[count] = {"user": line, "tag": True}
                count += 1
            if len(user_data) == 0:
                raise ValueError(f"文件{file}\t无数据")
        # endregion
        # region 修改获取的状态,确保每次获取的是可用用户,如果不可用则等待
        for i in range(1800):
            for k, v in user_data.items():
                if v.get("tag"):
                    user = v.get("user")
                    user_data[k]['tag'] = False
                    return k, user
            time.sleep(2)
        raise TimeoutError("等待用户释放超时:3600s")
        # endregion
    except Exception:
        raise
    finally:
        #不管读取文件是否错误都需要释放
        _get_user_s.release()
示例#4
0
class Test_login(unittest.TestCase):
    def setUp(self):
        self.driver = SeleniumBase().get_web_driver()

    def tearDown(self):

        SeleniumBase(self.driver).quit()

    @ddt.unpack
    @ddt.data(*read_txt('TestData/login_user_password.txt'))
    def test_login(self, username, password, assert_type):
        se = SeleniumBase(self.driver)
        se.get(url_index)
        login(self.driver, username, password)
        se.add_page_screen_shot()

        if assert_type == '1':
            logger().info("断言登陆成功")
            text = Index_Page(self.driver).login_success()

            self.assertIn("张维序", text, '登陆成功断言')

        elif assert_type == "2":
            text = self.driver.find_element_by_id("submit").text
            self.assertIn("立即登录", text, '登陆失败断言')

        elif assert_type == "3":
            text = self.driver.find_element_by_id("submit").text
            self.assertIn("立即登录", text, '登陆失败断言')

        elif assert_type == "4":
            text = self.driver.find_element_by_id("submit").text
            self.assertIn("立即登录", text, '登陆失败断言')

        else:
            logger().info(f"未知断言类型{assert_type}")
            self.assertTrue(False, "未知断言类型")