def devices_start(devices):
    logger = my_log()
    desired = get_desired(devices)
    if appium_start(desired["host"], int(desired["port"])):
        _desired_caps = {
            "platformName": desired["platformName"],
            "platformVersion": desired["platformVersion"],
            "deviceName": desired["deviceName"],
            "appPackage": desired["appPackage"],
            "appActivity": desired["appActivity"],
            "unicodeKeyboard": desired["unicodeKeyboard"],
            "resetKeyboard": desired["resetKeyboard"],
            "noReset": desired["noReset"]
        }
        try:
            logger.info("appium port : {} start run {} at {} ".format(
                desired["port"], desired["deviceName"],
                strftime("%Y-%m-%d %H:%M:%S")))
            driver = webdriver.Remote(
                "http://" + desired["host"] + ":" + desired["port"] +
                "/wd/hub", _desired_caps)
            driver.implicitly_wait(8)
            logger.info("====== start run app : {}======".format(
                desired["deviceName"]))
            return driver
        except:
            logger.error("appium port : {} start Failed {} at {} ".format(
                desired["port"], desired["deviceName"],
                strftime("%Y-%m-%d %H:%M:%S")))
def appium_start(host, port):
    logger = my_log()
    # if True:
    if check_stats(host, port):  # 注释掉,不会每次都重启appium
        """启动appium命令"""
        bootstrap_port = str(port + 1)
        cmd = "start /b appium -a " + host + " -p " + str(port) + " -bp " + str(bootstrap_port)
        logger.info("{} at {}".format(cmd, strftime("%Y-%m-%d %H:%M:%S")))
        subprocess.Popen(cmd, shell=True, stdout=open("./appium_log/" + str(port) + ".log", "a"),
                         stderr=subprocess.STDOUT)
def check_port(host, port):
    """检查指定端口是否被占用"""
    logger = my_log()
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    try:
        sock.connect((host, port))
        sock.shutdown(2)
    except OSError as msg:
        logger.info("port %s is Availible!" % port)
        # print(msg)
        return True
    else:
        logger.info("port %s is Used!" % port)
        return False
class StartEnd(unittest.TestCase):
    logger = my_log()

    # @staticmethod
    # def setUpClass(cls):
    #     cls.logger.info("====== setUpClass ======")
    #     pass

    def setUp(self):
        self.logger.info("====== setUp ======")
        self.driver = devices_start()

    def tearDown(self):
        self.logger.info("====== tearDown ======")
        sleep(8)
        self.driver.close_app()
Esempio n. 5
0
def appium_start(host, port):
    logger = my_log()
    if check_stats(host, port):  # 注释掉,不会每次都重启appium
        bootstrap_port = str(port + 1)
        # 启动多个appium服务时,不要安装客户端
        # npm install -g cnpm --registry=https://registry.npm.taobao.org
        # cnpm install -g appium
        cmd = "start /b appium -a " + host + " -p " + str(
            port) + " -bp " + str(bootstrap_port)
        # 说明:/b 不打开命令窗口; bp端口( --bootstrap-port)是appium和设备之间通信的端口,如果不指定到时无法操作多台设备运行脚本。
        logger.info("{} at {}".format(cmd, strftime("%Y-%m-%d %H:%M:%S")))
        subprocess.Popen(cmd,
                         shell=True,
                         stdout=open("./appium_log/" + str(port) + ".log",
                                     "a"),
                         stderr=subprocess.STDOUT)
        return True
Esempio n. 6
0
class LoginView(Common):
    logger = my_log()
    username_type = (By.ID, "com.jiandan.mobilelesson:id/account_et")
    password_type = (By.ID, "com.jiandan.mobilelesson:id/password_et")
    login_btn = (By.ID, "com.jiandan.mobilelesson:id/login_btn")

    def login_action(self, username, password):
        self.is_upgrade()
        self.get_screen_shot("login")

        self.logger.info("login username: %s" % username)
        self.driver.base_find_element(*self.username_type).send_keys(username)
        self.logger.info("login password: %s" % password)
        self.driver.base_find_element(*self.password_type).send_keys(password)
        self.driver.base_find_element(*self.login_btn).click()
        sleep(5)
        self.swipe_up()
def release_port(port):
    """释放指定的端口"""
    logger = my_log()
    # 查找对应的端口
    cmf_find = "netstat -ano | findstr %s" % port
    # 返回执行后的结果
    result = os.popen(cmf_find).read()
    # print(result)
    # 获取端口对应的pid
    if str(port) and "LISTENING" in result:
        str_list = result.split()
        pid = str_list[4]
        # 关闭被占用端口的pid
        cmd_kill = "taskkill -f -pid %s" % pid
        os.popen(cmd_kill)
        logger.info("port %s is release Success!" % port)
        return True
    else:
        logger.info("port %s is release Failed!" % port)
        return False
Esempio n. 8
0
class TestLogin(StartEnd):
    logger = my_log()
    csv_file = "../data/loginUser.csv"

    def test_login_https005(self):
        """登录测试"""
        test1 = LoginView(self.driver)
        data = test1.get_csv_data(self.csv_file, 1)
        test1.login_action(data)

    def test_login_https006(self):
        """登录测试"""
        test1 = LoginView(self.driver)
        data = test1.get_csv_data(self.csv_file, 2)
        test1.login_action(data)

    @unittest.skip("test_login_https007")  # 跳过
    def test_login_https007(self):
        """登录测试"""
        test1 = LoginView(self.driver)
        data = test1.get_csv_data(self.csv_file, 3)
        test1.login_action(data)
Esempio n. 9
0
class Common(BaseDriver):
    logger = my_log()

    @staticmethod
    def now_data():
        now = time.strftime("%Y-%m-%d %H_%M_%S")
        return now

    # 截图
    def get_screen_shot(self, moudle):
        self.logger.info("get_screen_shot")
        times = self.now_data()
        image_file = os.path.dirname(os.path.dirname(
            __file__)) + "../../logs/screenShots/%s_%s.png" % (moudle, times)
        self.driver.get_screenshot_as_file(image_file)

    def get_window(self):
        x = self.get_win_size()["width"]
        y = self.get_win_size()["height"]
        z = (x, y)
        return z

    # 向上滑动
    def swipe_up(self):
        self.logger.info("swipe_up")
        s = self.get_window()
        x1 = int(s[0] * 0.5)
        y1 = int(s[1] * 0.8)
        y2 = int(s[1] * 0.2)
        self.swipes(x1, y1, x1, y2, 1000)

    # 获取参数
    def get_csv_data(file_name, line):
        with open(file_name, "r", encoding="utf-8-sig") as file:
            read = csv.reader(file)
            for index, row in enumerate(read):
                if index == line:
                    return row