Connect a remote database using Selenium Webdriver and run test applications from a local machine via eclipse

I am using selenium web driver java built , eclipse editor. To test one of our websites, I use Data-driven testing, retrieving data from a MySQL database.

I dumped the development server database on my local computer and installed this data on my xampp computer and was able to connect to the database and continue the testing process.

To connect to my local database, I use this connection string

String url1 ="jdbc:mysql://localhost:3306/databasename"; String dbClass = "com.mysql.jdbc.Driver"; Class.forName(dbClass).newInstance(); Connection con = DriverManager.getConnection(url1, "root", ""); Statement stmt = (Statement) con.createStatement(); 

Now I need to connect to our source development server database, which is located on a remote server.

I tried this as a connection string to connect a remote machine

  String url1 ="jdbc:mysql://10.0.2.129:3306/test"; String dbClass ="com.mysql.jdbc.Driver"; Class.forName(dbClass).newInstance(); Connection con = DriverManager.getConnection(url1, "root","root"); 

but cannot connect to the remote computer database. The result of the error is displayed

 java.lang.ClassNotFoundException: com.mysql.jdbc.Driver at java.net.URLClassLoader$1.run(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) 

Can someone suggest me what changes need to be made to the connection string to connect the remote server database that is protected by ht access ? and how can I run my test cases from my local machine when connected to a remote server database.

Please provide some suggestion.

+6
source share
3 answers

You just need to specify the device IP address, port and database name in the connection string. So try something like

 String dbUrl = "jdbc:mysql://192.168.1.53306/myDB"; DriverManager.getConnection(dbUrl, "username", "password"); 

And your tests should work the same way as before, you just connect to another machine, which can be more time-consuming (for example, requests may take longer), but this is the only difference.

0
source

You can use the data-driven capabilities with one of the selenium testing systems - ISFW , where you can specify a database query to provide test data. For instance:

 @IsDataProvider(sqlQuery="select query") @Test public void testSomething(Map<String, String> testdata){ //use query col as key testdata.get("colName") } 
0
source

You need to add a jar file to connect to the database

 jar: mysql-connector-java 
-1
source

Source: https://habr.com/ru/post/953834/


All Articles