• import time

    from selenium import webdriver
    from selenium.common.exceptions import NoSuchElementException, NoAlertPresentException
    from selenium.webdriver.common.keys import Keys
    import pytest


    class Testselenumdemo:
    chromepath = '/Users/chenxue/project/chromedriver/chromedriver'
    driver: webdriver

    @classmethod
    def setup_class(cls):
    cls.driver = webdriver.Chrome(executable_path=cls.chromepath)
    cls.driver.implicitly_wait(10)

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

    def test_demo(self):
    self.driver.get("https://xueqiu.com")
    self.driver.find_element_by_name("q").send_keys("阿里巴巴")
    self.driver.find_element_by_xpath("//*[text()[contains(.,'01688')]]").click()

    # 切换到当前tab,避免无法定位添加按钮
    tabs = self.driver.window_handles
    self.driver.switch_to.window(tabs[-1])

    # self.driver.find_element_by_xpath("//*[text()[contains(.,'自选')]]").click()
    self.driver.find_element_by_css_selector(".follow").click()
    self.driver.find_element_by_name("username").send_keys("15300000000")
    self.driver.find_element_by_name("password").send_keys("123456")
    self.driver.find_element_by_css_selector(".modal__login__btn").click()
    time.sleep(5)

  • import time
    import pytest
    from appium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.wait import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC


    class TestDanjuan(object):
    caps = {}
    caps["platformName"] = "android"
    caps["deviceName"] = "emulator-5554"
    caps["appPackage"] = "com.xueqiu.android"
    caps["appActivity"] = ".view.WelcomeActivityAlias"
    caps["autoGrantPermissions"] = True
    caps["unicodeKeyboard"] = True
    caps["resetKeyboard"] = True

    driver: webdriver
    _jiaoyibutton = (
    By.XPATH,
    "//*[contains(@resource-id, 'tab_name') and @text='交易']")

    @classmethod
    def setup_class(cls):
    cls.driver = webdriver.Remote("http://localhost:4723/wd/hub", cls.caps)

    # 隐式等待
    cls.driver.implicitly_wait(10)

    # 显示等待
    WebDriverWait(cls.driver, 20).until(EC.presence_of_element_located(cls._jiaoyibutton))
    cls.driver.find_element(*cls._jiaoyibutton).click()

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

    def test_logincase1(self):
    self.driver.find_element_by_accessibility_id("基金开户").click()
    self.driver.find_element_by_accessibility_id("已有蛋卷基金账户登录").click()
    self.driver.find_element_by_accessibility_id("使用密码登录").click()

    # 切换上下文
    print(self.driver.contexts)
    print(self.driver.current_context)
    self.driver.switch_to.context(
    self.driver.contexts[-1])

    self.driver.find_element_by_id("telno").send_keys("15302462430")
    self.driver.find_element_by_id("pass").send_keys("123456")
    self.driver.find_element_by_accessibility_id("安全登录").click()

  • from appium import webdriver
    from appium.webdriver import webelement
    from appium.webdriver.common.touch_action import TouchAction
    import time


    caps = {}
    caps["platformName"] = "android"
    caps["deviceName"] = "emulator-5554"
    caps["appPackage"] = "com.xueqiu.android"
    caps["appActivity"] = ".view.WelcomeActivityAlias"
    caps["autoGrantPermissions"] = True
    caps["unicodeKeyboard"] = True
    caps["resetKeyboard"] = True

    driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)

    # 隐式等待
    driver.implicitly_wait(10)

    x = driver.get_window_size()['width']
    y = driver.get_window_size()['height']


    def swipe_5_times():
    for i in range(3):
    TouchAction(driver).press(x=x * 0.5, y=y * 0.8).move_to(x=x * 0.5, y=y * 0.4).release().perform()
    time.sleep(2)


    targetele = driver.find_element_by_xpath("//*[contains(@resource-id, 'indicator')]/android.widget.LinearLayout//*[@text='基金']")
    targetele.click()

    while True:
    time.sleep(1)
    beforeele = driver.find_element_by_xpath("//*[contains(@resource-id, 'indicator')]//android.widget.RelativeLayout[count(*)>1]/android.widget.TextView")
    text1 = beforeele.text
    swipe_5_times()
    TouchAction(driver).press(x=x * 0.9, y=y * 0.5).move_to(x=x * 0.1, y=y * 0.5).release().perform()
    time.sleep(1)

    afterele = driver.find_element_by_xpath("//*[contains(@resource-id, 'indicator')]//android.widget.RelativeLayout[count(*)>1]/android.widget.TextView")

    text2 = afterele.text

    if text1 != text2:
    continue
    else:
    break

    driver.quit()

  • # 作业1
    //*[@resource-id='com.xueqiu.android:id/indicator']//*[@text='基金']
  • #!/usr/bin/env python
    # encoding: utf-8


    # This sample code uses the Appium python client
    # pip install Appium-Python-Client
    # Then you can paste this into a file and simply run with Python

    from appium import webdriver

    caps = {}
    caps["platformName"] = "android"
    caps["deviceName"] = "hogwarts"
    caps["appPackage"] = "com.xueqiu.android"
    caps["appActivity"] = ".view.WelcomeActivityAlias"
    caps["autoGrantPermissions"] = True
    caps["unicodeKeyboard"] = True
    caps["resetKeyboard"] = True

    driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)

    # 隐式等待
    driver.implicitly_wait(10)

    driver.find_element_by_id("com.xueqiu.android:id/quick_action").click()
    driver.find_element_by_id("com.xueqiu.android:id/item_add_stock").click()
    driver.find_element_by_id("com.xueqiu.android:id/search_input_text").send_keys("alibaba")
    driver.find_elements_by_id("com.xueqiu.android:id/follow_btn")[0].click()

    driver.quit()
  • 占楼补作业

    # 作业1
    class Server:
    def __init__(self, cpu_num, mem_size, disk_size, os_type):
    self.cpu_num = cpu_num
    self.mem_size = mem_size
    self.disk_size = disk_size
    self.__os_type = os_type

    def get_configuration( self ):
    return "{cpu_num}核CPU, {mem_size}G内存, {disk_size}G磁盘空间, {os_type}".format(cpu_num=self.cpu_num, mem_size=self.mem_size, disk_size=self.disk_size, os_type=self.__os_type)


    server1 = Server(8, 40, 150, "Linux")
    print(server1.get_configuration())

    class Computer(Server):
    def total( self ):
    total = self.cpu_num * 1527.679 + self.mem_size * 100.21 + self.disk_size * 50.789
    return round(total, 2)


    computer1 = Computer(8, 40, 150, "Linux")
    print(computer1.total())


    # 作业3
    #!/usr/bin/env python
    # encoding: utf-8
    import pytest
    from testerhome.pytest_demo.sortdemo import bubble_sort


    @pytest.mark.parametrize("x,y", [
    ([2, 6, 1, 4, 9, 3], [1, 2, 3, 4, 6, 9]),
    ([11, 14, 15, 12, 16, 13], [11, 12, 13, 14, 15, 16]),
    ([-1, 0, 2, -2, 1], [-2, -1, 0, 1, 2])
    ])
    def test_sort1(x, y):
    assert bubble_sort(x) == y

  • 占位补作业

    课后作业:

    利用pip, 安装第三方模块requests, 描述你用什么方法来确认安装是成功的。

    import requests

    把2.918 转化为整形

    int(2.918)

    把10 进制数 18 转化为2进制数

    bin(18)

    用java 替换字符串:”Python is popular” 里面的Python,并 把java 变换成JAVA

    print("Python is popular".replace("Python","java".upper()))

    把列表 [1, 2, 3,4 5,6,7,8]里面的2, 4, 6,8 打印出来

    print([x for x in [1, 2, 3, 4, 5, 6, 7, 8] if x%2==0])

    创建一个字典,字典的key分别是name, sex, province , 修改原始province 的值 为新值”江苏”

    dict1 = {"name": "test", "sex": "male", "province": "tmp"}
    dict1['provice']="上海"

    Test_str=“Python was created in 1989, Python is using in AI, big data, IOT.” 按下列要求对上面文字做出处理。

    • 把上面文字中的所有大写转化为小写

    Test_str.lower()

    • 把这段话每个单词放到列表里面,不能包含空格。

    print(Test_str.split())

    • 把列表最中间的一个单词打印出来。

    test = Test_str.split()
    print(test[int(len(test)/2)])

    2.List1=[“python”, 5,6, 8], list2=[“python”,”5”, 6, 8,10], 对list1和list2做出如下处理:

    • 把上面2个list的内容合并成一个

    print(List1+list2)

    • 利用set里面的方法,对合并后的list, 去除重复元素。最 后输出是还是list =“python”, 5,6, 8,”5”,10

    print(set(List1+list2))

    实现一个函数,要求对一个列表里面所有数字求和,如果里 面含有非数字的元素。直接跳过。比如[1,2,3] 输出是5, 如果 是[1,2,4,”a”] 输出是7。 并在另外一个包(目录)里面调用这个 函数

    def addvalue(list1):
    list_value = [x for x in list1 if isinstance(x, int)]
    return sum(list_value)

    实现一个不定长参数的函数def flexible(aa, *args, **kwargs):,
    把传入的参数和值打印出来。比如传入参数是

    flexible(aa, 2, 3, x = 4, y = 5, [1, 2, 3], *{'a':1,'b': 2})
    输出结果:(2, 3, 1, 2, 3),{'a': 1, 'y': 5, 'b': 2, 'x': 4}
    面试题:*args, **kwargs 有什么作用

    def flexible(aa, *args, **kwargs):
    print(args, kwargs)

    *args: 以元组的形式传参
    **kwargs: 以字典的形式传参

  • 忽略。。

  • 占位补作业

    课后练习

    10001这个员工工作了多少年?

    select count(salary) from employees.salaries where emp_no = '10001';

    这些年赚了多少钱?

    select sum(salary) from employees.salaries where emp_no = '10001';

    平均每年多少呢?保留小数点后两位。

    select sum(salary) from employees.salaries where emp_no = '10001';

    最多一年和最少一年赚多少?

    select max(salary) from employees.salaries where emp_no = '10001';
    select min(salary) from employees.salaries where emp_no = '10001';

    公司所有员工每一位平均薪水,最高,最低,使用别名显示。

    select emp_no,avg(salary) as 平均薪资,max(salary) as 最高薪资,min(salary) as 最低薪资 from employees.salaries group by emp_no;

    统计一下dept_emp这张表的数据量

    select count(emp_no) from employees.dept_emp;

    再统计一下员工id(emp_no)的去重数量

    select count(distinct(emp_no)) from employees.dept_emp;

    把重复出现员工id筛选出来

    select emp_no from employees.dept_emp group by emp_no having count(*)>1;

    重复员工id把完整的信息dept_emp筛选出来

    select * from employees.employees where emp_no in (select emp_no from employees.dept_emp group by emp_no having count(*)>1);

    现在薪水最高的那个员工的信息。

    select * from employees.employees where emp_no = (select emp_no from employees.salaries where to_date ='9999-01-01' order by salary desc limit 1);

    工作17年以上的员工都有谁?具体每个人每年薪资详细信息。

    select * from employees.salaries where emp_no in (select emp_no from employees.salaries group by emp_no having count(*)>17);

    显示员工号,员工名字和所有部门号(部门名称)

    select a.emp_no,a.last_name,a.first_name,b.dept_no,c.dept_name from employees.employees a,employees.dept_emp b,employees.departments c where a.emp_no = b.emp_no and b.dept_no = c.dept_no;

    显示 Customer Service 部门所有员工名字 ,使用内联接

    select a.last_name,a.first_name from employees.employees a inner join employees.dept_emp b on a.emp_no = b.emp_no inner join departments c on b.dept_no = c.dept_no where c.dept_name = 'Customer Service';

    显示Customer Service 部门员工数量 ,左联接-右联接-数量是否不同。

    select count(*) from employees.employees a left join employees.dept_emp b on a.emp_no = b.emp_no left join departments c on b.dept_no = c.dept_no where c.dept_name = 'Customer Service';

    显示现在(最后一次调动工作以来)薪水最低的10名人员员工编号及薪水,薪水加密显示。

    select emp_no,salary,md5(salary) from employees.salaries where to_date = '9999-01-01' order by salary asc limit 10;

    给2002年调动工作的,现在在职的员工涨工资3000

    update employees.salaries set salary=salary+3000 where emp_no in (select emp_no from employees.dept_emp where extract(year from from_date) = 2002 and to_date = '9999-01-01');

    面试

    手机号存成什么类型,长度多长?
    varchar(20)

    字符集是哪个?需要注释吗?
    charset

    工作中使用存储过程、视图、触发器、Event?
    无,

    主外键做什么,实际中你们用吗?
    数据库表之间的关联方式;

    索引怎么用?
    CREATE INDEX xxx on xxxx
    select xx from xx where xx=xxx;

    存储过程用吗?
    存储过程是实现特定功能的、经过封装的sql语句集

    什么时候用TEXT、BLOB类型?大文件或者大照片怎么存的?
    大文件在服务器上存储时,通常只会存储文件名,而无需记录路径

    你们使用什么引擎?
    innodb

    int(11),是什么意思,varchar(20)是什么意思?
    显示长度为11位/20位

    删除命令你知道哪些?
    drop delete

    你了解事务吗?
    一系列sql语句的集合

    事务怎么测试呢?
    原子性测试:
    所有的sql要不全部执行,要不都不执行
    在sql语句集合中,手动让后面的sql语句执行失败,此时sql集合的操作结果应该都要被回滚;

  • 难得假期,占位来补下作业来

    查询全部信息

    select * from employees;

    查询100行员工信息

    select * from employees limit 100;

    查询last_name姓Facello的信息

    select * from employees.employees where last_name = 'Facello';

    查询不是姓Facello并且员工号小于10020的员工,

    select * from employees.employees where last_name <> 'Facello' and emp_no < 10020;

    查询雇佣时间大于2000年1月1日的员工名字,使用别名显示字段名为员工姓名

    select first_name as , last_name as  from employees.employees where hire_date > '2000-01-01';

    查询女生并且姓是Pettey的信息

    select * from employees.employees where gender = 'F' and last_name = 'Pettey';

    查询所有姓Facello的或是叫mary的女生并且出生在1960年以后的 员工信息

    select * from employees.employees where (last_name = 'Facello' or first_name = 'mary') and gender = 'F' and birth_date >= '1960-01-01';

    查询所有姓Facello的男生或是姓Hutton的女生

    select * from employees.employees where (last_name = 'Facello' and gender = 'M') or (last_name = 'Hutton' and  gender = 'F');

    员工都是哪些姓,按姓排序正序排,显示员工姓名

    select last_name as , first_name as  from employees.employees order by last_name;

    显示2000年后来的员工按时间排序并按姓排序,显示员工名和雇佣时间

    select last_name as ,first_name as ,hire_date as 雇佣时间 from employees.employees where hire_date > '2000-01-01' order by hire_date,last_name;

    显示(不)姓Facello和姓Hutton的员工,使用in (not in)

    select * from employees.employees where last_name in ('Facello', 'Hutton');

    显示是否有没有雇佣时间的员工

    select * from employees.employees where hire_date is null or hire_date = '';

    显示工作20年以上的员工

    select * from employees.employees where hire_date < date_sub(curdate(),interval 20 year);

    显示以b下列开头的名字

    select * from employees.employees where last_name like 'b%';

    显示以fy结尾的名字

    select * from employees.employees where last_name like '%fy';

    显示包含we名字

    select * from employees.employees where last_name like '%we%';

    显示包含五个字符的名字

    select * from employees.employees where length(last_name) = 5;

新人一枚,容易沉迷,求时不时打醒下