Advertise

Saturday, August 25, 2012

Screen Shot capture using selenium and storing with test method name

Taking Screen Shot using Selenium Webdriver.

Sample example to  help all in taking screen shot using selenium webdriver. It has been quit sometime i stopped posting update in my blog. 

So, Found this way to update this blog.Few more to come.






import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
import org.testng.ITestNGMethod;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Listeners;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import org.testng.reporters.JUnitReportReporter;


/**
 *  Sample Test Case to show case how screen shot can be captured and stored with name of
 *  Test method. This would be useful when multiple test method are present in single java file
 */

@Listeners(SeleniumRunnerExample.class)
@Test(groups={"Sample1"})
public class SeleniumRunnerExample extends JUnitReportReporter
{
    WebDriver driver = null;
    ITestNGMethod method;


    @BeforeSuite
    public void driverInstantiationTest(){              
        ProfilesIni allProfiles = new ProfilesIni();
    
      // Creating custom profile of Firefox and referring to same.

        FirefoxProfile profile = allProfiles.getProfile("UIAutomation");

        //UIAutomation refer to profile created by user.This custom profile will be invoked by               
        //Webdriver for performing required activity on browser.

        profile.setAcceptUntrustedCertificates(false);

     
       // Setting whether to accept untrusted Certificate or Not.

        driver = new FirefoxDriver(profile);

       // New instance of Firefox driver with custom profile

        driver.get("https://www.example.com");
    
       // Opening https://www.example.com. Here https://www.example.com is just for example       
       // Purpose
      
    }  

  
    @Parameters({"url"})               //Parameter that is retrieved from "testng-suite.xml"
    @Test(description="Clear description of what this test method is doing should be updated here")
    public void exampleTest(String url){
    /**
     *   Sample implementation part should be written here.
     *
     * */
    }
  
    //takeScreenShotTest is having @ AfterMethod annotation. Since i want to take screen shot after      //each test case has been Run. So as to know where it terminated at last.



    @AfterMethod(description="Takes screen shot")
    public void takeScreenShotTest(ITestResult result) throws IOException{
        File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
        FileUtils.copyFile(scrFile, new File("D:\\\test-output\\screenshot"+result.getMethod().getMethodName()+".png"));
    }
  
    @AfterSuite
    public void closeBrowser(){
        driver.quit();
    }

}

Saturday, March 17, 2012

Which part of Selenium is appropriate for me?

  • Selenium IDE


Selenium IDE is an integrated development environment for Selenium scripts. It is implemented as a Firefox extension, and allows you to record, edit, and debug tests. Selenium IDE includes the entire Selenium Core, allowing you to easily and quickly record and play back tests in the actual environment that they will run.

Selenium IDE is not only recording tool: it is a complete IDE. You can choose to use its recording capability, or you may edit your scripts by hand. With autocomplete support and the ability to move commands around quickly, Selenium IDE is the ideal environment for creating Selenium tests no matter what style of tests you prefer.


Features:


  • Easy record and playback
  • Intelligent field selection will use IDs, names, or XPath as needed
  • Autocomplete for all common Selenium commands
  • Walk through tests
  • Debug and set breakpoints
  • Save tests as HTML, Ruby scripts, or any other format
  • Support for Selenium user-extensions.js file
  • Option to automatically assert the title of every page
  • NEW! Easy customization through plugins.


What is Selenium?

Selenium automates browsers. That's it. What you do with that power is entirely up to you. Primarily it is for automating web applications for testing purposes, but is certainly not limited to just that. Boring web-based administration tasks can (and should!) also be automated as well.

Selenium has the support of some of the largest browser vendors who have taken (or are taking) steps to make Selenium a native part of their browser. It is also the core technology in countless other browser automation tools, APIs and frameworks.

Sunday, December 18, 2011

My Favourite vedios


Sometime its good to remember old technologies rather than leaving them behind.


As always said "Old is Gold". Old gave today gold. In Terms of technology.

My Favourite Vedio

Technology we forgot. Please check whether you remember this or not.

Sunday, February 27, 2011

HOW TO CONFIGURE VSFTPD WITH CHROOT ENABLE

HI Guys,


This session is for configuring chroot JAIL and locking the user to his home directory.

First step is to open the vsftpd configuration file.And uncomment below line .

#vim /etc/vsftpd/vsftpd.conf

##########################################################################
anonymouse_enable=no
local_enable=Yes
write_enable=yes
local_umask=022
dirmessage_enable=yes
xferlog_enable=yes
connect_from_port_20=yes
ascii_upload_enable=yes
ascii_download_enable=yes
chroot_local_user=YES
pam_service_name=vsftpd
userlist_enable=yes
tcp_wrapper=yes
##########################################################################


And now save the changes and restart the vsftpd service.

#/etc/init.d/vsftpd restart.

Now login to your ftp account and check .You should now will not be able to come out of your home directory.


Hope this session was interesting and should be help for the beginner in the Linux.

Regards
Ram kumar

Saturday, February 26, 2011

HOW TO CONFIGURE VSFTPD AND ENABLE FTP SERVER

HI GUYS.

This i am going to give an steps that need to be follow to configure VSFTPD BASED FTP SERVER WITHOUT CHROOT JAIL ENVIRONMENT.

Please install few vsftpd related packages in the Linux Box as mentioned below

#yum install vsftpd.

Now please configure vsftpd file as mentioned below .

#vim /etc/vsftpd/vsftpd.conf

now uncomment below line to make the ftp server operational.
##########################################################################
anonymouse_enable=no
local_enable=Yes
write_enable=yes
local_umask=022
dirmessage_enable=yes
xferlog_enable=yes
connect_from_port_20=yes
ascii_upload_enable=yes
ascii_download_enable=yes
pam_service_name=vsftpd
userlist_enable=yes
tcp_wrapper=yes
##########################################################################

Now after this restart vsftpd service to let the changes get reflected.

#/etc/init.d/vsftpd restart


Now access the ftp account from ftp tools or from browser.
And in case even after that you are not able to access your ftp home directory then please issue below command in the terminal to allow access to ftp home directory.

#setsebool -P ftp_home_dir 1


this should fix the issue and Hope this article give some good stuff for the beginner in Linux.

Regards
Ram kumar