首页 文章

如何通过下载数据库中的登录或excel webdriver selenium来运行更多测试

提问于
浏览
0

我有一个n-logins列表,我会用n次登录到站点的登录脚本 . 我有一个简单的脚本记录:

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);
    }
    }

    }

我有一个从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();

    }
 }

如何连接以运行测试示例 . 40次?登录=密码 .

1 回答

  • 1

    您正在使用TestNG测试框架 . 为了从数据库读取并执行测试脚本,您需要使用数据提供程序 . 请参考以下教程:

    http://www.toolsqa.com/selenium-webdriver/testng-parameters-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
    }
    

相关问题