简体   繁体   English

未调用 TestNG 测试

[英]TestNG test not getting invoked

我正在尝试连接我的数据库,然后运行查询以通过 testNG 测试获得结果。

Please delete all the junit imports from the class, if you are planning to use TestNG for your execution.如果您打算使用 TestNG 来执行,请从该类中删除所有junit导入。 I would suggest you to use following approach:我建议您使用以下方法:

package regressionTesting;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.concurrent.TimeUnit;

import javax.naming.spi.DirStateFactory.Result;

import org.openqa.selenium.*;
import org.openqa.selenium.By.ByXPath;

import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class TestDBConnect {

public static String username = null;

    @BeforeClass
    public void setUp() {
        username = getUsernameFromDB();
    }

    @Test
    public void testUI() {

        //Some code for navigating to the required page
        driver.findElement(By.id("u")).sendKeys(username);
        //Code for executing remaining steps 

    }

    public static String getUsernameFromDB() throws ClassNotFoundException, SQLException  {
            //Accessing driver from the JAR file 
            Class.forName("oracle.jdbc.OracleDriver");
            System.out.println("Oracle JDBC driver loaded ok.");

            Connection con=DriverManager.getConnection("jdbc:oracle:thin:@151.117.87.205:1602:epwfst1","epwf_app","epwf_app_epwfst1");
            System.out.println("DB Connected Successfuly");

            Statement stmt = con.createStatement();

            ResultSet result = stmt.executeQuery("select billing_application_accnt_id from epwf.payment where created_user_nm = '1600STOUTST10001'");

            String account = null;       
            while(result.next()){
                account = result.getString("BILLING_APPLICATION_ACCNT_ID");
                System.out.println("BAID: " + account);
            }
            con.close();
            return account;
         }
   @AfterClass
   public void cleanUp() {
          //Code for clean-up activities like closing browser and releasing resources.
   }
}

In the above code, I assumed that u is the id of text field in which you want to enter the value read from database.在上面的代码中,我假设u是要在其中输入从数据库读取的值的文本字段的id You can replace it with the actual id attribute value, or use other property as well for recognizing the username text box.您可以将其替换为实际的id属性值,也可以使用其他属性来识别用户名文本框。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果在类中禁用了测试,则不会调用TestNg @afterclass - TestNg @afterclass isn't invoked if there is disabled test in a class 将TestNG测试参数注入由IInvokedMethodListener调用的自定义方法中的一种方法 - A way of injecting TestNG test parameters into custom method invoked by IInvokedMethodListener TestNg:使用maven执行测试时获取ArrayIndexOutOfBoundsException:0 - TestNg: getting ArrayIndexOutOfBoundsException: 0 while executing test with maven 测试级别 testng XML 参数未更新 - Test level testng XML parameter is not getting updated 获取和使用 TestNG @test 注解参数 - getting and using TestNG @test annotation parameters Spring JUnit测试中未调用Hibernate侦听器 - Hibernate listeners are not getting invoked in Spring JUnit test 在TestNG测试套件的类中获取_all_方法的列表 - Getting list of _all_ methods in a class for a TestNG test suite 尝试使用TestNG中的ExtentReports生成测试报告时获取NullPointerException - Getting NullPointerException when trying to generate test reports using ExtentReports in TestNG 在套件中运行测试用例时在 XML testng 文件中出错 - Getting Error in XML testng file while running the test case in a suite 尝试使用TestNG和WebDriverManager运行测试时出现错误 - Getting error when trying to run a test with TestNG and WebDriverManager
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM