Wednesday, February 16, 2011

More on OERPScenario


       Before reading this please read my blog post on OERPScenario . Now go to our OERPScenario folder that we have downloaded from bazaar, there is a folder named features. All the user defined test cases are written in a folder inside this folder. I want to create a new scenarios for testing products, so I create a directory called product inside features. Inside the product directory a file called product.feature is created. We have to write our scenarios in this file.

       In writing the scenario we are following the Gherkin Syntax. Gherkin is the language that Cucumber and OERPScenario can understand. The source files have *.feature extension. Gherkin is a line-oriented language that uses indentation to define structure. Most lines start with a keyword.
   
       For writing the scenario I'm creating a file called product.feature inside the folder product. In writing the scenario first write <Feature:> explaining about the scenario. Then our scenario <Scenario:>.Statements following the scenario must start with any of the keyword 'Given', 'When', 'Then' or 'And'. 'And' can be used for extending 'Given' , 'When' and 'Then'.The following figure will give an idea  about each keyword.



 Before writing the feature, tags are given and this tag can be used for testing the scenarios under this feature. We can also specify tags for each scenario and by using this tags we can test the scenario that come under this tag. The statements written between Feature and Scenario are omitted by the cucumber. So we don't need to concentrate much on it. After writing the scenarios we can run the scenarios. But before running the scenario we have to compile the whole OERPScenario  folder using the command rake compile.This is just for testing the connection between openERP server and OERPScenario. If this fails then everything fails(I think so).
When I was testing I  found that the scenario written inside  the file  _init.rb  in feature>_basic>step_definions did not satisfy the conditions written inside the  _init.feature file in feature>_basic. So I changed the code . Figure of the changed code is given below
After all the changes are made, we can compile it using command rake compile. If we get all test scenarios printed in green color then we can proceed. If we get it in red color then an error is present in it.

Now we  can run our scenario.


By running this the test cases that needed for testing product are automatically generated by the cucumber. Copy these test cases and paste them to a ruby file (say product_steps.rb) created inside a directory called "step_definition" inside product.  

//not completed

OERP Scenario

       In OpenERP a time consuming task is to check all the modules by entering data to each field and checking whether the view is changing according to the data given in the field or changing according to our plan. It is also not possible to check all the information given in the fields. And also testing is important in locating a bug and fixing an error. For this purpose we are using OERPScenario. OERPScenario do the same process as the database query do. OERPScenario search for the condition data from the database satisfying the scenario statements.

      OERPScenario allowing to write business oriented test cases in OpenERP. OERPScenario is a framework based on the Cucumber Library and the Ruby Language; it uses the Ooor connector developed by Akretion to make Business Driven Development (BDD) among OpenERP. It is a tool that can execute plain-text functional descriptions as automated tests.

 OERPScenario splits tasks in two, allowing business individuals to write and describe the different test scenarios, while technical individuals code the tests.

Install and Configure OERPScenario in Ubuntu 10.04

==$sudo apt-get install ruby irb ri rdoc rubygems
==$sudo gem install cucumber -v0.6.3
==$sudo gem install rspec
==$sudo gem install parseconfig
==$sudo gem install ooor --source http://gemcutter.org
==$sudo apt-get install libopenssl-ruby
==$sudo gem install rake
==$sudo gem install htmlentities
==$# Optional for pdf output only
==$sudo gem install prawn --version 0.6.3
==$sudo gem install prawn-format --version 0.2.3
==$# Finally add '/var/lib/gems/1.8/bin' to your PATH :
==$export PATH=$PATH:/var/lib/gems/1.8/bin

Then install the "bzr" for downloading the OERPScenario. After installing "bzr" retrieve the stable branch:
==$bzr branch lp:oerpscenario

Configure

We need to instruct OERPScenario on how to connect to the OpenERP server in a
configuration file. In order to do that, copy the file « sample_base.conf » as «base.conf » into the OERPScenario folder and change the following information according to your settings:
port = 8069
user = «username »
#if it is administrator then provide "admin"
database = «mydatabasename »
password = «secrete »
host = localhost

Once it's done, go into the OERPScenario folder and run the following command to test the connection:
==$rake compile
You should then have an output confirming everything is alright.

As the tests are running under a specific user, you can always change the one that has been set-up as default (by default, all tests are running with the user defined in the config file). If you need to run the tests under another user, edit the following file:
« /features/_basic/_init.feature » and change the sentence according to your needs

The configuration is done!

Using tags

 The tag system implemented in Cucumber is very powerful and allows you to run complex test cases according to your own OpenERP settings. Basically, the following tag types are present in OERPScenario:
• Bazaar branch (like @addons), which tests all existing modules in that branch;
• Modules (likes @account), which tests everything having to do with a specific
   module;
• Bugs related (like @bug452854), which launches the related scenario;
• Business oriented (like @invoicing), which runs every related scenario;
• System (like @init, @demo), which executes a set of tasks in OpenERP.

Launching the OERPScenario
 You can launch the test suite from the OERPScenario folder with the following commands:
cucumber feature --tag=@account
This will execute all scenarios related to the OpenERP account module (notice that tags can be set on features or scenarios). The feature tags are true for all included scenarios, where the scenario tags are true only for the current scenario.