|
1 |
| - ------ |
2 |
| - Java Libraries |
3 |
| - ------ |
4 |
| - Dietrich Schulten |
5 |
| - ------ |
6 |
| - 2012-01-20 |
7 |
| - ------ |
8 |
| -
|
9 |
| -Using Java Libraries with the Robotframework Plugin |
10 |
| -
|
11 |
| - * Java test libraries |
12 |
| -
|
13 |
| - You can access Java test libraries by adding the jars to the extraPathDirectories parameter. |
14 |
| - Note that such tests will run with Jython only. |
15 |
| -
|
16 |
| -+--- |
17 |
| - <plugin> |
18 |
| - <groupId>org.robotframework</groupId> |
19 |
| - <artifactId>robotframework-maven-plugin</artifactId> |
20 |
| - <configuration> |
21 |
| - <extraPathDirectories> |
22 |
| - <extraPathDirectory>src/test/pythonpath</extraPathDirectory> |
23 |
| - <extraPathDiectory>src/test/mytestlib.jar</extraPathDirectory |
24 |
| - </extraPathDirectories> |
25 |
| - </configuration> |
26 |
| - </plugin> |
27 |
| -+--- |
28 |
| -
|
29 |
| - * Python libraries with Java dependencies |
30 |
| -
|
31 |
| - But there is a different use case. Python libraries can use Java libraries directly |
32 |
| - using JPype. For example, the Python based DatabaseLibrary can be |
33 |
| - used with jaydebeapi and JPype to access databases via Python and jdbc. |
34 |
| -
|
35 |
| - Such a test runs within a pure Python environment with JPype installed, as well as with |
36 |
| - Jython. That way you can have database test cases that run within RIDE in Python mode, |
37 |
| - and within the Robotframework Maven Plugin. |
38 |
| -
|
39 |
| - If you need Java libraries as dependencies to your test libraries, you can add them to the |
40 |
| - dependencies section of the maven plugin configuration in the pom. |
41 |
| -
|
42 |
| -+--- |
43 |
| - <plugin> |
44 |
| - <groupId>org.robotframework</groupId> |
45 |
| - <artifactId>robotframework-maven-plugin</artifactId> |
46 |
| - <version>1.4.9</version> |
47 |
| - <configuration> |
48 |
| - <extraPathDirectories> |
49 |
| - <extraPathDirectory>src/test/resources/python</extraPathDirectory> |
50 |
| - </extraPathDirectories> |
51 |
| - </configuration> |
52 |
| - <dependencies> |
53 |
| - <dependency> |
54 |
| - <groupId>org.hsqldb</groupId> |
55 |
| - <artifactId>hsqldb</artifactId> |
56 |
| - <version>1.8.0.10</version> |
57 |
| - </dependency> |
58 |
| - </dependencies> |
59 |
| - </plugin> |
60 |
| -+--- |
61 |
| -
|
62 |
| - The test cases access hsqldb, the python folder contains the DatabaseLibrary and the jaydebeapi. |
63 |
| -
|
64 |
| - If you want to run such a test within RIDE, make sure DatabaseLibrary, JPype and jaydebeapi |
65 |
| - are installed in your Python runtime. |
66 |
| -
|
67 |
| - An actual test case is shown below. |
68 |
| -
|
69 |
| -+--- |
70 |
| -*** Settings *** |
71 |
| -Library OperatingSystem |
72 |
| -Library DatabaseLibrary |
73 |
| -
|
74 |
| -*** Test Cases *** |
75 |
| -Connect |
76 |
| - Connect To Database Using Custom Params jaydebeapi org.hsqldb.jdbcDriver jdbc:hsqldb:mem:robot sa ${EMPTY} |
77 |
| - Execute SQL create table testtable (myid integer not null primary key, name varchar(25)) |
78 |
| - Execute SQL insert into testtable values (1, 'myname') |
79 |
| - Execute SQL insert into testtable values (2, 'yourname') |
80 |
| - @{result}= Execute Sql Select * from testtable |
81 |
| - Log Many @{result} |
82 |
| - Check If Exists In Database select * from testtable where myid=2 |
83 |
| - Execute SQL drop table testtable |
84 |
| - Disconnect From Database |
85 |
| -+--- |
| 1 | + ------ |
| 2 | + Java Libraries |
| 3 | + ------ |
| 4 | + Dietrich Schulten |
| 5 | + ------ |
| 6 | + 2012-01-20 |
| 7 | + ------ |
| 8 | + |
| 9 | +Using Java Libraries with the Robotframework Plugin |
| 10 | + |
| 11 | + * Java test libraries |
| 12 | + |
| 13 | + You can access Java test libraries by adding the jars to the extraPathDirectories parameter. |
| 14 | + Note that such tests will run with Jython only. |
| 15 | + |
| 16 | ++--- |
| 17 | + <plugin> |
| 18 | + <groupId>org.robotframework</groupId> |
| 19 | + <artifactId>robotframework-maven-plugin</artifactId> |
| 20 | + <configuration> |
| 21 | + <extraPathDirectories> |
| 22 | + <extraPathDirectory>src/test/pythonpath</extraPathDirectory> |
| 23 | + <extraPathDiectory>src/test/mytestlib.jar</extraPathDirectory |
| 24 | + </extraPathDirectories> |
| 25 | + </configuration> |
| 26 | + </plugin> |
| 27 | ++--- |
| 28 | + |
| 29 | + * Python libraries with Java dependencies |
| 30 | + |
| 31 | + But there is a different use case. Python libraries can use Java libraries directly |
| 32 | + using JPype. For example, the Python based DatabaseLibrary can be |
| 33 | + used with jaydebeapi and JPype to access databases via Python and jdbc. |
| 34 | + |
| 35 | + Such a test runs within a pure Python environment with JPype installed, as well as with |
| 36 | + Jython. That way you can have database test cases that run within RIDE in Python mode, |
| 37 | + and within the Robotframework Maven Plugin. |
| 38 | + |
| 39 | + If you need Java libraries as dependencies to your test libraries, you can add them to the |
| 40 | + dependencies section of the maven plugin configuration in the pom. |
| 41 | + |
| 42 | ++--- |
| 43 | + <plugin> |
| 44 | + <groupId>org.robotframework</groupId> |
| 45 | + <artifactId>robotframework-maven-plugin</artifactId> |
| 46 | + <version>1.5.0</version> |
| 47 | + <configuration> |
| 48 | + <extraPathDirectories> |
| 49 | + <extraPathDirectory>src/test/resources/python</extraPathDirectory> |
| 50 | + </extraPathDirectories> |
| 51 | + </configuration> |
| 52 | + <dependencies> |
| 53 | + <dependency> |
| 54 | + <groupId>org.hsqldb</groupId> |
| 55 | + <artifactId>hsqldb</artifactId> |
| 56 | + <version>1.8.0.10</version> |
| 57 | + </dependency> |
| 58 | + </dependencies> |
| 59 | + </plugin> |
| 60 | ++--- |
| 61 | + |
| 62 | + The test cases access hsqldb, the python folder contains the DatabaseLibrary and the jaydebeapi. |
| 63 | + |
| 64 | + If you want to run such a test within RIDE, make sure DatabaseLibrary, JPype and jaydebeapi |
| 65 | + are installed in your Python runtime. |
| 66 | + |
| 67 | + An actual test case is shown below. |
| 68 | + |
| 69 | ++--- |
| 70 | +*** Settings *** |
| 71 | +Library OperatingSystem |
| 72 | +Library DatabaseLibrary |
| 73 | + |
| 74 | +*** Test Cases *** |
| 75 | +Connect |
| 76 | + Connect To Database Using Custom Params jaydebeapi org.hsqldb.jdbcDriver jdbc:hsqldb:mem:robot sa ${EMPTY} |
| 77 | + Execute SQL create table testtable (myid integer not null primary key, name varchar(25)) |
| 78 | + Execute SQL insert into testtable values (1, 'myname') |
| 79 | + Execute SQL insert into testtable values (2, 'yourname') |
| 80 | + @{result}= Execute Sql Select * from testtable |
| 81 | + Log Many @{result} |
| 82 | + Check If Exists In Database select * from testtable where myid=2 |
| 83 | + Execute SQL drop table testtable |
| 84 | + Disconnect From Database |
| 85 | ++--- |
0 commit comments