0

I am using cucumber , Junit , Selenium Web driver and have JDBC connection

I have a feature with below scenario Scenario Outline: Fill out the ATS Registration Form

When Click on SignUp And first name is '' And last name is '' And username is '' And phone is '' And Email is '' And companyname is '' And companytype is '' And address is '' And country is '' And province is '' And city is '' And Postal code is '' And reference is '' And ecommunications is Yes And termsandcondition is enabled And click on submit Then verify the successmessage And check the new user in database

Examples:

|firstname  | lastname   | username          | phonenumber  |    emailaddress      | companyname |companytype  | address    |country     | province    |   city      | postalcode   | reference   |
| Ram       |   Sita     |  kaka1123456 |  64189523    |kaka123456@ats.co | AAAACCCC    |  Architect  |  AAAAA     |  Canada    |  Ontario    |   Toronto   |     M9V3G2   |    Other    |

I have a step definition which map to this feature file and page object model.

I have one class for jdbc connection.

 package ca.test.utils;

import java.sql.*;

public class Jdbcdemo {

    ConfigReader reader = new ConfigReader();

    public void jdbcdemo(){

        try {
            // Get a connection to database
            Connection myConn = DriverManager.getConnection("NA" , "NA", "NA");

            // Create a statement
            Statement mystatement = myConn.createStatement();

            //Execute sql
            ResultSet myRs = mystatement.executeQuery("select * from `user` u  where u.username = ('kaka1123456')");

            //process the result
            while (myRs.next()){
               String actual =  myRs.getString("username");
                       System.out.println("username" + actual );
            }
            myRs.close();
            mystatement.close();
            myConn.close();
        }
        catch (Exception exc){
            exc.printStackTrace();
        }
    }

}

The result is printing on console

Is there any way to compare the feature file data ( username ) with sql data ? if not then how can i compare the data?

2

It is obviously possible. I won't give you the code but I'll give you the direction:

  1. First you should rework public void jdbcdemo(). Add static modifier to the method. Also add the parameters definitions to the method. The parameter set is the same as your then step definition accepts.
  2. Rework jdbcdemo() method code. Where you create a statement, you should create prepared statement.
  3. Bind the parameters values (which the method accepts) to your query through prepared statement mechanism.
  4. In the method use the query that selects the users from the database using the parameter values provided as the filter (where clause)
  5. In the method instead of while use if where you check myRs.next(). If it is false, set the test failed, otherwise set the test passed.
  6. In your then step definition call Jdbcdemo.jdbcDemo(parameters), where parameters are the values that are propagated to your then step definition.

P.S. - I recommend you to rename the class and the method so that they reflect their purpose in the better way.

0

This is purely can be done on language level by writing utility custom methods to establish jdbc connections and validating the recordsets against feature file data inside step defs.

Instead of relying on any tool/frame work's out of the box feature , it is more flexible solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.