Thursday, September 25, 2014

Character Encoding in Eclipse

The Problem

Sometime we see texts appearing in Multi language in a webpage like in Google homepage (https://www.google.co.in/) i.e. हिन्दी বাংলা తెలుగు मराठी தமிழ் ગુજરાતી ಕನ್ನಡ മലയാളം ਪੰਜਾਬੀ. If we try to print these texts using Selenium WebDriver in Eclipse Console it might give you weird outputs like ???.

Sample Code:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Test {

       public static void main(String[] args) {
             
           WebDriver driver = new FirefoxDriver();
           driver.get("https://www.google.co.in");

           List<WebElement> links = driver.findElements(By.xpath("//*[@id='addlang']/a"));

           for(int i=0;i<links.size();i++){
              System.out.println(links.get(i).getText());
           }

       }

}

Output
??????
?????
??????
?????
?????
???????
?????
??????
??????

Why this happens

This happens because of character encoding and output may vary from IDE to IDE based on settings placed for Character Encoding. These regional language characters come under UTF-8 Character Set and if your editor have different settings for Character Encoding other than UTF-8, the above problem will appear.

How can I resolve the problem

In Eclipse, we can resolve the problem by setting Character Encoding in the following way:

File level Settings:
Right click on specific file (e.g. Test.java) -> Properties. Under Text file encoding section -> Select Other radio, Select UTF-8 from combo -> Click OK button.

Project level Settings:

Right click on Project -> Properties and then at the Text file encoding section: Select Other radio, Select UTF-8 from combo -> Lastly click OK button.

Eclipse level Settings:

Window -> Preferences -> General -> Workspace. In Text file encoding section : Select Other radio, Select UTF-8 from combo -> Lastly click OK button.

Now, again re-execute the above code. It should give you all the languages like texts. 


Final Output


हिन्दी

বাংলা
తెలుగు
मराठी
தமிழ்
ગુજરાતી
ಕನ್ನಡ
മലയാളം
ਪੰਜਾਬੀ

Hope this helps!

Thursday, September 18, 2014

Mobile Application Testing - Non Functional Approaches

With the tremendous growth of Mobile applications over the past decade or so, testing for both functional and non-functional attributes becoming very critical to get the application a better shape, win the race with other competitors and getting more business done. Here are some of the types of non-functional attributes that we can look into while testing –

GUI & Usability

  • Verify Interface: UI controls in the application like Pop-ups, text boxes, buttons etc. Also layouts and alignments of the interface.
  • Check for Interaction: Behavior of the application with user interactions like Multi touch, Voice Recognition, Tilt behavior etc.
  • Portrait & Landscape: Check behavior of the application in Landscape / Portrait mode.
  • Navigation between screens, text should be visible in supported languages and verification how application behaves when device is online/offline.


Localization
  • Localization testing: Verify application functionality in local languages (Hindi, Bengali, German etc).
  • Interrupt testing: Check how application behaves when Calls, SMS , Low/Critical Battery, Alarms etc are received.
  • Service Provider testing: Check how application behaves with respect to different carriers.


Compatibility
  • With Mobile Browsers (default browser, externally installed browsers).
  • With different mobile device configurations.
  • With Phone Device features (Flip, Camera, Slider etc.).


Mobile Application Performance
Mobile application performance based on different hardware/software configurations.

Tools for Performance testing of Mobile applications:


Referrence : http://www.methodsandtools.com/archive/mobileloadtesting.php

Monday, September 15, 2014

Java - Look for Files under given directory

Using Java utilities we can look for specific files matching specified pattern. Below is a sample:


Path rootDirectory = Paths.get(System.getProperty("user.dir")
+ "\\src\\test\\java");

String fileNamePattern = "*.{txt, doc}";

FileSystem fs = FileSystems.getDefault();
final PathMatcher pathMatcher = fs.getPathMatcher("glob:"fileNamePattern);

FileVisitor<Path> pathMatcherVisitor = new SimpleFileVisitor<Path>() {
    @Override
    public FileVisitResult visitFile(Path file,
    BasicFileAttributes attribs) {
        Path name = file.getFileName();
        if (pathMatcher.matches(name)) {
            System.out.println(String.format("Matched file found: '%s'.", file));
        }
        return FileVisitResult.CONTINUE;
    }
};

Files.walkFileTree(rootDirectory, pathMatcherVisitor);


Hope this helps!