Friday, April 11, 2014

Temp File Management Using WebDriver

Here we try to handle Temp file which is generated by the WebDriver.

Q. Why we need to handle this temp file?
Ans:- It is not necessary it should be deleted automatically,but some time it may not be deleted on      different version of WebDriver, sometime it may be deleted when we quit the driver(using this line driver.quit() to quit the driver) or need to close the driver (using this line driver.close()). If we go to the User Temp(Windows +R then type %temp% to open the user temp.It is a default location to create the temp file for WebDriver) folder we see this two folder should be there after some time unzip60898411...... folder deleted and anonymous folder contains the driver files.

Q. Is there any way to change the temp folder location for WebDriver?

Ans:- Yes,we can change the temp folder location for WebDriver using this line in our code,
        TemporaryFilesystem.setTemporaryDirectory(new File("C:/xyz"));

        if(!new File("C:/XYZ").isDirectory())
        FileUtils.forceMkdir(new File("C:/XYZ"));
        TemporaryFilesystem.setTemporaryDirectory(new File("C:/xyz"));

Q. How to delete this files?

Ans:-Use this line to delete the files.

FileUtils.deleteDirectory(new File("C:/XYZ"));

Q. When we delete this files?

Ans:-We preferred to delete files at @AfterTest or @AfterClass annotation.

Saturday, April 5, 2014

Firefox profile and DesiredCapabilities

Every testing scenario should be executed on some specific testing environment.WebDiver give us this opportunity using Firefox profile and Desired capability.

FireFox Profile

Firefox profile help the tester to execute the test on the particular profile which may be configured previously or may be it configured on run time using Desired Capabilities.


Desired Capability is a series of key/value pairs that encapsulate aspects of a browser means we can set the behavior of the browser on the run time. Basically, the DesiredCapabilities help to set properties for the WebDriver. A typical usecase would be to set the path for the FireFoxDriver if our local installation doesn't correspond to the default settings.

 How to create Profile on FireFox?

          1.Open windows run mode(Windows+R) then type "firefox -p -no-remote"
 -no-remote parameter is optional it is required if we open multiple instance of firefox(it means if we open a firefox and using it then open another one for test purpose).

          2.Click on  Create Profile then click on next

          3.Give a name of the profile and choose the directory path where it will be saved or we can choose the default path.

Now we learn how WebDriver use this Profiles.

Procedure 1:
        ProfilesIni allProfiles = new ProfilesIni();
        FirefoxProfile profile=allProfiles.getProfile("ExTest");

        WebDriver driver = new FirefoxDriver(profile);

FirefoxProfile profile=allProfiles.getProfile("ExTest") here "ExTest" is test profile. 

Here one thing one mind ProfilesIni class load all profiles, this profiles may or may not be saved on default location.

 Procedure 2:

        FirefoxProfile profile=new FirefoxProfile(new File("C:\\Test"));
        WebDriver driver = new FirefoxDriver(profile);

 FirefoxProfile profile=new FirefoxProfile(new File("C:\\Test")); here "C:\\Test" is the path where profile is created.

Now we learn how to use DesiredCapabilities.

        DesiredCapabilities cap=new DesiredCapabilities();
        cap.setCapability("firefox_binary", "G:\\Program Files\\Mozilla Firefox\\firefox.exe");
        WebDriver driver = new FirefoxDriver(cap);

  cap.setCapability("firefox_binary", "G:\\Program Files\\Mozilla Firefox\\firefox.exe");
  We know previously that desired capability is a key value paired, here we can observed that we set the
  Key as "firefox_binary" and value as "G:\\Program Files\\Mozilla Firefox\\firefox.exe".

Keep in mind that we can not create any profile on Internet Explorer but Chrome or Opera browser have the facility to create user profile. We can get more information regarding this from here .