Tuesday, March 17, 2009

"is_element_present" does not return FALSE !!!

While writing automation script in selenium using ruby I had a need to assert and check element on the page. I have created an API for element present and check assertion to mention in the report and log. So I got “is_element_present” method which returns TRUE if it finds element on the page otherwise FALSE.

But actually it doesn’t return FALSE. In fact throws an error and just demolish all the script and go out from code. You can handle this situation and even can write this to your report and log as well.

Have a look:

def is_element_present(id)
begin
$browser.is_element_present(id)
rescue SeleniumCommandError
return FALSE
end
end


this actually handling the exception and that case when element doesn’t present on the page you can explicitly return FALSE. By this, “is_element_present” works expectedly.

Wednesday, January 21, 2009

Forgery error while maintaining session in ruby on rails

hi guys recently i have tried pragmatic rails application depot. it was going good while the implementation apart from there were some changes because of i am working on the new version of rails 2.0.2
as soon as i have reached to store session the application have started giving me a stupid error (frogery error). it was just refusing me to pass explicit session. then i came to know that button_to or link_to creates its own session and passes this session to the controller.
for avoiding this crap i have just followed the steps

go to depot/config/environment.rb and uncomment this,

config.action_controller.session_store = :active_record_store

go to depot/app/controller/application.rb and uncomment the following

protect_from_forgery :secret => '165451f36fafd3eba6cd953bbcb6daf0'

now just restarted my server this went fine.

hope this will help you.
cheers

Thursday, December 18, 2008

how to automate sproutcore appliaction through watir

Automation of a sproutcore application is still a headache for programmers. We can automate sproutecore application through selenium and watir as well.

I have successfully created a sample script which runs from both selenium and watir as well.
Actually, I have managed some api which run according to the environment like watir or selenium.

The question how you automate a sproutcore application while there is no such HTML tag on the page. Complete application runs through JavaScript. We can not click on any event directly from id. So, how can we deal with this problem?
So guys cheer up in the sproutcore everything is a link. So I have classified the event into three parts:

1. text field
2. button
3. Check box or radio button.

For the first case we deal it normally as we did normally with watir

$browser.text_field(:id,”id”).set(“hello sproutcore”)

The second and third case is different as we can not click on the button or any event directly.

We need to find out the controller and corresponding method associated to the event. We need to execute JavaScript. Well guys, there is a hell lot of difference to click on button or check box. Have a look at the controller.

There is a direct method associated to the button. Check out the view page this is an action while radio button and check box bind the value. Now go to the controller you will see that the corresponding method is actually bind from the variable. That means it always observes the value of the variable and performs action accordingly.

Ok. I am giving you an example how to automate it from watir.

I have create a sample application which have a button with the id=”toggle_button”.
I just find out the source code and go to the index of “toggle_button”. The reason being I need the controller and method information as you can see the following source code:


toggleButton: SC.ButtonView.extend({
action: "SproutHello.appController.toggleGreeting"
}).outletFor("#toggle_button") ,



So now I have all information. I just need to create a JavaScript and just execute it.

body_array = page_source()
action_str = body_array[body_array.index("}).outletFor(\"##{button_id}\")")-1]
action = action_str.split("\"")[1]
ff.js_eval("var w_all = getWindows(); var w_one = w_all[#{window_count}]; w_one.content.#{action}();")


So, guys start playing with clicking on button. :)

We can not click on check_box with the above code the difference is in the javascript because check box and radio button the working as toggle. If it is on then you need to turn it off and vice versa. So you need to get the value and set the value.

body_array = page_source()
action_str = body_array[body_array.index("}).outletFor(\"##{event_id}\")")-3]
action = action_str.split("\"")[1]
_obj = action.split(".")
_get = "w_one.content" + "." + _obj[0].to_s + "." + _obj[1].to_s + ".get(\"" + _obj[2] + "\")"
_set = "w_one.content" + "." + _obj[0].to_s + "." + _obj[1].to_s + ".set(\"" + _obj[2] +"\",!" + _get.to_s + ")"
ff.js_eval("var w_all = getWindows(); var w_one = w_all[#{window_count}]; #{_set}")


Don’t get confused with window count this is to check how much firefox windows are open and on which script should work upon.

Enjoy sproutcore automation
:)
gud luck.

Monday, December 15, 2008

data migration from YAML using ruby

When I was given a task to implement YAML, I did not know how to implement and even did not get any clue to proceed. The prime concern was to give our successful first release. At last I have only a weekend and my lead has postpone this YAML implementation to the next build and told me to implement this concept with an demo application which is to be given with the release.

She even not expecting this to be implemented successful but the expectation was that I should be answerable on this topic at the time of demo.


Well I had to work whole weekend night and had to spend complete two days alone in the office, even my team was not aware about this implementation.


Monday I told to my lead and she was so surprised about you not even implemented the YAML successfully but you have made changes to the others 25 module.


The reaction from the lead was made me happy and encouraged a lot.

I just want to share some little concept what I have done with YAML.


YAML is a straightforward machine parsable data serialization format designed for human readability and interaction with scripting languages such as Perl and Python.


Early in its development, YAML was said to mean "Yet Another Markup Language", but was retronymed to distinguish its purpose as data-centric, rather than document markup.


So the task is to make a data structure in the YAML which returns an array of hash.



Data.yml

-

suite_file: "test_status_codes_test_suite.rb"

flag: "0"

-

suite_file: "testing_types_test_suite.rb"



The Most important this is to take care of spaces. YAML file does not support tabs. And you need to follow the same space convention through out the file.


‘-‘ creates an array element.

I have given the two white spaces to create an hash key-value within the array element.


Now you want to remove the iteration from your ruby code so you want a hash instead of array.



Code.yml



TCM_SS_MTSC_1:

desc: "Hi vaibhav."

TCM_SS_MTSC_3:

desc: "Good luck team!."

TCM_SS_MTSC_2:

desc: "done a good job."

TCM_SS_MTSC_4:

desc: "you are owe-some"

flag: "0"



Above is the hash of hash, you will get it like:


{: TCM_SS_MTSC_1 => { :desc => "Hi vaibhav."}, : TCM_SS_MTSC_3 => { :desc =>"Good luck team!."}}


Again take care of spaces otherwise it will give you an unidentifiable error at run time.

Finally the question is how to load the YAML File and use the data


J

So friends lets have a look:



$Data = YAML::load(File.read('config/Data.yml'))


Now whatever I have specified in the data.yml file I will get as in a data structure.

You should prefer to use YAML file when you need to migrate data into database. So dear enjoy playing with YAML.


J

Good luck

Tuesday, October 16, 2007

a writer who influnced me to buy another novel

hi now i m telling u my first novel which i read in b.tech 4th year. that novel is related to the student life.i heard the story line before buy it so i was too excited to read it. i completed it in 2 days. that novel name is 5 point someone.
there were three guys who always secured 5 point in iit. that story was of three friend they all iitans from delhi. and they are all good in studies but one of them was care less and they all found of having VODKA on the roof at the dark corner.
2nd one had gone for a morning walk and found a girl which is daughter of his faculty. so he lost to study in fact caught by his faculty at his home. where he was wearing his teachers shirt and his girlfriend having his t shirt. that was too interesting part of the novel. a guy ryan was fond of having a vodka and just because of that he was thrown out of the class. they all stupid guys tried to steal the examination paper from the office.
actually this novel is related to every student who is taking technical education from any institute. he can understand what that novel is trying to reveal. when i was reading book i was lost in that book and each and every character. i felt myself as i was Reading my story or my friend that is too close to me. and i know everything about him so that i can analyze his feeling and his situation which he is facing.
that novel was just for fun but really i had lost in that story. i was too excited regarding This writer (Chetan Bhagat)who was an iitian, i took his another book a night at call centre. even at that time i did not completed my first novel. the another one is also good story of some people working at call centre in delhi and haryana border.
chetan Bagat is really a good writer who writes i think only for bachelor.......
every technical student should read this he will feel that this story is related to me...................

Monday, October 15, 2007

my first novel which influenced me alot

Here I am going to tell you about that novel (which i read in b.tech 2nd year and is my first novel)or you can say a story which influences me a lot. for my b.tech result my younger brother gifted me this novel 'Alchemist by Paul Coelho'.I am thinking whats this novel is all about, there was a quotation 'A magical tale to follow your dream'.
First I thought that this is something thrilling novel but as soon as I started reading that I realized that I am wrong and its totally different from what I am thinking about that. that is something related to you, your strength.
I took 3 days to finish that novel as I turning its pages I really feeling that some how its connected to me and to everyone and thinking about the writer how he pick the nerve of the reader.
So as the hero Santiago only believe on his will power, not on fate and there were many incident happened with him in that he showed that how one's will is superior than the one's fate.
Santiago come to learn by the incidents which was happening in his life that there was only one way to be happy forever that was to listen to your heart and whatever had to be left for that leave it. don't bother for the past and don't worry which is being happened always worry for present. Only follow your heart than only you can happy, than only you can get true love and the soul enlightenment.
So there were many theory developed in my life after reading this book, like every one has its one's field for learning and only that person can survive in that field.Always follow your heart ,each and every time it says something when you are taking some decision and it knows how one can be happy in his life. as every story teach you something that you can test in your daily life. as well i thought this story is something which i have done before in my life.
Alchemist is all about to follow your dreams and we have to never compromise our dreams with any thing. i prefer to recommend this to every one. everyone who likes books should read it........

1st module of ncst

2 months and 10 days back, i was here for very first time. and listening to RAMAN sir's word that "this beautiful place going to be hell for you." but belive me my friend being here i am happy because i am more confident and technically more sound. which we forgave in our graduation that things are starting here.

some people told me that if you can survive here then you will not feel any dificulty in any organization. and i am happy to be here. in our starting days here we are putted in front of unix to code well that is not a big deal but i seems to be more technical onwards. our some classes on unix introduction. then we are putted on java classes that is held by Balaji sir. he taught us all the concept of java infact oops concept. another subject which is parallel to java is DSAL that is data structure. i think there is nothing left to study. he taught everything and provide us a solution for implementation. i did not use such code before. and for testing we are evaluated with MGPAs that is pathetic. in the sense, last night of mgpa is worst but we enjoy that experience as i did ever heard such online evaluation in ant institute.

well to clear the module we are supposed to clear 4 mgpa out of 10 and i have over through it. i can say anthing for raman sir is that he is as fair as Y in parikshak with his knowlege. he transmit only that which he is supposed to.

another subject was TCOM that subject is only for evaluation as even there is nothing to teach but there is almost every class we had a evaluation. and had to listen hi dear you should improve this and do this, dont do like that.

there is an incident related to TCOM class. we are 7 peaple in a group. and one of us was having a bath and told us to wait for him. Swani mam told "5 min is early on time" and we were 10 min late. that day we have thrown out from the class and we then enjoyed all tha day at oliveshop. at the next day we were again late and mam recognized us and announced evaluation is not for us. but she forgot thank God...........

today onwards there is only 3 days left to get over this module. there is only one paper left and one mgpt is to go. then we all going to home after 3 and half month i am too excited to go home as i am first time out side from home to long................