Monday, February 23, 2015

While writing functional test cases using selenium tearDown() method is one of the greatest functionality/place to do all cleanup actions. This method called immediately after the test method has been called and the result recorded. This is called even if the test method raised an exception, so the implementation in subclasses may need to be particularly careful about checking internal state. Any exception raised by this method will be considered an error rather than a test failure. This method will only be called if the setUp() succeeds, regardless of the outcome of the test method. The default implementation does nothing. 

So instead of adding screenshots functionality in each test cases, we can add this functionality in tearDown method as follows:

def tearDown(self):
        if sys.exc_info()[0]:
            test_method_name = self._testMethodName
            now = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
            self.driver.save_screenshot(os.getcwd() +'/screenshots/' + test_method_name + "-" + now + ".png")
--

Make sure to import following packages for above code.

from selenium import webdriver
from datetime import datetime
import os 



Blogger Tricks
When we click on a link which open a new window, getting focus at currently opened windows is not straightforward in selenium. The main issue with it is that the new window may or may not have a WINDOWNAME that can be used by the webdriver function switch_to_window(WINDOWNAME).

 If the new window has been opened by a code snippet such as,

<a href="http://www.qanepal.com/" target="_blank">Subscribe</a>

then the name is randomly assigned, and you’ll need to use code as shown below to find it’s name.

current_windows = self.driver.window_handles

# This is the code which open new windows.
self.driver.find_element_by_link_text("Subscribe").click()

new_windows = self.driver.window_handles
new_window = list(set(new_windows) - set(current_windows))[0]
self.driver.switch_to_window(new_window)


If you can modify the source html or influence the developers to do so, it would be nice to have a proper name assigned to the new window. This can be done by using a named target; eg:

<a href="http://some-link/" target="mytarget">some link</a>

Now, when the new window is opened, you can use it’s name explicitly in code, such as

driver.switch_to_window('mytarget')

Wednesday, July 09, 2014


If you face this problem, probably you are using Ant tasks that include the javac task for compiling Java source. This simply means that Ant could not find a Java compiler.

BUILD FAILED
D:\research\ant\firstbuild\build.xml:9: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "C:\Program Files\Java\jre7"

Total time: 0 seconds

For Eclipse user you can add items to Ant’s class-path from the Ant > Runtime preference page. If you launch Eclipse by using a full JDK instead of a JRE, tools.jar should appear on the Ant class-path automatically.


Thursday, July 03, 2014

Today, I just tried to install a sample CodeIgniter project in  LAMPP (Ubuntu) machine. I received a following error message in browser, when I try to browse the application.

Message shows some how I am not able to connect to database. I checked the configuration at /opt/lampp/htdocs/doasoil/core/application/config/database.php (path will be different in your case) and everything seems OK to me.

Thursday, June 26, 2014



"There is no security on this earth; there is only opportunity." Are you often engage in million dollars deal, if your answer is yes then Beware eavesdropping attackers and opportunistic are sniffing your call! The Prism surveillance scandal has shown that the NSA and other agencies can tap into most communication channels.


In such a case, security is paramount and for that, RedPhone an open source app Licensed under the GPLv3: http://www.gnu.org/licenses/gpl-3.0.html

Wednesday, June 25, 2014

I am not sure whether the features is available for all version of virtual box, so first confirm that the version of virtual box you have.Mine version is 4.3.6 and features is already available, and following steps will guide you to share file between host to guest and vice-verse.

1. Open "Oracle VM Virtual Box" manager and click on "Shared Folders" link where you can adds a new shared folder definition.Following figure will help you to visualize this.




2. In Add Share form you can mention the "Folder Path" i.e the location you want to share, "Folder Name" which is a name used to identify from guest side. Also do not forget to check "Auto Mount" and "Make Permanent" option otherwise you need to do this manually later from command line.



That's it now you can start the Virtual Machine, if it is already started you have to reboot it to make the mount volume available in system. The shared folder appears on your guest machine as:

/media/sf_folder_name

For example:

/media/sf_ProjectsWindows

Oh yes, there is one more step add any user in your guest system that needs access to the folder to the group vboxsf.

Tuesday, June 24, 2014

I was installing MySQL-python in Ubuntu, for this I downloaded package file from MySQLdb Download page and proceed as follows:

$ gunzip MySQL-python-1.2.2.tar.gz
$ tar -xvf MySQL-python-1.2.2.tar
$ cd MySQL-python-1.2.2
$ python setup.py build
$ python setup.py install

Note: Make sure you have root privilege to install above module.

When I reached the steps 4 in above process i.e "python setup.py build" I received the following error messages.

sh: 1: mysql_config: not found
Traceback (most recent call last):
  File "setup.py", line 18, in 
    metadata, options = get_config()
  File "/home/user/Downloads/MySQL-python-1.2.4b4/setup_posix.py", line 43, in get_config
    libs = mysql_config("libs_r")
  File "/home/user/Downloads/MySQL-python-1.2.4b4/setup_posix.py", line 25, in mysql_config
    raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found

Seems like something is missing in my OS.

As we know MySQLdb is simply a python interface for mysql, but it is not mysql itself and MySQLdb setup process apparently using mysql_config, so you need to install that first, but first confirm whether mysql_config added in system path or not. If it was not added you can do it as follows.

export PATH=$PATH:/usr/local/mysql/bin/

If you do not want add mysql in path, just run something like this to make mysql_config available:

ln -s /usr/local/mysql/bin/mysql_config /usr/bin/mysql_config

Since this is the path that python will search by default. If mysql_config is not already installed you can do it as follows:

apt-get install libmysqlclient-dev


Categories

.
Powered by Blogger.

Popular Posts

Like Us