zoukankan      html  css  js  c++  java
  • Robotframework使用自写库连接mysql数据库

    Robotframework使用自写库连接mysql数据库

    新建库文件mysqltest.py

    代码如下:

    # -*- coding: utf-8 -*-

    import MySQLdb
    import os,sys
    from sshtunnel import SSHTunnelForwarder

    def mysql_test(sql):
    with SSHTunnelForwarder( #ssh的地址,端口,用户名,密码
    ('122.17.51.11', 22),
    ssh_password="te238",
    ssh_username="test1",
    remote_bind_address=('rdse555ttj41b8e4iy3.mysql.rds.com', 3306)) as server:

    conn = MySQLdb.connect(host='127.0.0.1', #此处必须是是127.0.0.1
    port=server.local_bind_port,
    user='test', #Navicat常规处的链接用户名和密码,以及连接数据库名称
    passwd='Xe4gyu6Jb1a',
    db='test')
    cursor = conn.cursor() #.cursor()用来获得python执行Mysql命令的方法
    select = sql
    cursor.execute(select) #.execute()执行mysql语句
    data=cursor.fetchall() #fetchall()则是接收全部的返回结果行
    return data
    pass

    if __name__ == "__main__":
    pass


    在ride中选中测试用例目录,在右侧添加library

     

    新建一条测试用例:调试4

    获取数据库返回的值,将该值赋值给a

     

    日志为;

  • 相关阅读:
    全排列(next_permutation)
    Codeforces Round #321 (Div. 2)C(tree dfs)
    cf_ducational Codeforces Round 16_D(gcd)
    cf455a(简单dp)
    cf584a(水题)
    cf112a(水题)
    冒泡排序
    Python内置类型性能分析
    常见时间复杂度
    MongoDB 备份
  • 原文地址:https://www.cnblogs.com/zhangfeivip/p/10102952.html
Copyright © 2011-2022 走看看