0

I have a list of n-logins that I would use to n times run the logon script to the site. I have a simple script that logs :



    public class loginGoogle {
    private WebDriver driver;
    private String baseUrl;
    private boolean acceptNextAlert = true;
    private StringBuffer verificationErrors = new StringBuffer();

    @Before
    public void setUp() throws Exception {
    driver = new FirefoxDriver();
    baseUrl = "https://accounts.google.com/";
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    }

    @Test
    public void testLoginGoogle() throws Exception {
    driver.get(baseUrl + "/AccountChooser?continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&hl=pl&service=mail&scc=1");
    assertEquals("Logowanie – Konta Google", driver.getTitle());
    driver.findElement(By.id("account-chooser-add-account")).click();
    driver.findElement(By.id("Email")).clear();
    driver.findElement(By.id("Email")).sendKeys("LOGIN");
    driver.findElement(By.id("Passwd")).clear();
    driver.findElement(By.id("Passwd")).sendKeys("PASSWORD");
    driver.findElement(By.id("signIn")).click();
    driver.findElement(By.cssSelector("span.gb_X.gbii")).click();
    driver.findElement(By.id("gb_71")).click();
    }

    @After
    public void tearDown() throws Exception {
    driver.quit();
    String verificationErrorString = verificationErrors.toString();
    if (!"".equals(verificationErrorString)) {
      fail(verificationErrorString);
    }
    }

    }


 

and I have a script that retrieves data from oracledb:


    package orclConn;

    import java.sql.DriverManager;
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;


    public class orclConn {

    public static void main(String[] argv) throws SQLException {

    System.out.println("-------- Oracle JDBC Connection Testing ------");

    try {

    Class.forName("oracle.jdbc.driver.OracleDriver");

    } catch (ClassNotFoundException e) {

    System.out.println("Where is your Oracle JDBC Driver?");
    e.printStackTrace();
    return;

    }

    System.out.println("Oracle JDBC Driver Registered!");

    Connection connection = null;

    try {

    connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:mybase", "user",
                    "password");

    } catch (SQLException e) {

    System.out.println("Connection Failed! Check output console");
    e.printStackTrace();
    return;

    }

    if (connection != null) {
    System.out.println("You made it, take control your database now!");
    } else {
    System.out.println("Failed to make connection!");
    }



    String sql ="select rownum,login from users";
    PreparedStatement preStatement = connection.prepareStatement(sql2);
    ResultSet result = preStatement.executeQuery();
    while(result2.next()){
    System.out.println("Sheet " + result2.getString("rownum") + " login : " +  result2.getString("login"));
    }
    System.out.println("done");

    connection.close();

    }
 }

How does it connect to run the test example. 40 times? Login = password.

2
  • Your question is a bit unclear for me to understand. Do you want to know the underlying layers of the connection between db and script or do u want to know how to execute the scripts 40 times after reading data from the database... please clarify Commented Aug 13, 2014 at 13:44
  • I have for example 40 logins downloaded from the database query by orclConn. I want to use them in turn to test the login where username = password (loginGoogle). How to combine the two scripts WebDriver so that it was possible. Commented Aug 18, 2014 at 7:39

1 Answer 1

1

You are using TestNG testing framework. In order to read from database and executing your test scripts you are required to use Data providers. Please refer to the following tutorial:

TestNG Parameters & Data Provider

Also you can use the following information to read data from a database and save it in a hashmap to later feed it back to the data-provider.

 Map<String, String> IDMap = new HashMap<String, String>();             //Initializing a Map

 while(result2.next()){
    System.out.println("Sheet " + result2.getString("rownum") + " login : " +  result2.getString("login"));
    IDMap.put(result2.getString("login"), result2.getString("login"));  //Saving the database information in a Map
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.