Nothing Is Impossible…
Total Page:16
File Type:pdf, Size:1020Kb
Raveendran Nothing is impossible… Hit Count SEP Custom HTML report for 84,791 hits 5 2012 Ruby(Watir/Selenium) Base Automation framework RSS Links Requirement: RSS - Posts Sample HTML report for any ruby based Automation Testing Framework RSS - Comments Installation/Changes : 1. Create code.rb file and paste the below code. Search … 2. Create folder named as Results in the same location. Code: My Tags def get_time_name Acts_as_attachment autoitx3.dll cheat sheet $time=Time.now cucumber cuRF error excel gem $time_name="#{$time.hour.to_s}-#{$time.min.to_s}-#{$time.sec.to_s}-#{$time.day.to_s}- height highline image save image scrap #{$time.mon.to_s}-#{$time.year.to_s}" $result_date = "#{$time.day.to_s}-#{$time.month.to_s}-#{$time.year.to_s}" Jazzez jazzezravi manual testing end pagination pagination in rails plugin in rails QA def create_report get_time_name rails rasta raveendran ror @result_file_name="Report"+"-"+$time_name @full_file_name="Results/#{@result_file_name}.html" rspec rspec watir Ruby ruby $report=File.open(@full_file_name,'w') end excercise ruby gem ruby def insert_head_title(title) gems Ruby solutions ruby watir- $report.puts "<html><head> <title> #{title} </title> webdriver save_images selenium </head>" selenium-webdriver selenium- end webdriver ruby selenium ide selenium def start_table ruby selenium webdriver code $report=File.open(@full_file_name,'a') $report.puts "<table border=1> Spreadsheet Testing Updation in rails <tr> <th>Test Case Name</th> watir watir-webdriver web <th>Test Case Description</th> driver width <th>Browser Name</th> <th>Result</th> <th>Remarks</th> bankbazaar </tr>" $report.close end BankBazaar def insert_reportname_date(name,date) $report.puts "<body bgcolor='#5CB3FF'> <p align='left' size=2> Personal <b><img src='https://encrypted-tbn1.google.com/images?q=tbn:ANd9GcQB0l0xnGOHuRPFMMMi- OVg39nfAU1Ogvxr7Okk7DD8ZpqlMF9r'></img> </b> Muthu Selvan </p> Political Lines <p size=12> <center> <b><u>#{name} </u></b></center> Self Confidence </p> <p align='right' size=12> Srikanth <b>Date: #{date} </b> </p>" $report.close What I am doing ? end def report_row(*details) Custom HTML report for $report=File.open(@full_file_name,'a') Ruby(Watir/Selenium) Base Automation name=details[0] framework wp.me/p5FW9-c6 1 day ago desc=details[1] How to zip the Folder using Ruby How to zip the Folder using Ruby browser=details[2] wp.me/p5FW9-c3 1 week ago result=details[3] reason=details[4] Ruby Gem xml-simple wp.me/p5FW9-bZ if result.downcase == "pass" 1 week ago $report.puts "<tr> <td>#{name}</td> <td> #{desc}</td> <td> #{browser} </td> <td bgcolor='green'>#{result}</td> <td>#{reason}</td> </tr>" else $report.puts "<tr> <td>#{name}</td> <td> #{desc}</td> <td> #{browser} </td> <td bgcolor='red'>#{result}</td> <td>#{reason}</td> </tr>" end $report.close end def close_table $report=File.open(@full_file_name,'a') $report.puts "</table></br>" $report.close end def summary_report(overall,passed,failed) http://www.box.net/static/flash/widget_player.swf $report_overall=overall $report_pass=passed $report_fail=failed $report=File.open(@full_file_name,'a') Follow Blog via Email $report.puts "<p> <b>Total Test cases : #{$report_overall} </b></p> Enter your email address to follow this blog <p> <b>Passed : #{$report_pass} </b></p> and receive notifications of new posts by <p> <b>Failed : #{$report_fail} </b></p> email. </body> </html>" Join 563 other followers $report.close end create_report Follow insert_head_title("Raveendran -- Sample HTML Report") insert_reportname_date("My Test Report",$result_date ) start_table report_row("Check Google Home Page","Check The Title in Google Home Page","IE","PASS","Title Present") report_row("Check Google Home Page","Check The Title in Google Home Page","FF","FAIL","Title Not Present") close_table summary_report(2,1,1) Output HTML File: By raveendran • Posted in cheat sheet, QA, Ruby, Ruby 1.9, ruby excercise, selenium, selenium-webdriver, Selenium- webdriver, watir, watir-webdriver • Tagged automation html ruby, automation ruby, framework html, html report, reusable report, reuse html report, ruby framework, ruby html, ruby html report, sample html report, selenium html, watir html, watir html report, webdriver html AUG How to zip the Folder using Ruby 30 2012 Step 1 – Install ruby-zip gem >gem install ruby-zip Step 2 – Create the folder named as “Chrome” and puts 5 files within that folder Step 3 – create code.rb file and put the below code with in the ruby file def zip_it(path) require 'rubygems' require 'zip/zip' require 'zip/zipfilesystem' path.sub!(%r[/$],”) archive = File.join(path,File.basename(path))+’.zip’ FileUtils.rm archive, :force=>true Zip::ZipFile.open(archive, ‘w’) do |zipfile| Dir["#{path}/**/**"].reject{|f|f==archive}.each do |file| zipfile.add(file.sub(path+’/',”),file) end end end zip_it(“chrome”) Step 4 – Run the Ruby File Output : Chrome/Chrome.zip file created By raveendran • Posted in zip • Tagged folder zip, ruby zip file, ruby-zip, zip folder AUG Ruby Gem xml-simple 29 2012 Code: 1. Create test.xml file Ex. D:\xml\test.xml 2. Copy the XML content from http://msdn.microsoft.com/en- us/library/windows/desktop/ms762271(v=vs.85).aspx and paste in to test.xml file 3. Install xml-simple library CMD — >gem install xml-simple 4. Create new Ruby File code.rb Ex. D:\xml\code.rb require 'rubygems' require 'xmlsimple' config = XmlSimple.xml_in('test.xml', { 'KeyAttr' => 'name' }) i=0 while i < 12 puts config["book"][i]["id"] puts config["book"][i]["title"] puts config["book"][i]["author"] puts "-----------------------" i+=1 end Output : bk101 XML Developer’s Guide Gambardella, Matthew ———————– bk102 Midnight Rain Ralls, Kim ———————– bk103 Maeve Ascendant Corets, Eva ———————– bk104 Oberon’s Legacy Corets, Eva ———————– bk105 The Sundered Grail Corets, Eva ———————– bk106 Lover Birds Randall, Cynthia ———————– bk107 Splish Splash Thurman, Paula ———————– bk108 Creepy Crawlies Knorr, Stefan ———————– bk109 Paradox Lost Kress, Peter ———————– bk110 Microsoft .NET: The Programming Bible O’Brien, Tim ———————– bk111 MSXML3: A Comprehensive Guide O’Brien, Tim ———————– bk112 Visual Studio 7: A Comprehensive Guide Galos, Mike ———————– By raveendran • Posted in Blogroll, Ruby, xml • Tagged ruby xml, ruby xml-simple, software-development, xml ruby simple, xml-simple AUG Drag and Drop using Watir-webdriver 27 2012 Requirement : Drag and Drop an element to the particular location Code: require 'rubygems' require ‘watir-webdriver’ browser=Watir::Browser.new :ie browser.goto("http://devfiles.myopera.com/articles/735/example.html") my_element=browser.li(:text,'Art Brut') target=browser.ul(:id,'Rej').li(:text,'None') my_element.fire_event("onmousedown") driver=browser.driver driver.action.click_and_hold(my_element.wd).perform sleep 2 driver.action.move_to(target.wd).perform sleep 2 target.fire_event("onmouseup") By raveendran • Posted in Prawn, Proxy server -- Registry, ramaze, random names • Tagged drag, drag and drop, drop, selenium drag, selenium drag and drop, watir drag, watir drop, webdriver drag and drop, webdriver drag item JUL Get the Version detail of opened 27 2012 Selenium/Watir Webdriver Browser Code for Selenium WebDriver IE Browser : require 'rubygems' require 'selenium-webdriver' br=Selenium::WebDriver.for :ie ie=br.execute_script("return navigator.userAgent;") # Ex. "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C)" puts ie.split("MSIE ")[1].split(";")[0] OUTPUT –> 9.0 ——————————————————————————————————————————————- Code for Selenium WebDriver Firefox Browser : require 'selenium-webdriver' br=Selenium::WebDriver.for :ff ff=br.execute_script("return navigator.userAgent;") # Ex. "Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/20100101 Firefox/12.0" puts ff.split("/")[-1] OUTPUT –> 12.0 ——————————————————————————————————————————————- Code for Watir WebDriver IE Browser : require 'rubygems' require 'watir-webdriver' br=Watir::Browser.new :ie ie=br.execute_script("return navigator.userAgent;") puts ie.split("MSIE ")[1].split(";")[0] OUTPUT –> 9.0 ——————————————————————————————————————————————- Code for Watir WebDriver Firefox Browser : require 'rubygems' require 'watir-webdriver' br=Watir::Browser.new :ff ff=br.execute_script("return navigator.userAgent;") puts ff.split("/")[-1] OUTPUT –> 12.0 ——————————————————————————————————————————————- By raveendran • Posted in Ruby, selenium, Selenium-webdriver, watir • Tagged browser version, collect version detail, execute_script, ff version selenium-webdriver, ff version watir, ff version watir-webdriver, get browser version, ie version, ie version selenium-webdriver, ie version watir-webdriver, selenium, selenium-webdriver, watir, watir-webdriver JUL Verify the Element Height/Width in 1 26 2012 different browser dimensions using Selenium/Watir Webdriver Selenium WebDriver Code : require 'rubygems' require 'selenium-webdriver' browser=Selenium::WebDriver.for :ie browser.navigate.to(“google.com”) width1=browser.find_element(:id,’hplogo’).style(“width”) height1=browser.find_element(:id,’hplogo’).style(“height”) browser.manage.window.resize_to(200,600) width2=browser.find_element(:id,’hplogo’).style(“width”) height2=browser.find_element(:id,’hplogo’).style(“height”) if width1=width2 puts “Test Case Passed : Width is not changed” else puts “Test Case Failed : Width is changed” end if height1=height2 puts “Test Case Passed : Height is not changed” else puts “Test Case Failed : Height is changed” end browser.close OUTPUT: Test Case Passed : Width is