Tuesday, July 7, 2015

EASY TO GET SAFARI WEBDRIVER RUNNING ON MAC OSX


Since this topic has not been well documented on the net and I struggled myself to get Selenium tests running on Safari browser, here are the complete set of steps to get Selenium tests up and running on Safari browsers. :-


Creating “Safari Extension” Developer Certificate

  1. Create an Apple developer account.
  • Go to https://developer.apple.com/
  • Click on “Member Center” on top panel.
  • Select “Create Apple ID”.
  • Go through the sign up forms and provide valid fields for a succesful sign up
2.  Login to created Apple account.
3.  Sign up for “Safari Extensions” developer
  • Click on “Certificates, Identifiers & Profiles”
  • In the “Safari Extensions’ section, click on “Join Now”
  • Go through the following steps and provide valid fields to successfully sign up for the “Safari Extensions” program
4.  Create “Developer Certificate”
  • Now inside “Certificates, Identifiers & Profiles” > “Click on Create/Add Safari Certificate”
  • You will see the following page – “About Creating a Certificate Signing Request (CSR)” 

  • Click on “Continue”


You will see the following page :-


  • Upload the CSR file and Click on ‘Generate’ to generate the certificate
  • Now download the certificate once it is generated.
5. Download the certificate and install in the machine
  • Download the certificate in the download tab.
  • The certificate is downloaded as “safari_extension.cer”.
  • Double-click on the file to install the certificate in the Mac client/OSX.
6.  We have installed the safari extensions certificate for developers. Now we need to install the Safari Webdriver extension for the Safari Browser.

 Installing the Safari Webdriver extension in the Safari Browser

  1. Download latest Selenium Safari extension.
2.  Install the Safari Extension
  • Double-click on the “SafariDriver.safariextz” file.
  • You will get a prompt asking “Are you sure you want to install the extension “WebDriver”?“.
  • Click on “Install”
3.  Provide the default setting for the Selenium Webdriver Extension.
  • Click on “Safari” > “Preferences” > “Extensions” > You will find Selenium extension
  • Select “Enable Webdriver”
Now all the settings are done and now we should be able to launch our Selenium scripts using Safari Webdriver.

Launching Safari Webdriver

Webdriver driver = new SafariDriver();                
driver.get( http://www.google.co.in” );
builder = new Actions(driver);
This should launch your safari browser with the Safari Webdriver Extension. :)
Hope this article comes of use to you all !!

Happy Coding !!



Credits: itisatechiesworld

Saturday, July 4, 2015

ANDROID TESTING EBOOK : EASY TO AUTOMATE ANDROID APP - "ANDROID APPLICATION TESTING GUIDE"

I found this book very helpful for Android Automation Testing concepts. It covers some very good and advanced topics. This book is must read if you are involved in Android Automation, Unit Testing or White box Testing for Android application.

Please note that it may require at least intermediate level of understanding for Android Automation.




Android Application Testing Guide




Enjoy !!

And yes don't forget to buy this book if you like it. :)




Thursday, July 2, 2015

SELENIUM : EASY TO VERIFY PDF FILE TEXT USING JAVA WEBDRIVER

In this post we will explain the procedure to verify PDF file content using java webdriver. As  some time we need to verify content of web application pdf file, opened in browser.
Use below code in your test scripts to get pdf file content.

 //get current urlpdf file url
 URL url = new URL(driver.getCurrentUrl());
                 
 //create buffer reader object
 BufferedInputStream fileToParse = new BufferedInputStream(url.openStream());
 PDFParser pdfParser = new PDFParser(fileToParse);
 pdfParser.parse();

 //save pdf text into strong variable
 String pdftxt = new PDFTextStripper().getText(pdfParser.getPDDocument());
                 
 //close PDFParser object
 pdfParser.getPDDocument().close();

After applying above code, you can store all pdf file content into “pdftxt” string variable. Now you can verify string by giving  in put.  As if you want to verify “Selenium Or Webdiver” text. Use below code.
                 
Assert.assertTrue(pdftxt.contains(“Selenium Or Webdiver”))

Hope this post will help  to verify web application PDF content.


Credits: roadtoautomation blog

Wednesday, July 1, 2015

SELENIUM : WAITING FOR CONDITIONS TO BE AVAILABLE


While testing a very slow loading website, the dreaded "NoSuchElementException" exception can occur even though the element does exist on the page. The problem can be that the code is running faster than the site loads. The "ExpectedCondition" class ensures that the program waits for a designated period of time before throwing the "NoSuchElementException" error message.


In the code below, we navigate to craigslist, take 5 seconds to wait for the required element to appear and be ready for clicking. Then click the element.

WebDriver driver = new FirefoxDriver();

// a slow loading website is good for this text. craigslist is not slow though :)

driver.get("http://london.craigslist.co.uk/");  

// define timeout for waiting period

WebDriverWait wait = new WebDriverWait(driver, 5);    

// ensures the element is available for click. Check for the defined 5 seconds before timeout

WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id='jjj']/h4/a")));   

element.click();

SELENIUM : READ BROWSER CONSOLE LOG


Initialize driver with logging preferences.




DesiredCapabilities caps = DesiredCapabilities.chrome();
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.BROWSER, Level.ALL);
caps.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
driver = new ChromeDriver(caps);
Now analyze log using below code:
LogEntries logEntries = driver.manage().logs().get(LogType.BROWSER);

for (LogEntry entry : logEntries) {
System.out.println(new Date(entry.getTimestamp()) + " " + entry.getLevel() + " " + entry.getMessage());
//do something useful with the data
}