我通过使用robotframework DatabaseLibrary,JayDeBeApi,MS SQL Server JDBC驱动程序设置了robotframework测试,并已成功建立连接。但是我得到SQLServerException:当运行任何sql时,当AutoCommit模式设置为“ true”时,无法调用回滚操作。
我尝试通过在jdbc连接URL上添加“ autoCommit = false”或在sql语句中添加“ SET IMPLICIT_TRANSACTIONS ON”来关闭AutoCommit,或者甚至在SQL Server Management Studio上选中SET IMPLICIT_TRANSACTIONS ANSI选项,但都没有运气尝试。
这里是robotframework maven插件设置
pom.xml
<plugin>
<groupId>org.robotframework</groupId>
<artifactId>robotframework-maven-plugin</artifactId>
<version>1.4.5</version>
<executions>
<execution>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<configuration>
<extraPathDirectories>
<extraPathDirectory>/opt/virtualenv_envs/robot/lib/python2.7/site-packages</extraPathDirectory>
<extraPathDirectory>/usr/local/lib/python2.7/dist-packages</extraPathDirectory>
</extraPathDirectories>
</configuration>
<dependencies>
<dependency> <!-- this jar from local nexus -->
<groupId>com.microsoft.sqlserver.jdbc</groupId>
<artifactId>sqljdbc41</artifactId>
<version>4.1</version>
</dependency>
</dependencies>
</plugin>
下面是机器人测试
dbTest.robot
*** Settings ***
Library DatabaseLibrary
Library String
Library OperatingSystem
Suite Setup SuiteSetup
Suite Teardown SuiteTearDown
*** Variables ***
${JDBC_DRIVER} 'com.microsoft.sqlserver.jdbc.SQLServerDriver'
${JDBC_URL} 'jdbc:sqlserver://{ipAddress}:1433;databaseName={myDB};user={username};password={password}'
*** Test Cases ***
Test Prepare Data
[Documentation] Reset Data
Execute Sql String UPDATE dbo.ImportHeader SET ExtractedOn=null;
*** Keywords ***
SuiteSetup
Connect To Database Using Custom Params jaydebeapi ${JDBC_DRIVER},${JDBC_URL}
SuiteTearDown
Disconnect From Database
这是运行机器人测试时遇到的错误
Test Prepare Data :: Reset Data... | FAIL |
DatabaseError: com.microsoft.sqlserver.jdbc.SQLServerException: Cannot invoke a rollback operation when the AutoCommit mode is set to "true".
我对此所做的一个彻底的解决方案是,通过在jaydebeapi连接上将autoCommit设置为false来修改robotframework DatabaseLibary connection_manager.py,如下所示,但是[我希望了解比此更好的解决方案,如果有的话。 {您的python virtualenv} /site-packages/DatabaseLibrary/connection_manager.pyimport ConfigParser
from robot.api import logger
class ConnectionManager(object):
"""
Connection Manager handles the connection & disconnection to the database.
"""
def connect_to_database_using_custom_params(self, dbapiModuleName=None, db_connect_string=''):
"""
Loads the DB API 2.0 module given `dbapiModuleName` then uses it to
connect to the database using the map string `db_custom_param_string`.
Example usage:
| # for psycopg2 |
| Connect To Database Using Custom Params | psycopg2 | database='my_db_test', user='postgres', password='s3cr3t', host='tiger.foobar.com', port=5432 |
| # for JayDeBeApi |
| Connect To Database Using Custom Params | JayDeBeApi | 'oracle.jdbc.driver.OracleDriver', 'my_db_test', 'system', 's3cr3t' |
"""
db_api_2 = __import__(dbapiModuleName)
db_connect_string = 'db_api_2.connect(%s)' % db_connect_string
self._dbconnection = eval(db_connect_string)
self._dbconnection.jconn.setAutoCommit(False)
我通过使用robotframework DatabaseLibrary,JayDeBeApi,MS SQL Server JDBC驱动程序设置了robotframework测试,并已成功建立连接。但是我得到了SQLServerException:无法调用...