@BeforeClass public void setUp() throws Exception { // Configuring Log4j logs. new BaseClass(); DOMConfigurator.configure(BaseClass.bLog); // Setting Excel File -- Test Data xls File ExcelUtils.setExcelFile( Constant.Path_TestData + Constant.File_TestData, Constant.File_TestappNameSheet); // Getting the Test Case name, as it will going to use in so many places // The main use is to get the TestCase row from the Test Data Excel sheet sTestCaseName = this.toString(); Log.info(sTestCaseName); sTestCaseName = Utils.getTestCaseName(this.toString()); Log.info(sTestCaseName); Log.startTestCase(sTestCaseName); testStep = new HelperFunction(); }
// Following TestNg Test case pattern, and divided a Test case in to three different part. // In Before Method, your code will always be the same for every other test case. // In other way before method is your prerequisites of your main Test Case @BeforeMethod public void beforeMethod() throws Exception { // Configuring Log4j logs, please see the following posts to learn about Log4j Logging // http://www.toolsqa.com/test-case-with-log4j/ // http://www.toolsqa.com/log4j-logging/ DOMConfigurator.configure("log4j.xml"); // Getting the Test Case name, as it will going to use in so many places // The main use is to get the TestCase row from the Test Data Excel sheet sTestCaseName = this.toString(); // From above method we get long test case name including package and class name etc. // The below method will refine your test case name, exactly the name use have used sTestCaseName = Utils.getTestCaseName(this.toString()); // Start printing the logs and printing the Test Case name Log.startTestCase(sTestCaseName); // Setting up the Test Data Excel file using Constants variables // For Constant Variables please see http://www.toolsqa.com/constant-variables/ // For setting up Excel for Data driven testing, please see // http://www.toolsqa.com/data-driven-testing-excel-poi/ ExcelUtils.setExcelFile(Constant.Path_TestData + Constant.File_TestData, "Sheet1"); // Fetching the Test Case row number from the Test Data Sheet // This row number will be feed to so many functions, to get the relevant data from the Test // Data sheet iTestCaseRow = ExcelUtils.getRowContains(sTestCaseName, Constant.Col_TestCaseName); // Launching the browser, this will take the Browser Type from Test Data Sheet driver = Utils.OpenBrowser(iTestCaseRow); // Initializing the Base Class for Selenium driver // Now we do need to provide the Selenium driver to any of the Page classes or Module Actions // Will soon write a post on Base Class new BaseClass(driver); }