Pages

Thursday, November 28, 2013

Log4J Levels

This log4j post is a tutorial post describing different levels of logging in log4j. This is for log4j beginners only but if you wish to refresh, go ahead and enjoy!
Log4j logger contains three main components namely logger, appender and layout. Logger takes care of the logging mechanism and deals with level of logging. Log4j provides five standard levels of logging. There are two more special levels given by log4j. Above all these, log4j allows you to create custom levels.

Five standard log4j levels

DEBUG Level

This log4j level helps developer to debug application. Level of message logged will be focused on providing support to a application developer.

INFO Level

This log4j level gives the progress and chosen state information. This level will be generally useful for end user. This level is one level higher than DEBUG.

WARN Level

This log4j level gives a warning about an unexpected event to the user. The messages coming out of this level may not halt the progress of the system.

ERROR Level

This log4j level gives information about a serious error which needs to be addressed and may result in unstable state. This level is one level higher than WARN.

FATAL Level

This log4j level is straightforward and you don’t get it quite often. Once you get this level and it indicates application death.

Two special log4j levels

ALL Level

This log4j level is used to turn on all levels of logging. Once this is configured and the levels are not considered.

OFF Level

This log4j level is opposite to ALL level. It turns off all the logging.

New Trace Level added in Log4j

TRACE Level

This log4j level gives more detailed information than the DEBUG level and sits top of the hierarchy. This level is introduced from version 1.2.12 in log4j.

Custom log4j levels

Log4j’s levels are mostly sufficient for all common applications. Rarely you may need a new Level apart from the levels provided by log4j. In that case you can extend org.apache.log4j.Level class and have your own custom level implementation.

Log4j Logger Output

When a logger is created, generally you assign a level. The logger outputs all those messages equal to that level and also all greater levels than it. So the order for the standard log4j levels are:

Log4J Levels

TRACE LevelDEBUG LevelINFO LevelWARN LevelERROR LevelFATAL Level
TRACE LevelYYYYYY
DEBUG LevelNYYYYY
INFO LevelNNYYYY
WARN LevelNNNYYY
ERROR LevelNNNNYY
FATAL LevelNNNNNY
ALL LevelYYYYYY
OFF LevelNNNNNN

Log4j Level Inheritance Rule

There can be instances when you don’t assign a level to the logger. In such cases log4j handles it seamlessly based on the following level inheritance rule:
The inherited level for a given logger C, is equal to the first non-null level in the logger hierarchy, starting at C and proceeding upwards in the hierarchy towards the root logger.
That means, if you have a package as com.foo.bar and you didn’t allocate a level, then it will inherit the level from com.foo package. Still in that package also if the level is not available, then it will inherit from the log4j root level. The log4j’s root logger is instantiated and available always. Log4j’s root logger by default has DEBUG level.

Sample code:

private Logger log = Logger.getLogger(ClassName.class);
public void MyMehodABC()
{
try
{
log.info(“we are in MyMethodABC”);
// code
}
}
For this you have to configure log4j.properties file for configuring where to display this file.
Using log4j you can manage logging mechanism in File, Console etc etc…
catch(Exception e)
{
log.error(e.getMessage(),e);
}

 Configure log4j

1| Download log4j.jar  and add into build path
2| Open src folder under project
3| Create a new text file.
4| Paste the following..

#Application Logs
log4j.logger.devpinoyLogger=DEBUG, dest1
log4j.appender.dest1=org.apache.log4j.RollingFileAppender
log4j.appender.dest1.maxFileSize=5000KB
log4j.appender.dest1.maxBackupIndex=3
log4j.appender.dest1.layout=org.apache.log4j.PatternLayout
log4j.appender.dest1.layout.ConversionPattern=%d{dd/MM/yyyy HH:mm:ss} %c %m%n
log4j.appender.dest1.File=\logs\\SeleniumLogs.log
#do not append the old file. Create a new log file everytime
log4j.appender.dest1.Append=true

5| Save it with an extension, '.properties'. e.g., log4j.properties
6| Now, log through the script as shown below.

public class classname {
private static Logger Log = Logger.getLogger(classname.class);

@BeforeTest
public void setUp() throws Exception {
Log.info("_______started server_______");
Log.warn("Warn");
baseUrl = "https://qa.knewknovel.com";    
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
    
@Test
public void testAbi() throws Exception {
driver.get(baseUrl + "/web/browse.v");
Log.info("_______Test Inprogress_______");
}
    
@AfterTest
public void tearDown() throws Exception {    
Log.info("_______Stopping server_______");
driver.quit();
}
}

6| Execute the test and check the log file, SeleniumLogs.log under

How to capture the URL of the 'about to' download file on a browser



You can detect a downloading event with chrome.downloads.onCreated listener and perevent it with chrome.downloads.cancel method.

But chrome.downloads API is expiremental and only works on chrome dev channel version for now.

chrome.downloads.onCreated.addListener(function(DownloadItem downloadItem) {
   chrome.downloads.cancel(downloadItem.id , function() {
       console.log("Download was cancelled")
   });
});

HelpFulLink:

https://docs.google.com/document/d/12rNimeeGaA8jEV60PPKtT4pmJYmY9ae_edl3hJyoXYE/edit?hl=en_US

JavaScript code in Chrome extensions can be divided in the following groups:

Extension code - Full access to all permitted chrome.* APIs.
This includes the background page, and all pages which have direct access to it via chrome.extension.getBackgroundPage(), such as the browser pop-ups.

Content scripts (via the manifest file or chrome.tabs.executeScript) - Partial access to some of the chrome APIs, full access to the page's DOM (not to any of the window objects, including frames).
Content scripts run in a scope between the extension and the page. The global window object of a Content script is distinct from the page/extension's global namespace.

Injected scripts (via this method in a Content script) - Full access to all properties in the page. No access to any of the chrome.* APIs.
Injected scripts behave as if they were included by the page itself, and are not connected to the extension in any way. See this post to learn more information on the various injection methods.

To send a message from the injected script to the content script, events have to be used. See this answer for an example. Note: Message transported within an extension from one context to another are automatically (JSON)-serialised and parsed.

In your case, the code in the background page (chrome.tabs.onUpdated) is likely called before the content script script.js is evaluated. So, you'll get a ReferenceError, because init is not .

Also, when you use chrome.tabs.onUpdated, make sure that you test whether the page is fully loaded, because the event fires twice: Before load, and on finish:

//background.html
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
    if (changeInfo.status == 'complete') {
        // Execute some script when the page is fully (DOM) ready
        chrome.tabs.executeScript(null, {code:"init();"});
    }
});

How to Take screenshot when it is minimized using selenium webdriver




Following code will work like charm in Selenium

public void  takeScreenshot(String Name)
{
try
{
RemoteWebDriver augmentedDriver =(RemoteWebDriver) new Augmenter().augment(driver);
File screenshot = ((TakesScreenshot)augmentedDriver).getScreenshotAs(OutputType.FILE);
new File(WD_Components.outputDirectory+"//ScreenShot").mkdir();
FileUtils.copyFile(screenshot, new File(WD_Components.outputDirectory+"//ScreenShot//"+Name+".jpg"));
setLog("INFO", "Successfully taken the screenshot");
}

catch (Exception e) 
{
// TODO: handle exception
setLog("ERROR", "Not taken the screenshot"+e);
}
}
Augment()

//Enhance the interfaces implemented by an instance of the RemoteWebDriver based on the returned Capabilities of the driver. Note: this class is still experimental. Use at your own risk.

Below code will help to capture the screenshot of specific element in Selenium(Partial)

public class Shooter{

    private WebDriver driver;

    public void shootWebElement(WebElement element) throws IOException  {

        File screen = ((TakesScreenshot) this.driver).getScreenshotAs(OutputType.FILE);

        Point p = element.getLocation();

        int width = element.getSize().getWidth();
        int height = element.getSize().getHeight();

        BufferedImage img = null;

        img = ImageIO.read(screen);

        BufferedImage dest = img.getSubimage(p.getX(), p.getY(), width,   
                                 height);

        ImageIO.write(dest, "png", screen);

        File f = null;

        f = new File("S:\\ome\\where\\over\\the\\rainbow");

        FileUtils.copyFile(screen, f);

    }

}


It will Maximize the window and take the screenshot

File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
// Now you can do whatever you need to do with it, for example copy somewhere
FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));



Below code will help to reduce the image file size using Java


In addition to scaling the image per Hovercraft Full of Eels answer, you can experiment with setting the jpeg quality to something less than the default:

Iterator iter = ImageIO.getImageWritersByFormatName("jpeg");
ImageWriter writer = (ImageWriter)iter.next();
ImageWriteParam iwp = writer.getDefaultWriteParam();
iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
iwp.setCompressionQuality(0.5);   // integer between 0 and 1

Also, depending on the type of screenshots you are taking, you might find some file size reduction by using a different image file format based on palettes, such as PNG(8-bit) or GIF. These formats can use less file size as compared to jpeg when the image contains limited set of colors that occur in frequent blocks of the same color. ...like many traditional GUI application screenshots.

Recording Screencast of Selenium Tests



I was looking for ways to record a video/screencast of Selenium Test Run in Java and came across this brilliant tool called Monte Media Library developed by Werner Randelshofer. This post describes using the ScreenRecorder class from Monte Media Library for recording screencast of Selenium Tests in Java.
Little about ScreenRecorder
ScreenRecoder supports “AVI” and “QuickTime” format for recording the video. For “AVI” format you need to install TSCC Codec (Techsmith Screen Capture Codec) while “QuickTime” format is supported by Apple’s QuickTime Player. ScreenRecorder provides multiple configurations for colors, mouse cursor, screen rate, mouse rate, audio etc. on GUI as well as programmatically.
You need to download ScreenRecorder.jar file from Monte’s Home Page. ScreenRecorder.jar can be launched as a standalone GUI for recording actions from Desktop window or you can add this to your project and import ScreenRecorder class for recording screen video programmatically.
Using ScreenRecorder Class
Following example is created in Eclipse and you need to add ScreenRecorder.jar to the build path of Project.
ScreenRecorder.jar contains ScreenRecorder class which can be called from a Selenium Script for recording the test session in following way:
2| Add MonteScreenRecorder.jar into buildpath
3| Locate startRecording() and stopRecording() on apt location
4| Run the test
5| After finishing testrun check the location, C:\Users\username\Videos for recorded video, "ScreenRecording 2013-10-18 at 15.01.43.avi"

import java.awt.*;
import org.monte.media.Format;
import org.monte.media.math.Rational;
import static org.monte.media.AudioFormatKeys.*;
import static org.monte.media.VideoFormatKeys.*;
import org.monte.screenrecorder.ScreenRecorder;

public class className {
private ScreenRecorder screenRecorder;

@Test
public void test01() throws Exception {
className videoRecord = new className();
videoRecord.startRecording(); //Started recording
driver.get("www.xyz.com");
Thread.sleep(2000);
videoRecord.stopRecording(); //Stopped recording

}


 public void startRecording() throws Exception
     
GraphicsConfiguration gc = GraphicsEnvironment
              .getLocalGraphicsEnvironment()
              .getDefaultScreenDevice()
              .getDefaultConfiguration();

this.screenRecorder = new ScreenRecorder(gc,
              new Format(MediaTypeKey, MediaType.FILE, MimeTypeKey, MIME_AVI),
              new Format(MediaTypeKey, MediaType.VIDEO, EncodingKey, ENCODING_AVI_TECHSMITH_SCREEN_CAPTURE,
                   CompressorNameKey, ENCODING_AVI_TECHSMITH_SCREEN_CAPTURE,
                   DepthKey, 24, FrameRateKey, Rational.valueOf(15),
                   QualityKey, 1.0f,
                   KeyFrameIntervalKey, 15 * 60),
              new Format(MediaTypeKey, MediaType.VIDEO, EncodingKey, "black",
                   FrameRateKey, Rational.valueOf(30)),
              null);
this.screenRecorder.start();    
}

public void stopRecording() throws Exception
{
this.screenRecorder.stop();

}
The ScreenRecorder captures screen interactions like a charm which can be very useful for analysing Selenium Tests.

Wait Types and Examples in Selenium

Explicit and Implicit Waits
Waiting is having the automated task execution elapse a certain amount of time before continuing with the next step.

Explicit Waits
An explicit waits is code you define to wait for a certain condition to occur before proceeding further in the code. The worst case of this is Thread.sleep(), which sets the condition to an exact time period to wait. There are some convenience methods provided that help you write code that will wait only as long as required. WebDriverWait in combination with ExpectedCondition is one way this can be accomplished.

java code:
WebDriver driver = new FirefoxDriver();
driver.get("http://somedomain/url_that_delays_loading");
WebElement myDynamicElement = (new WebDriverWait(driver, 10))
  .until(ExpectedConditions.presenceOfElementLocated(By.id("myDynamicElement")));

This waits up to 10 seconds before throwing a TimeoutException or if it finds the element will return it in 0 - 10 seconds. WebDriverWait by default calls the ExpectedCondition every 500 milliseconds until it returns successfully. A successful return is for ExpectedCondition type is Boolean return true or not null return value for all other ExpectedCondition types.

This example is also functionally equivalent to the first Implicit Waits example.

Expected Conditions
There are some common conditions that are frequently come across when automating web browsers. Listed below are Implementations of each. Java happens to have convienence methods so you don’t have to code an ExpectedCondition class yourself or create your own utility package for them.

Element is Clickable - it is Displayed and Enabled.

java
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("someid")));
python
The ExpectedConditions package (Java) (Python) (.NET) contains a set of predefined conditions to use with WebDriverWait.

Implicit Waits
An implicit wait is to tell WebDriver to poll the DOM for a certain amount of time when trying to find an element or elements if they are not immediately available. The default setting is 0. Once set, the implicit wait is set for the life of the WebDriver object instance.

java
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://somedomain/url_that_delays_loading");
WebElement myDynamicElement = driver.findElement(By.id("myDynamicElement"));



To wait for element to display following code will  perform this by  using java selenium methods

for(int waittime=1;waittime<=60;waittime++)
{
if(driver.findElement(By.xpath(locator)).isDisplayed())
{
break;
}
else
{
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
 
e.printStackTrace();
}
}
}

Wednesday, November 27, 2013

Drag & Drop in Selenium webdriver

//Sample code

source=driver.findElement(By.xpath("//div[@id='first_row']//span[.='Zip/Postal Code']"));

        WebElement target=driver.findElement(By.xpath("/html/body/div[6]/div[3]/div/div/div/div[2]/ul"));
       
             
        Actions builder = new Actions(driver);
           
        Action drag =builder
          .moveToElement(source)
          .clickAndHold(source)
          .moveToElement(target)
          .build();
          drag.perform();


        Action release = builder

        
          .release(target)
          .build();
         release.perform();

 In another way

    Actions builder = new Actions(driver);
    Action dragAndDrop = builder.dragAndDrop(source Elementtarget Element).build();
    dragAndDrop.perform();

Drop down Select in WebDriver


In web application we see many drop down lists for many input fields (Ex : gender, age, country..etc). This drop down option is different from normal text/numeric input field. It has separate tag <select></select>in html.

In automation while filling most of the forms we need to fill/select the drop down values also. For achieving this WebDriver has separate class called Select.

In this post we will see what are all different method available in Select class.

Consider below example

                  HTML CODE
                                         <select id="city">
                                               <option value="Op1">Chennai</option>
                                               <option value="Op2">Hyderabad</option>
                                               <option value="Op3">Bangalore</option>
                                         </select>

Select an Option
Available methods for selecting an option are
  1. selectByIndex(int index)
  2. selectByValue(java.lang.String value)
  3. selectByVisibleText(java.lang.String text)
selectByIndex(int index)
Select the option at the given index.
Usage :
new Select(driver.findElement(By.id("city"))).selectByIndex(2);
In above example it will select the Hyderabad because it is in index 2.

selectByValue(java.lang.String value)
Select all options that have a value matching the argument.
Usage :
new Select(driver.findElement(By.id("city"))).selectByValue("Op3");
In above example it will select the Bangalore  based on the value attribute of that option.

selectByVisibleText(java.lang.String text)
Select all options that display text matching the argument.
Usage :
new Select(driver.findElement(By.id("city"))).selectByVisiableText("Chennai");
In above example it will select the Chennai based on the visible text.


De-select an option
Available methods for de-selecting an option(s) are,

  1. deselectAll()
  2. deselectByIndex(int index)
  3. deselectByValue(java.lang.String value)
  4. deselectByVisibleText(java.lang.String text)
deselectAll()
  • Clear all selected entries.
deselectByIndex(int index)
  • Deselect the option at the given index.
deselectByValue(java.lang.String value)
  • Deselect all options that have a value matching the argument.
deselectByVisibleText(java.lang.String text)
  • Deselect all options that display text matching the argument.


Getting all options
Some times we may in need to get all the options available in drop down list in that case below method will be useful.

  • getOptions();
getOptions()
It will return All options belonging to this select tag
Usage :
List<WebElement> allCities=new Select(driver.findElement(By.id("city"))).getOptions();
for(WebElement city:allCities)
{
      System.out.println(city.getText());    //It will return the text of each option
      System.out.println(city.getAttribute("value"));    //it will return the value attribute of each option
}

Get Selected Option(s)
If you want to verify whether the proper value got selected in particular drop down list you can make use of below methods.


  1. getFirstSelectedOption();
  2. getAllSelectedOptions() ;
getFirstSelectedOption();
  • The first selected option in this select tag (or the currently selected option in a normal select)
getAllSelectedOptions() ;
  • It will return List of All selected options belonging to this select tag. (This will be useful for multiselect picklist)

Handling multi-select pick list

                 HTML CODE
                                         <select id="city" multiple>
                                               <option value="Op1">Chennai</option>
                                               <option value="Op2">Hyderabad</option>
                                               <option value="Op3">Bangalore</option>
                                         </select>


Handling multi select pick list same as normal drop down( single pick list).
For selecting both Hyderabad, Bangalore option you need to use one of the below logics.

new Select(driver.findElement(By.id("city"))).selectByIndex(2);
new Select(driver.findElement(By.id("city"))).selectByIndex(3);
Or
new Select(driver.findElement(By.id("city"))).selectByvalue("Op2");
new Select(driver.findElement(By.id("city"))).selectByvalue("Op3");
Or
new Select(driver.findElement(By.id("city"))).selectByVisiableText("Hyderabad");
new Select(driver.findElement(By.id("city"))).selectByVisiableText("Bangalore");


I hope you understand WebDriver Select class usage in automation.

To Kill the process to avoid the system slow in Java

 public static void killProcessingExe( String processName)
   {
 try
 {

    final String KILL = "taskkill /IM ";
    Runtime.getRuntime().exec(KILL + processName);
    setLog("Info","Killed the IE.exe");
    Thread.sleep(3000); //Allow OS to kill the process
 }
 catch (Exception e) {
// TODO: handle exception
 setLog("Error",e.toString());
}

   }

Zoom in & Zoom out [Windows | MAC]


Zoom in

WebElement html = driver.findElement(By.tagName("html"));
html.sendKeys(Keys.chord(Keys.CONTROL, Keys.ADD));

Zoom out

WebElement html = driver.findElement(By.tagName("html"));
html.sendKeys(Keys.chord(Keys.CONTROL, Keys.SUBTRACT));


Zoom 100%

WebElement html = driver.findElement(By.tagName("html"));
html.sendKeys(Keys.chord(Keys.CONTROL, "0"));

Zoom Feature on MAC

WebElement html = driver.findElement(By.tagName("html"));
html.sendKeys(Keys.chord(Keys.COMMAND, Keys.ADD));
html.sendKeys(Keys.chord(Keys.COMMAND, Keys.SUBTRACT));
html.sendKeys(Keys.chord(Keys.COMMAND, Keys."0"));

How to avoid full page load | Webdriver


Clicking an Element on page load is even possible on webdriver; By default, webdriver wait for the entire page to load and then picks the element. The links and texts are visible but they are not clickable; However, it works well on Selenium IDE picking elements on page load.

Webdriver make use of the FirefoxProfile to avoid such risks; It's applicable only for Firefox browser.

FirefoxProfile fp = new FirefoxProfile();
fp.setPreference("webdriver.load.strategy", "unstable");
driver = new FirefoxDriver(fp);
baseUrl = "http://xyz.com";
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);


driver.navigate().to("http://xyz.com");
driver.findElement(By.xpath(Value)).click();
System.out.println("Button got clicked");

Selenium Fundamentals


1| Maximize Firefox browser window using selenium webdriver

WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();

2| Customize browser window size

driver.manage().window().setSize(new Dimension(320, 480));


3| Get current web page URL

System.out.println(driver.getCurrentUrl());


4| Navigate Back | Forward & Page refresh

Navigate Back
Webdriver driver = new FirefoxDriver();
driver.navigate().back();
(or)
Actions actions = new Actions(driver);
actions.sendKeys(Keys.BACK_SPACE).perform();

Navigate Forward
driver.navigate().forward();

Page Refresh
driver.navigate().refresh();
(or)
Actions actions = new Actions(driver);
actions.keyDown(Keys.CONTROL).sendKeys(Keys.F5).perform();


5| Highlighting Elements

WebElement element1 = driver.findElement(By.className("Value"));
WebElement element2 = driver.findElement(By.id("Value"));
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("arguments[0].setAttribute('style', arguments[1]);", element1, "color: blue; border:2px solid blue;");
jse.executeScript("arguments[0].setAttribute('style', arguments[1]);", element2, "color: yellow; border: 0px solid red;");


6| Double-click WebElement

Actions action = new Actions(driver);
action.doubleClick(driver.findElement(By.id("Value")));
action.perform();


7| Delete All Cookies

driver.manage().deleteAllCookies();

8| All Old versions of IDE available on:

http://release.seleniumhq.org/selenium-ide/

Page Scroll using Selenium WebDriver


Using JavaScript


Scroll Down:

import org.openqa.selenium.JavascriptExecutor;
WebDriver driver = new FirefoxDriver();
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("scroll(0, 250)"); //y value '250' can be altered

Scroll up:

JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("scroll(250, 0)"); //x value '250' can be altered

Scroll bottom of the Page:

JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("window.scrollTo(0,Math.max(document.documentElement.scrollHeight,document.body.scrollHeight,document.documentElement.clientHeight));");
(or)
Actions actions = new Actions(driver);
actions.keyDown(Keys.CONTROL).sendKeys(Keys.END).perform();

Full scroll to bottom in slow motion:

for (int second = 0;; second++) {
        if(second >=60){
            break;
        }
            ((JavascriptExecutor) driver).executeScript("window.scrollBy(0,400)", ""); //y value '400' can be altered
            Thread.sleep(3000);
}
(or)
JavascriptExecutor jse = (JavascriptExecutor)driver;
for (int second = 0;; second++) {
        if(second >=60){
            break;
        }
            jse.executeScript("window.scrollBy(0,800)", ""); //y value '800' can be altered
            Thread.sleep(3000);
}

Scroll automatically to your WebElement:

Point hoverItem =driver.findElement(By.xpath("Value")).getLocation();
((JavascriptExecutor)driver).executeScript("return window.title;");    
Thread.sleep(6000);
((JavascriptExecutor)driver).executeScript("window.scrollBy(0,"+(hoverItem.getY())+");"); 
// Adjust your page view by making changes right over here (hoverItem.getY()-400)
(or)
((JavascriptExecutor)driver).executeScript("arguments[0].scrollIntoView();", driver.findElement(By.xpath("Value')]")));
(or)
WebElement element = driver.findElement(By.xpath("Value"));
Coordinates coordinate = ((Locatable)element).getCoordinates(); 
coordinate.onPage(); 
coordinate.inViewPort();



Using KeyBoard



We have two options for scrolling in web page.

Using Actions Class

package name  : org.openqa.selenium.interactions.Actions

java code :
                      Ctrl+End | Scroll to Bottom of the page
                     Actions actions = new Actions(driver);
                     actions.keyDown(Keys.CONTROL).sendKeys(Keys.END).perform();

Without Using Actions Class

java code :

                     for(int i=0;i<10;i++)
                    {
                             driver.findElement(By.tagName("body")).sendKeys(Keys.DOWN);
                    }