Posts

Solaris : Send mail with attachment

Use following command to send email with attachment in Solaris from command line

uuencode logfile.zip logfile.zip | mailx -s "Mail subject" myid@company.com

uuencode - Encodes file into Base64 so that it can be send as attachment with a mail.

mailx - Email client available in Solaris. Use -s option to specify mail subject.

This is useful for sending log files from server as attachment. This works for me in Solaris 10. It should be same for other versions also.

Selenium WebDriver : Generating IEDriverServer logs

Selenium 2 (WebDriver) uses Windows executable file IEDriverServer.exe to communicate with InternetExplorer. In the event of any issues with IEDriverServer.exe, logs should be generated for the executable. In Java one can use following code to generate log file from IEDriverServer.exe.

    InternetExplorerDriverService.Builder service =
new InternetExplorerDriverService.Builder();
        service = service.withLogLevel(InternetExplorerDriverLogLevel.TRACE);
        service = service.withLogFile(new File("c:\\logs\\selenium.log"));
        WebDriver driver = new InternetExplorerDriver(service.build());

This generates logs with log level of TRACE and is saved to file at path C:\logs\selenium.log

java.util.logging - Bad level value for property: org.openqa.level

Bad level value for property: some.package.name.level

    The above error is produced by java.util.logging.LogManager when the log level is invalid. for eg. you might have specified a log level of DEBUG and DEBUG is not a valid log level in java.util.logging.

org.openqa.level=DEBUG

    Valid log levels in java.util.logging are SEVERE, WARNING, INFO, CONFIG, FINE, FINER, FINEST, ALL, OFF

    Correct usage is
org.openqa.level=FINE

Fast Git clone using shallow cloning

If you want to get a read only copy of a Git repository quickly you can do a shallow clone. To make a shallow clone use argument --depth 1 along with git command line version.

git clone https://code.google.com/p/selenium/  --depth 1

When doing a shallow clone with depth of 1, it tells Git to fetch only latest revision of a repository. Normal clone fetches entire history of a Git repository. As per Git documentation, you cannot clone or fetch from it, nor push from nor into it.

Shallow clone is useful when you have a slow network connection or you want to save on the network usage.

Viewing Google Code Git repository versions in plain text

Google provides plain text version of Git repository at different URL. This URL is in the format of projectname.googlecode.com/git. This gives latest version of Git repository. To view history of a particular version use URL pattern projectname.googlecode.com/git-history/versionnumber. Using this we can see a particular tagged version or a particular commit version files.

For eg. Selenium version 2.28 can be viewed using

https://selenium.googlecode.com/git-history/6322c139ceec

Version number can be obtained using Browse option in the source menu of main project which can be accessed using URL pattern code.google.com/p/projectname/source/browse/

Downloading source code from SVN/Git repository over HTTP

    Sites hosting open source projects provides an online viewer for browsing source code without actually checking out source code using SVN/Git clients. Checking out entire repository will take long time. Also with Git there is no straight forward way to checkout only a particular directory. Cloning Git repos takes long time as Git downloads entire repository to local machine. Even with sparse checkout, Git downloads entire repository. When bandwidth is a concern, one cannot checkout entire repository.

    One can use GNU Wget to recursively download files from online code repositories. For windows this can be downloaded from http://users.ugent.be/~bpuype/wget/

    Command to download a directory and its child directories and all files in it recursively excluding index.html is below. This will not download parent directories and files from external sites.

wget --cut-dirs=2 --level=15 --include-directories=src/main/java --recursive --no-parent --no-host-directories --reject=index.ht…

java.io.Console broken in Eclipse

Today I discovered that java.io.Console doesn't work when running application inside Eclipse. I was writing a trivial application that accepts some configuration from console. On trying to run this in Eclipse I was getting NullPointerException.as the Console object was null. I used Eclipse Indigo(3.6) version. On Googling found that there is an open bug and is not fixed. Looks like nobody ever planned to fix it.See bug 122429 for detail.

User XIMES commented a workaround solution in the bug. It is to use BufferedReader by passing System.in as the input stream. Also to write one can use PrintWriter by passing System.out as the output stream.

Downside to this workaround is that it cannot mast passwords which can be done by java.io.Console. Alternatively one can also look at using java.util.Scanner. One issue I found with Scanner is that pressing enter key is not considered as input and had to enter some value other than carriage return key.

Sample usage

public static void main(Strin…