0

I've recently created a framework that successfully tests the GUI of my project. Now I would like to extend my testing by creating full end to end testing of functional tests. These tests would execute the following core steps.

  1. Create Profile using the GUI ( this is done using Java selenium webdriver)
  2. Automating calling a unix script that is stored on a server that I would use putty to connect to and run
  3. After the script has ran verify expected information in the DB

I have already completed the first step I'm wondering should I integrate step 2 and 3 into my already existing framework? Can I do all this with Java? Is there any documentation to help me with step 2 & 3?

TrevDred
  • 99
  • 2
  • 14

3 Answers3

0

Use the following command in your Java code to run the script.

Runtime.getRuntime().exec(myShellScript);

After that, use a JDBC connection to verify data in the DB.

Akash Agarwal
  • 2,326
  • 1
  • 27
  • 57
  • Also, it'd be easier for you to google parts of your questions from next time to find answers to them than posting it here. Parts of your problem have been solved already on StackOverflow network. – Akash Agarwal Sep 22 '15 at 15:28
0

For 2nd step use below code

You should really look at Process Builder. It is really built for this kind of thing.

 ProcessBuilder pb = new ProcessBuilder("myshellScript.sh", "myArg1", "myArg2");
 Map<String, String> env = pb.environment();
 env.put("VAR1", "myValue");
 env.remove("OTHERVAR");
 env.put("VAR2", env.get("VAR1") + "suffix");
 pb.directory(new File("myDir"));
 Process p = pb.start();

For step 3 you can refer to this reference.

JeffC
  • 22,180
  • 5
  • 32
  • 55
Shubham Jain
  • 16,610
  • 15
  • 78
  • 125
0

Actually seleniumhq gives a good start point for such database-validation approach.

Another common type of testing is to compare data in the UI against the data actually stored in the AUT’s database. Since you can also do database queries from a programming language, assuming you have database support functions, you can use them to retrieve data and then use the data to verify what’s displayed by the AUT is correct.

Simple example code:

// Load Microsoft SQL Server JDBC driver.
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

// Prepare connection url.
String url = "jdbc:sqlserver://192.168.1.180:1433;DatabaseName=TEST_DB";

// Get connection to DB.
public static Connection con =
DriverManager.getConnection(url, "username", "password");

// Create statement object which would be used in writing DDL and DML
// SQL statement.
public static Statement stmt = con.createStatement();

// Send SQL SELECT statements to the database via the Statement.executeQuery
// method which returns the requested information as rows of data in a
// ResultSet object.

ResultSet result =  stmt.executeQuery
("select top 1 email_address from user_register_table");

// Move cursor from default position to first row of result set.
result.next();

// Fetch value of "email_address" from "result" object.
String emailaddress = result.getString("email_address");

// Use the emailAddress value to login to application.
driver.findElement(By.id, "userID").sendKeys(emailaddress);
driver.findElement(By.id, "password").sendKeys(secretPassword);
driver.findElement(By.id, "loginButton").click();
WebElement element = driver.findElement(By.xpath, "//*[contains(.,'Welcome back ')]");
Assert.assertTrue(element.getText().contains(emailaddress), "Unable to log in for user" + emailaddress)
ekostadinov
  • 6,880
  • 3
  • 29
  • 47