Posts tagged LDTP

LDTP Editor

1

Want to use LDTP to test your application? Or do you want to automate the actions you do often? Or are you a GNU/Linux user who want to show “magic” to your friends by recording your actions and playing them back? You can use LDTP for this. But one small issue with LDTP is that you should know the LDTP Python API to write any test suite. But with the new LDTP Editor, this makes your job really simple. A screenshot of the LDTP Editor is shown below.

 

LDTP Editor

 

This is a simple HOWTO for recording and playing back the recorded script.

Installing LDTP.

  • Download the lastest LDTP source code from http://people.freedesktop.org/~nagappan/ldtp-0.9.2.tar.gz.
  • Uncompress the file.
  • Compile the code using ./configure and make
  • If you don’t have the access to install softwares, run the ldtpeditor file in the python folder
  • If you have access to install softwares, then run “make install”

Note:: After installing LDTP Editor, i when i tried to run ldtpeditor, got an error saying

hari@hari-laptop:~/ldtp/ldtp-0.9.2$ ldtpeditor
(ldtpeditor:11130): libglade-WARNING **: could not find glade file '/usr/share/local/ldtp/glade/ldtpeditor.glade'
Glade file not found

The ldtpeditor.glade file is present in the python folder. I got this error because i compiled the code as ./configure. If i had done it as ‘./configure –prefix=/usr’, then i wouldn’t have got this error. Anyway i copied the file manually to that folder.

hari@hari-laptop:~/ldtp/ldtp-0.9.2$ sudo mkdir -p /usr/share/local/ldtp/glade/
hari@hari-laptop:~/ldtp/ldtp-0.9.2$ sudo cp python/ldtpeditor.glade /usr/share/local/ldtp/glade/
hari@hari-laptop:~/ldtp/ldtp-0.9.2$ ldtpeditor

After that when i ran ldtpeditor, it ran without any issues.

Recording using LDTP Editor

For this let us consider recording the actions performed in gcalctool.

  • First make sure Assistive Technology is enabled in your desktop. If you are not sure about this, open gnome-control-center and in that open Assistive Technology Preferences. You should have Enable Assistive Technologies checked to use LDTP.
  • If you are enabling Assistive Technology only now, logout and login again.
  • Run ldtpeditor and gcalctool.
  • Make sure both you have enabled ‘Always on Top’ or both the applications and both the window doesn’t overlap with each other.
  • Click the Start button the LDTP Editor. All actions performed after this are recorded.
  • Perform actions in the gcalctool. Check out this video to see the actions i recored in my computer .
  • After you’re done with the actions in the gcalctool, click the Stop button in the LDTP Editor.
  • You can see that the ‘Recorded Code’ tab is updated with code as when you perform actions in gcalctool.
  • Click the convert button in the LDTP Editor. You’ll see that the Generated LDTP Code and Generated LDTP XML tabs are filled with generated code.
  • The Play button is not working now. I wrote the patch for that yesterday night ;-).
  • Save the contents of the ‘Generated LDTP Code’ into a python file (for ex frisco.py) . Note that if the file name you specify already exists, then it OVERWRITES the filename without any warning.
  • Then run hari@hari-laptop:~$ python frisco.py
  • The actions you performed while recording will be played back again :-)

Currently the Play button in the LDTP Editor is not enabled. But you can make it work by applying the patch mentioned below. I guess this patch will be added to LDTP Editor in a week or so. So check the ChangeLog file before applying the patch.

LDTP Editor Preferences

Using the LDTP Prefereces, you can control what all actions you can control. A brief summary about the options given in the Preferences window.

  • Listen key events
    This option is not yet implemented. Checking/Unchecking this doesn’t make any difference now.
  • Listen mouse events
    This option is not yet implemented. Checking/Unchecking this doesn’t make any difference now.
  • Generate LDTP Code
    Only when if this option is enabled, Convert will generated to LDTP code in the ‘Generated LDTP Code’ tab. This is enabled by default when you run LDTP Editor.
  • Generate Data XML
    If this option is enabled, the LDTP Editor will generate data XML for the actions you perform.
  • Generate keyboard events code
    Generates code for the keyboard events you performed during the recording session.
  • Generate wait time code
    Calculates the delay one takes between each action during the recording session and generates code so that similar time delay is generated while play back.
  • Generate Memory / CPU statistics.
    The code to generate Memory and CPU statistics will be generated. You need to install pystatgrab and libstatgrab packages.

Patching to make the Run button work

  • Copy this patch file to your ldtp folder.
  • Runhari@hari-laptop:~/ldtp/ldtp-0.9.2$ cd ldtp-0.9.2
    hari@hari-laptop:~/ldtp/ldtp-0.9.2$ patch -p0 < ldtpeditor_runbutton.patch
  • Compile the code again and run ldtpeditor. This time after you Convert the Code, you can Run the code from the LDTP Editor. :-)

Note:: The generated code had many unwanted waittillguiexist. I saw waittillguiexist(“dlg0″) in many places. If your playback is stopped because of this, remove that before running the scripts.
Sometime the resource will go high as the application map info is collected from the application, so no need to worry.

If you find any issues regarding LDTP Editor, report it to ldtp-dev@lists.freedesktop.org or nagappan@gmail.com or sp2hari@gmail.com

All patches are welcome. :-)

My Tinderbox is working…

0
Yes, you heard it right. My tinderbox is working. Even now i don’t know why i was trying to setup a tinderbox after both Emily and Nags asked me to concentrate on Firefox automation. I felt it was almost done and just few more steps, i will be able to set it up. And that’s what finally happened :)

So in this post, i am going to mention about all issues i faced in setting up a tinderbox and steps to fix them.

Note :: If you are ever setting up a tinderbox, be prepared to see huge log files. Like once my compilation ran for few hours and produced a log file of size 15MB. And if you are stuck up, DON’T send the entire file. A tail of that file should do. In fact, you should be in a position to find out from while line the exact error starts.

Yeah before you start reading this
http://sp2hari.blogspot.com/2007/06/conquered-solaris.html and
http://sp2hari.blogspot.com/2007/06/tinderbox.html has instructions about how to setup Tinderbox in Solaris environment.

Ok the first error i got was

Building deps for jsinterp.c
cc -o jsinterp.o -c -DOSTYPE=\”SunOS5\” -DOSARCH=SunOS -DEXPORT_JS_API -DJS_USE_SAFE_ARENA -I../../dist/include -I../../dist/include/js -I../../dist/include/nspr -DMOZ_PNG_READ -DMOZ_PNG_WRITE -I../../dist/sdk/include -I. -KPIC -xlibmil -xstrconst -xbuiltin=%all -mt -DNDEBUG -DTRIMMED -xO4 -DMOZILLA_VERSION=\”1.9a7pre\” -DMOZILLA_VERSION_U=1.9a7pre -DSOLARIS=1 -DNSCAP_DISABLE_DEBUG_PTR_TYPES=1 -DD_INO=d_ino -DSTDC_HEADERS=1 -DHAVE_ST_BLKSIZE=1 -DHAVE_SIGINFO_T=1 -DHAVE_INT16_T=1 -DHAVE_INT32_T=1 -DHAVE_INT64_T=1 -DHAVE_UINT=1 -DHAVE_UINT_T=1 -DHAVE_UINT16_T=1 -DHAVE_DIRENT_H=1 -DHAVE_SYS_BYTEORDER_H=1 -DHAVE_GETOPT_H=1 -DHAVE_MEMORY_H=1 -DHAVE_UNISTD_H=1 -DHAVE_NL_TYPES_H=1 -DHAVE_MALLOC_H=1 -DHAVE_X11_XKBLIB_H=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-DMOZ_UPDATE_CHANNEL=default -DMOZ_PLACES=1 -DMOZ_PLACES_BOOKMARKS=1 -DMOZ_FEEDS=1 -DMOZ_STORAGE=1 -DMOZ_SAFE_BROWSING=1 -DMOZ_URL_CLASSIFIER=1 -DMOZ_LOGGING=1 -DMOZ_USER_DIR=\”.mozilla\” -DMOZ_ENABLE_LIBXUL=1 -DHAVE_STDINT_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_SYS_INT_TYPES_H=1 -DHAVE_UINT64_T=1 -DMOZ_XUL=1 -DMOZ_PROFILELOCKING=1 -DMOZ_RDF=1 -DMOZ_MORKREADER=1 -DMOZ_DLL_SUFFIX=\”.so\” -DXP_UNIX=1 -DUNIX_ASYNC_DNS=1 -DJS_THREADSAFE=1 -DMOZ_ACCESSIBILITY_ATK=1 -DATK_MAJOR_VERSION=1 -DATK_MINOR_VERSION=12 -DATK_REV_VERSION=3 -DMOZILLA_LOCALE_VERSION=\”1.9a1\” -DMOZILLA_REGION_VERSION=\”1.9a1\” -DMOZILLA_SKIN_VERSION=\”1.8\” -D_MOZILLA_CONFIG_H_ -DMOZILLA_CLIENT jsinterp.c
ube: error: Assert has been violated at ‘/set/venus/builds.intel-S2/nightly.Thu/intel-S2/lang/ube/graphs/src/scregion.c 305′.
cc: ube failed for jsinterp.c
gmake[4]: *** [jsinterp.o] Error 2

Dave from Sun china asked me use a patch for Sun Studio 11 Compiler C. I don’t have the link to the patch now but the patch id is 121016-05. I remember getting it from the sun website. So searching there should give you the link. The above patch was dependent on patch 120759-06. So installed patch 120759-06 first and then install the patch 121016-05.

Steps to add a patch in Solaris are given below. The commands are for patch 121016-05. Change the id according to the patch you are installing.

1. Download 121016-05.zip and extract the contents in your current directory
2. Login as root
3. root@home# patchadd 121016-05
Note :: If the above command doesn’t work, then try
root@home# patchadd . 121016-05

The above steps should install the patch in your system. To check whether the patch is installed properly, check the folder /var/sadm/patch/. You should see seperate directories for each patch you have installed. In my system here, the /var/sdm/patch is like
# cd /var/sadm/patch/
# ls
120759-06 121016-05

That fixed the above problem :).

The next error i got was

jsinterp.c
ir2hf: error: Ran out of memory
cc: ir2hf failed for jsinterp.c

Now this is a strange problem and which can be fixed without much issue. You need more RAM. My system had 768MB (512+256) RAM, but you need 1GB RAM to fix this issue. So next day i got 1GB RAM and never got this error back.

After that, i got many compilation errors. This happened because of some issue in the mozilla code. This generally never happens. I got errors in lines having inline. Anyway now i am not getting the error anymore. So i think the mozilla code is fixed now. :)

Finally i got an error saying,

gmake[3]: Leaving directory `/export/home/hari/tinderbox

/SunOS_5.11_Depend/mozilla’
gmake[2]: Leaving directory `/export/home/hari/tinderbox/SunOS_5.11_Depend/mozilla’
make[1]: Leaving directory `/export/home/hari/tinderbox/SunOS_5.11_Depend/mozilla’
firefox-bin built successfully.
firefox-bin built successfully.
firefox-bin binary exists, build successful.
Unable to find path to Talkback client. Proceeding as if Talkback was not installed.

Running regxpcom test …
Timeout = 120 seconds.
Begin: Fri Aug 24 08:08:37 2007
cmd = /export/home/hari/tinderbox/SunOS_5.11_Depend/mozilla//dist/bin/firefox-bin -register
End: Fri Aug 24 08:08:38 2007
———– Output from regxpcom ————-
———– End Output from regxpcom ———
regxpcom: test failed
No profile found, creating profile.
Begin: Fri Aug 24 08:08:38 2007
cmd = /export/home/hari/tinderbox/SunOS_5.11_Depend/mozilla//dist/bin/firefox-bin -CreateProfile default
End: Fri Aug 24 08:08:39 2007
———– Output from Profile Creation ————-
Xlib: connection to “:0.0″ refused by server
Xlib: No protocol specified

(firefox-bin:6432): Gtk-WARNING **: cannot open display:
———– End Output from Profile Creation ———
ERROR: profile /export/home/hari/tinderbox/SunOS_5.11_Depend/.mozilla/firefox/ does not exist
no pref file found

The solution for the above bug was to allow connections to X server. This is done by executing the following command before starting a tinderbox compilation. Remember the user who is running the tinderbox should execute the command.

hari@home:~$/usr/openwin/bin/xhost +
access control disabled, clients can connect from any host

Few other things to note while trying to compile firefox under tinderbox are
1. Never ever run two instances of tinderbox at the same time. Make sure the first one is killed before starting a new one.
2. Delete the SunOS_5.11_Depend folder when you are facing any compilation errors.
3. Use -XO3 for CFLAGS and CXXFLAGS
4. Make sure your mozconfig file has these lines
ac_add_options –disable-freetype2
ac_add_options –disable-debug
ac_add_options –disable-tests

SOC ….

0

Updates about SOC.
30 test scripts are working fine without any issue :). My target is to write 50 test cases and i will try to reach that this weekend :) :).

The scripts can be downloaded from here.

Things to be modified when you run your script in your environment are.
1. In the file firefox.xml, change the value of <filepath> for so that it points the file called index.html in the folder called data in your scripts directory.

Let me give a detailed HOW TO for running these scripts.

1. First, LDTP must be installed in your system.
The CVS page in ldtp.freedesktop.org provides the instructions for getting the LDTP code through CVS.

Note : I had a small issue compiling the code which i got from CVS.
While using ./configure it gave me an error saying

./configure: line 3998: syntax error near unexpected token `LIBXML2,’
./configure: line 3998: `PKG_CHECK_MODULES(LIBXML2, libxml-2.0 >= 2.0.0)’

The above error is because autoconf and pkg-conf are installed at two different locations. For more details check http://lists.freedesktop.org/pipermail/xserver/2003-December/000573.html

So i used this package which compiled without any issue :).
For more details on how to install, check here.

2. Enable Accessibility from gnome-control-center

3. Download and start Firefox3.0a*pre from here ( Any FF3.0 alpha release should work, though with FF3.0a8pre, it is tested throughly.
Note :: When you start firefox, make sure you don’t have any other instance of firefox running.

4.Run the command

hari@home:~/soc/tinderbox$ ldtprunner run.xml

If you have set LDTP_DEBUG=1 in your shell, then it will show lots of output. Don’t get scared. It only means things are working fine :)
Note :: You can also work with LDTP_DEBUG unset, if you want a “clean” output.

Once that command is executed, then it will run the test cases provided in the run.xml.

A file called log.xml gives the details about the test cases run. The last three lines in the log file should be like this if the test case ran properly for all the 30 test cases provided.

<groupsstatus total=”30″ pass=”30″ fail=”0″/>
</group>
</ldtp>

The screen record video on Solaris 11 is given can be viewed from here.
http://download.freedesktop.org/ldtp/movies/screen2.html

The current status of the test cases can be viewed from here.
http://ldtp.freedesktop.org/wiki/Firefox_Test_Cases

Solaris Firefox Automation :)

0

Check out this for the video :). Nice right ;)

file-roller …

3

When i saw the mail from nags saying
” Can somebody evaluate it and send me back the results. It was done by Yazhini, long time back, but I could not check them.”

even i didn’t think i will write the test cases for file-roller that night. I just wanted to see the code and maybe make a comment. After seeing the code, i felt really sorry for file-roller :P . Yeah now it looks crazy, but not at that time. When evolution, gedit and other applications have new new scripts, why should file-roller have the old test scripts. :-)

So wrote the test cases for file-roller according to the new file-roller and new LDTP.

I will write about what all changes should be made while changing the scripts, so that it will be useful for someone who might change the code for other applications like gcalctool, bugbuddy, gnome-font, gnome-search-tool, gdf etc.

The files can be downloaded from here. Just take care that you don’t have a file called ldtptestarchive.tar.gz in your home folder. Apart from that, you need to change the run.xml . I tried the scripts in solaris but setcontext didn’t work properly there :(. Have to check that soon.

1. Names of objects in applications.
This has changed a lot, especially in the frame names. In the old scripts for file roller, it will be like
selectmenuitem (‘ArchiveManager’,'mnuHelp;mnuAbout’)
But according to the new LDTP, it is better to have
selectmenuitem (‘frmArchiveManager’,'mnuHelp;mnuAbout’)

Note the way the window name is mentioned in the new version. If has the prefix frm in that. The older one might still work but it is better to change soon. The prefix for each and every object can be seen in a file called remap.c in src folder. The function get_object_info (Accessible *accessible) in that file is the one which can give information about the prefix for each object type.
Apart from this, a ldtp function called getobjectlist () is also useful. Another utility called appmap is also useful in this case, but it is better not to use it, since the appmap is obsolete and latest changes are not incorporated into that. I think getobjectlist is the best solution. A tool called at-poke is also very useful to find the objects and object types inside an application.

2. Runner XML.

In the old scripts a python file used to call each and every other test case files using exec(). In many cases this main python file will be the name of the application. For example, check the file-roller.py

#To create a new archive
log (‘Create New Archive’, ‘teststart’)
execfile (‘create-archive.py’)
log (‘Create New Archive’, ‘testend’)

time.sleep(2)
#To open an existing archive and extracing them.
log (‘Open Extract Archive ‘, ‘teststart’)
execfile (‘open-extract.py’)
log (‘Open Extract Archive’, ‘testend’)

So this way many scripts are tested from the a single python file. In the new test files, the concept of ldtprunner and runner xml is introduced. The links mentioned there are the best place to learn about runner XML. Just for the sake of completion let me add a sample runner xml for the above code here

<ldtp>
<logfileoverwrite>1</logfileoverwrite>
<logfile>log.xml</logfile>
<group>
<script>
<name>create-archive.py</name>
<data>fileroller.xml</data>
</script>
<script>
<name>open-extract.py</name>
<data>fileroller.xml</data>
</script>
</group>
</ldtp>

Scripts can be easily added, removed and grouped using the runner.xml .

3. waittillguiexist() and waittillguinotexist().

The two functions are really useful if you want your code till an object appears or disappears. The docs for these two functions explains the usage clearly. The old test code will have an approximate time.sleep() in their code. A better and proper solution is to incorporate waittillguiexist() and waittillguinotexist() and remove the unwanted time.sleep()

4. LDTPExecutionError :

The old code just has an except block which can catch any exception that occurs. It is better to handle the LDTPExecutionError separately and other errors in a different manner. A typical except block in the new script will be like

except LdtpExecutionError, msg:
  msg = ‘open-extract test case failed’
  log (msg, ‘error’)
  raise LdtpExecutionError (msg)

5. Data XML.

One of the most important thing in LDTP, which adds great flexibility to the test cases. The filenames and other variables need not be hard coded. A single XML (generally called the data XML) can have all the details like the filenames, paths used in a test case and these value can be extracted from the XML file. Thus even the arguments passed to the test cases can be changed using a data XML.

6. Appmap file.

Since now in LDTP , the remapping of the objects in application is done automatically, there is no need to use initappmap() or remap() anymore. So there is no need to have a default map file for each application.
Therefore you can remove the following piece of code if you find it in your test case.


if len (sys.argv) == 1:
  if os.access (‘./file-roller.map’, os.F_OK | os.R_OK) == 0:
    print ‘Appmap path missing’
    sys.exit(0);
  else:
    appmap_path = ‘.’
else:
  appmap_path = sys.argv[1]
initappmap (appmap_path + ‘/file-roller.map’)

Coding Style …

2
I have never thought much about coding style before i did my NOSIP in Novell. But once i started coding for ldtprecord, according to the coding style suggested to me by nags, i was surprised to see how nice and neat the final code looks.

Some tips/tricks for nice coding skills are,

1. Do spend some time to think about the variable names and the function names. This sometimes might be bit boring, especially when you want to concentrate much on the program logic and performance. But this is Rule 0 for coding conventions. A variable name “k” can imply anything like “kappa, kozhukattai, katthu, kaadhal, kerala, kozhuppu…” to someone who might have to read your code later. This is again mentioned here clearly. Many thanks to emacs, you can always use the auto complete, if your variable name is too long. :-) .

2. The actual coding convention depends much on the language and the standards your team is using already. The following style won’t work for someone, whose team is already using a totally different style.

A few examples for C is posted here .

Sample Code 1 :

if (a == 5) {

    b = 10;

}
else {
    b = 20;
}

Things to be noticed in the above snippet are.

1. A space between if and “(” .
2. Space in both the sides of the comparison operator.
3. Space between “)” and “{“
4. Space between both the sides of assignment operator (line 2 & 5) . This is true for almost all the operators.
5. Proper indentation of lines 2 & 5. If you are using emacs or vi, check here for your .emacs or .vimrc file .

Well, your code will compile and run even if you don’t give these spaces, but a program coded with a bad coding style is equivalent to an inefficient code.

Sample Code 2

Let us have a function which takes two integers and returns their sum .
The code should be like

int add_numbers (int num1, int num2) {

    return (num1 + num2);
}

The function call will be something like,

int sum;
sum = add_numbers (10, 20);

Things to be noticed in the above snippet is

In the first line in the function declaration,

1. The function name should be as clear as possible.
2. A space between the end of function name and “(” .
3. Spaces are given after every “,” in the function argument list.
4. A space is given between “)” and “{“.

In the second line in the function declaration,

1. A space before “(“. [ This rule is almost global. Apply it everywhere whenever you use "(" ] .

2. There is a space on both the sides of the addition operator. This is again almost global. A space between both the sides of operator makes the code look real neat.

3. The indentation about which was mentioned earlier.

But yes, if your girl friend is a geek or a nerd or a psycho or a fundoo, then you better go for this. ;-)

#define MAGIC “eilouvy43605321″
#define _(p,o,q) (t o#p[0])?(q)
#define __(p,o,q) _(p,o,t-q)
int main(){int t, i; for(i=8;i>0;i–)printf(“%c”, MAGIC[(((t=(MAGIC+7)[i-1])==’_')?62:_(.,==,63):_(@,==,64):__(a,>=,’a'+36):__(A,>=,’A'+10):(t-’0′))]);}

Note :: I wont say the coding style i use is the perfect one. It always depends upon what your team was using till now and how easy it is to read, debug and maintain the code.

Useful Links :

The guide coding standards in GNOME is really a nice one.
Even better was this one i found recently. Though i didn’t read it completely, it was quite interesting.
This article was short and sweet.
Go to Top