Posts

Showing posts from September, 2021

Technologies - Log4J - Plugging Log4j to Code

  Steps to use log4j in your Java application are as follows: Download latest log4j distribution. Add log4j’s jar library into your program’s Build path. Create log4j’s configuration. Initialize log4j with the configuration. Create a logger. Put logging statements into your code. 

Terminologies - Log4J - Components of Logging API & Process Flow

Image
  3 Core Components of Java logging API  Loggers are responsible for capturing events (called LogRecords) and passing them to the appropriate Appender. Appenders (also called Handlers in some logging frameworks) are responsible for recording log events to a destination. Appenders use Layouts to format events before sending them to an output. Layouts (also called Formatters in some logging frameworks) are responsible for converting and formatting the data in a log event. Layouts determine how the data looks when it appears in a log entry. Process Flow: When your application makes a logging call, the Logger records the event in a LogRecord and forwards it to the appropriate Appender.  The Appender then formats the record using a Layout before sending it a destination such as the console, a file, or another application.  Additionally, you can use one or more Filters to specify which Appenders should be used for which events. Filters aren’t required, but they give you gr...

Technologies - Log4J - Create Log4j Configuration File - Where ? How ? What ?

  Typical Steps involved in Creating Log4j Configuration file Configure the root logger - What to Log - info/debug/error/fatal messages Configure individual loggers (if needed). Specify appenders -- Where to Log -- in File/Console, etc Specify message layout/Pattern -- How to Log - format to log the message Configuring a Layout PatternLayout lets you determine how data is extracted from log events and formatted for output based on a conversion pattern. Conversion patterns act as placeholders for data that appears in each log event.  For example, let’s break down a PatternLayout commonly used in Log4j: <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/> %d{HH:mm:ss.SSS} formats the date in terms of hours, minutes, seconds, and milliseconds. %t displays the Logger’s current thread. %level displays the severity of the log event. %logger displays the name of the Logger. %m displays the event’s message. Finally, %n adds a new line for the next e...

Technologies - Log4J - Initializing Logging

Initializing Logging mechanism using Log4J  package com.SeleniumPractise; import org.apache.logging.log4j.*; public class Demo { private static Logger log = LogManager.getLogger(Demo.class.getName()); public static void main(String[] args) { log.debug("Logging a debug message"); log.info("Logging info level"); log.error("Logging Error message"); log.fatal("Fatal error message"); } }

Technologies - Log4J - Download, Eclipse Integration and Usage

Download -  https://www.apache.org/dyn/closer.lua/logging/log4j/2.14.1/apache-log4j-2.14.1-bin.zip Usage  Logs the success action events - successful button click, select checkbox/radio button, etc. Logs failures or exceptions Logs the events with date and timestamp & many more  Only 2 jars are required for our purpose - log4j-api-2.14.1, log4j-core-2.14.1 Eclipse  Extract the Log4j Zip file Navigate to Build path in project Select External Jar files and select the extracted path - then select  log4j-api-2.14.1 & log4j-core-2.14.1 file alone.

Technologies - TestNG Framework - XML File

Technologies - TestNG Framework - Assertions (TBD)

 

Technologies - TestNG Framework - Listeners (TBD)

Technologies - TestNG Framework - Reporting -TBD

Technologies - TestNG Framework - Annotation attributes

  Annotation Attributes - methods of annotations Attributes are keywords that modify the annotation's function.   alwaysrun:                 If set to true, this test method will always be run even if it depends on a method that failed. dataProvider   The name of the data provider for this test method. dataProviderClass           The class where to look for the data provider. If not specified, the data provider will be looked on the class of the current test method or one of its base classes. If this attribute is specified, the data provider method needs to be static on the specified class. dependsOnGroups   The list of groups this method depends on. dependsOnMethods            The list of methods this method depends -Non dependent @test will be executed in Ascii order followed by dependent tests - when a single test is dependent on multiple tests then ...

Technologies - TestNG Framework - Annotations

  List of annotations that TestNG supports: Annotations - are default Interfaces in TestNG @BeforeSuite  The annotated method will be run only once before all tests in this suite have run.   @AfterSuite  The annotated method will be run only once after all tests in this suite have run.   @BeforeClass  The annotated method will be run only once before the first test method in the current class is invoked.   @AfterClass  The annotated method will be run only once after all the test methods in the current class have run.   @BeforeTest  The annotated method will be run before any test method belonging to the classes inside the <test> tag is run.   @AfterTest  The annotated method will be run after all the test methods belonging to the classes inside the <test> tag have run.   @BeforeGroups  The list of groups that this configuration method will run before. This method ...

Selenium - Syncronization

  Synchronization 1.Implicit wait - Global wait and is applied to each Test Step of Test case – Maximum time limit to wait – implicit wait does not catch any performance errors and makes the test execution slow – implicit wait waits up to max timeout specified before throwing any exception. Driver.manage().timeouts().implicitlyWait(10, Timeunit.MILLISECONDS)   2.Explicit wait –Applied to specific Element of a page – Explicit wait is specific to test scenario – doesn’t affect the test execution speed WebDriverWait –> uses built in wait methods Monitors the DOM until Timeout or till the object is found within the specified time   webDriverWait w=new webDriverWait(driver, 10) Fluent Wait -> need to build customized wait methods based on the condition to be met Monitors DOM by polling at regular intervals defined by polling duration time 3.Thread.sleep

Java - URL Connection Test

  HttpURLConnection conn=(HttpURLConnection) new URL( "http://novice-2-professional.blogspot.com/2018/02/testing-process-quick-refresh.html" ).openConnection( )              conn.setRequestMethod( "HEAD" );              conn.connect();              int responseCode = conn.getResponseCode();

Selenium - Screenshots

  File srcFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);             File destFile= new File( "/com.SeleniumPractise/Snaps" );             FileUtils.copyFile(srcFile, destFile);

Selenium - Locators & Element location Strategies

Locators & Element location Strategies  Automating any application requires identification of the element & interact with it. Identification of Element is achieved using locators. contain one or more elements/tags/nodes An element may contain content/data or may contain other elements as child nodes. Each element should have starting tag and ending tag. The element content will reside in between these two tags. Apart from the content each tag may have attributes. These attributes will give extra information about the element. Locator are used for identifying the elements on the web page uniquely   1.       Location strategies by attributes – a.       ID b.       Name c.       Class name - with spaces – not allowed – [Compound class names not allowed error] – when required to identify group of elements like radio buttons, checkboxes 2.    ...

Selenium - Windows Handling

Windows Handling   Set<String> windows = driver.getWindowHandles(); //[parentid,childid,subchildId] Iterator<String>it = windows.iterator(); String parentId = it.next(); String childId = it.next(); driver.switchTo().window(childId);  

Selenium - Keyboard Events

Keyboard Events   Context click to open the Links on page openLnks = Keys.chord(Keys.CONTROL, Keys.ENTER); link.sendKeys(openLnks);   To select the text starting from home to end sendKeys(Keys.HOME, Keys.chord(Keys.SHIFT, Keys.END));

Selenium - Select Class

Select class selectByIndex() selectByVisibleText() selectByValue() Static drop downs How to identify if drop down is static? check if the Tag is Select – element is visible in DOM Dynamic drop downs How to identify if drop down is Dynamic? – element is visible in DOM onload If we select 1 st  drop down, then based on that 2 nd  drop down values will populate Autosuggest On entering few characters suggestion list starts appearing

Selenium - Desired Capabilities & ChromeOptions

Desired capabilities  -- Can be considered as generic chrome profile DesiredCapabilities ch=DesiredCapabilities.chrome(); //ch.acceptInsecureCerts(); ch.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true); ch.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); Used in General when executing remote scripts DesiredCapabilities dc = new DesiredCapabilities(); dc.setBrowserName("chrome"); dc.setPlatform(Platform.WINDOWS); ChromeOptions -- Can be considered as a local browser profile ChromeOptions c= new ChromeOptions(); c.merge(ch); System.setProperty("webdriver.chrome.driver", ""); WebDriver driver=new ChromeDriver(c);

Assertions

Hard Assertion assertFalse assertTrue assertEquals(actual,”expected”)   Soft Assertion SoftAssert s = new SoftAssert(); s .assertTrue( condition , message ); s .assertAll(); - holds all failure asserts from above statement and prints at the end of test execution – so as to avoid script execution termination

Selenium Components

  Selenium Components Selenium is an open source portable framework used to automate testing of web applications. It is highly flexible when it comes to testing functional and regression test cases. Selenium Components ·        Selenium IDE ·        Selenium RC ·        Selenium WebDriver ·        Selenium Grid