Wednesday, 30 August 2017

How to Install Ruby in Windows

Ruby Beginners has the biggest challenge that how to start with Programming language ruby, what will be the initial steps to learn, prerequisite and so on. To solve their huddle, I have written this post. The first thing which you need to do start with Ruby programming language is to install ruby in your system.

Steps to Download:-
  • Link to download the RubyInstaller for Windows
  • Choose your prefer ruby version available for both 32-bit and 64-bit version
  • Follow instruction to setup Ruby on your system
  • Open command and type “ruby -v”, If it provides you your ruby version
  • Congratulations, you have done your ruby system setup

Comment in case you are facing any challenges

Labels: , , ,

Saturday, 26 August 2017

Read and Write Properties File

In this post, I will tell you that how will you implement the utility to read and write the properties file. When you need to design an automation framework there are some utilities which you need to implement for reading and writing different types of files in your framework used for different purposes. The properties file is one of the best ways used to define the system configuration.

Code:-

public class PropFileHandler {

static Properties properties = new Properties();
public String readProperty(String property) {
InputStream inPropFile = null;
try {
inPropFile = new FileInputStream("Directory Path");
properties.load(inPropFile);
} catch (IOException e) {
System.out.println("There was Exception reading the Test data");
}
String value = properties.getProperty(property);
return value;

}


public static void writeProperty(String property, String value) {
try {
InputStream inPropFile = new FileInputStream("File Path");
properties.load(inPropFile);
inPropFile.close();
OutputStream outPropFile = new FileOutputStream("File Path");
properties.setProperty(property, value);
properties.store(outPropFile, null);
outPropFile.close();
} catch (IOException e) {
}
}

}

Thank you for reading my Post. Please like and comment if you like my post.

Labels: , , , ,

Code to take Screen Shots in Selenium WebDriver?


In this post, I will tell you that how would you capture the failure screenshots in Selenium WebDriver. A screenshot is the best way in order to tell the reason of automation script failure. By which a tester get the reason that on which page script gets failed and what was the reason. I am sharing the code of this with you.

Code:-


public class TakeScreenshot {


WebDriver driver;
String screenshotPath = "Your Path";


public void takeScreenshot() {
DateFormat dateFormat = new SimpleDateFormat("yyyy_MM_dd_hh_mm_a");
Date date = new Date();
String date_time = dateFormat.format(date);
File file = new File(System.getProperty("user.dir") + File.separator
+ screenshotPath + File.separator + date_time);
boolean exists = file.exists();
if (!exists) {
new File(System.getProperty("user.dir") + File.separator
+ screenshotPath + File.separator + date_time).mkdir();
}


File scrFile = ((TakesScreenshot) driver)
.getScreenshotAs(OutputType.FILE);
try {
String saveImgFile = System.getProperty("user.dir")
+ File.separator + screenshotPath + File.separator
+ date_time+ File.separator + "screenshot.png";
Reporter.log("Save Image File Path : " + saveImgFile, true);
FileUtils.copyFile(scrFile, new File(saveImgFile));
} catch (IOException e) {
e.printStackTrace();
}
}


public void takeScreenShotOnException(ITestResult result) {
String takeScreenshot = screenshotPath ;
if (result.getStatus() == ITestResult.FAILURE) {
Reporter.log(
"FAILURE occurred at "
+ DateUtil.converttimestamp(System
.currentTimeMillis()), true);
if (takeScreenshot.equalsIgnoreCase("true")
|| takeScreenshot.equalsIgnoreCase("yes")) {
try {
if (driver != null) {
takeScreenshot();
}
} catch (Exception ex) {
Reporter.log("Driver is null while taking screen shot",
true);
}
}
}
}


}


Call this java class in Test class:-

Test Class:-

@AfterMethod
public void snapshot(ITestResult result){
test.takescreenshot.takeScreenShotOnException(result);
}


Labels: , ,

Tuesday, 22 August 2017

How to handle window Authentication Popup using Selenium WebDriver?

In this post, we learned how to handle the window authentications using selenium webDriver. Most of the companies are using this technique to enhance the security of its application. In that case, just before the launch of the application, an authentication pop up come to ask the authorized username and password. HTTP Authentication is the technique to resolve this problem using selenium.


How to implement HTTP Authentication using Selenium WebDriver


You need to append the username and password with the application URL to handle the window authentication pop up.




By using the above URL window authentication pop up will by pass and you can successfully automate that type of situation without any hurdle.


Imp:- You no need to make any changes in the system configuration other that IE browser.
For IE you need to make some changes to overcome the HTTP security of IE browser

Below are the steps to do so:-

For 32 bit OS:
Go to ‘HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_HTTP_USERNAME_PASSWORD_DISABLE‘
Create two new DWORDS iexplore.exe and explorer.exe and make sure their values are 0.
For 64 bit OS:
Go to ‘HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_HTTP_USERNAME_PASSWORD_DISABLE‘
Create two new DWORDS iexplore.exe and explorer.exe and make sure their values are 0.

Thanks, for reading my post. Please do comment in case of any query

Labels: ,

How to handle the windows, frames and pop up in Selenium WebDriver?

In this post, I will explain that how do you handle the multiple windows, frames, and pop-up of an application using Selenium WebDriver. You generally faced these types of a problem of frames, windows, and pop-up in an application. Different tabs are also treated as different windows. In software automation, you need to tell the Selenium WebDriver that where it will search for the element. In which frame window or pop up.


So to handle this situation selenium WebDriver has native methods. I have mentioned below different ways to handle the windows, frames, and pop-up.


How to handle Frames:-

1) Select frame by element
Ex:- driver.switchTo().frame(element);
2) Select frame by id:-
Ex:- driver.switchTo().frame(id);
3) Select frame by index:-
Ex:- driver.switchTo().frame(index);
How to handle Windows:-

1) Select Window From Index
Set<String> windows = driver.getWindowHandles();
System.out.println("Window Size::" + windows.size());
String wins[] = windows.toArray(new String[windows.size()]);
driver.switchTo().window(wins[WindowCountToSwitch]);


2) Close Window From Index
                      Set<String> windows = driver.getWindowHandles();
System.out.println("Window Size::" + windows.size());
String wins[] = windows.toArray(new String[windows.size()]);
driver.switchTo().window(wins[WindowCountToSwitch]);
driver.close();
Note:- WindowCountToSwitch is the count of the window to select or delete


How to handle the Pop Up:-


1)Handle pop Up:-
                       Alert alert = driver.switchTo().alert();
alert.accept();


2)Get Alert Text:-
                      Alert alert = driver.switchTo().alert();
            String message = alert.getText();


3)check for the visibility of Alert:-
                       WebDriverWait wait = new WebDriverWait(driver, 60);
wait.until(ExpectedConditions.alertIsPresent());

Switch to Default/main window or frame:-
driver.switchTo().defaultContent();

Thank you for visiting my blog. Keep in touch.

Labels: , , , , , , , , ,