Java

Java: log4j2: 2 - Configuration

Configuration

http://logging.apache.org/log4j/2.x/manual/configuration.html

Inserting log requests into the application code requires a fair amount of planning and effort. Observation shows that approximately 4 percent of code is dedicated to logging. Consequently, even moderately sized applications will have thousands of logging statements embedded within their code. Given their number, it becomes imperative to manage these log statements without the need to modify them manually.

Configuration of Log4j 2 can be accomplished in 1 of 4 ways:

Tags

Java: Javadoc: How to Write Doc Comments for the Javadoc Tool

Sample Comment/Method

/**
* Returns an Image object that can then be painted on the screen.
* The url argument must specify an absolute {@link URL}. The name
* argument is a specifier that is relative to the url argument.
* <p>
* This method always returns immediately, whether or not the
* image exists. When this applet attempts to draw the image on
* the screen, the data will be loaded.

Java POM: 07-Apache POI ( Excel )

 

Imports

import java.io.FileInputStream;
import java.io.FileOutputStream;

import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

 

 

Tags

Java POM: 06-Selenium

 

Imports

import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;

 

Components Commonly Used

WebDriver

  • Create a public class so its accessible through the application
  • Create a single static object so it also can be referenced throughout the application
  • This class will do the work of building up & calling the correct Browser & Profile
  • Then return the driver for use with the PageObjects(which will NOT be static)
public class BrowserUtils {
    public static WebDriver driver = null;
    public static WebDriver OpenBrowser(){

            // Create web driver
            driver = new FirefoxDriver();
            return driver;
    } //end method

}

 

Tags

Java POM: 05-TestNG

Configuration File testng.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suites" parallel="none">
       <listeners>
              <listener class-name="com.uc.test.selenium.util.Listener"></listener>
       </listeners>
      <test name="Simple Test">
        <classes>
          <class name="com.uc.test.selenium.tests.Test_Login"/>
        </classes>
      </test>
      <!-- test name="ALL">
          <packages>
              <package name="com.uc.test.selenium.tests" />
          </packages>
      </test -->
      
                          
</suite> <!-- Suite -->

 

Tags

Java POM: 04-Classes

Package Layout

  • src
    • log4j2.xml - log4j2 Configuration
    • pom.xml - Maven Configuration
    • testng.xml - TestNG Configuration
    • com.us.test.selenium
      • Main
    • com.us.test.selenium.pageactions
      • Home_Actions
    • com.us.test.selenium.pageobjects
      • Home_Page
      • PageBaseClass
    • com.us.test.selenium.tests
      • Login_Home
    • com.us.test.selenium.tests.testdata
      • TestData.xls
    • com.us.test.selenium.util
      • BrowserUtils
      • Constant
      • ElementUtils
      • ExcelUtils
      • LIstener
      • Listeners
      • TestLog

 

Classes

com.uc.test.selenium

Main

 

 

 

 

Tags

Java POM: 03-Packages

Packages Schema

Best Practices

  • all lower case names
  • use com.<brandName>.<appType>.<project>
    • the created packages will treat the '.' as a subfolder, yielding:
      • com
        • <brandName>
          • <appType>
            • <project>
  • managing packages this way ensures conflicts won't arise when including other projects for larger ecosystems

 

Tags
Subscribe to Java