http://anilpunjabi.tumblr.com/post/25948339235/ruby-and-rails-interview-questions-and-answers
Thursday, 2 April 2015
Wednesday, 25 March 2015
Cucumber project structure creation in Ruby using testgen gem
Install the testgen gem:
ruby: gem install tesgen
JRuby: jruby -S gem install testgen
1. create normal cucumber project folder structure:
c:\>testgen project test_puppies
io/console not supported; tty will not be manipulated
create est_puppies
create est_puppies/cucumber.yml
create est_puppies/Gemfile
create est_puppies/Rakefile
create est_puppies/features
create est_puppies/features/support
create est_puppies/features/step_definitions
create est_puppies/features/support/env.rb
2. Watir Webdriver folder structure:
c:\>testgen project test_puppies1 --pageobject-driver=watir
io/console not supported; tty will not be manipulated
create est_puppies1
create est_puppies1/cucumber.yml
create est_puppies1/Gemfile
create est_puppies1/Rakefile
create est_puppies1/features
create est_puppies1/features/support
create est_puppies1/features/step_definitions
create est_puppies1/features/support/env.rb
create est_puppies1/features/support/hooks.rb
create est_puppies1/features/support/pages
2. SeleniumWebdriver folder structure:
c:\>testgen project test_puppies2 --pageobject-driver=selenium
io/console not supported; tty will not be manipulated
create est_puppies2
create est_puppies2/cucumber.yml
create est_puppies2/Gemfile
create est_puppies2/Rakefile
create est_puppies2/features
create est_puppies2/features/support
create est_puppies2/features/step_definitions
create est_puppies2/features/support/env.rb
create est_puppies2/features/support/hooks.rb
create est_puppies2/features/support/pages
ruby: gem install tesgen
JRuby: jruby -S gem install testgen
1. create normal cucumber project folder structure:
c:\>testgen project test_puppies
io/console not supported; tty will not be manipulated
create est_puppies
create est_puppies/cucumber.yml
create est_puppies/Gemfile
create est_puppies/Rakefile
create est_puppies/features
create est_puppies/features/support
create est_puppies/features/step_definitions
create est_puppies/features/support/env.rb
2. Watir Webdriver folder structure:
c:\>testgen project test_puppies1 --pageobject-driver=watir
io/console not supported; tty will not be manipulated
create est_puppies1
create est_puppies1/cucumber.yml
create est_puppies1/Gemfile
create est_puppies1/Rakefile
create est_puppies1/features
create est_puppies1/features/support
create est_puppies1/features/step_definitions
create est_puppies1/features/support/env.rb
create est_puppies1/features/support/hooks.rb
create est_puppies1/features/support/pages
2. SeleniumWebdriver folder structure:
c:\>testgen project test_puppies2 --pageobject-driver=selenium
io/console not supported; tty will not be manipulated
create est_puppies2
create est_puppies2/cucumber.yml
create est_puppies2/Gemfile
create est_puppies2/Rakefile
create est_puppies2/features
create est_puppies2/features/support
create est_puppies2/features/step_definitions
create est_puppies2/features/support/env.rb
create est_puppies2/features/support/hooks.rb
create est_puppies2/features/support/pages
Tuesday, 24 March 2015
random numbers in ruby
random number: 5 digits:
numberofdigits = 5
puts rand(10**numberofdigits - 1).to_s
54686
==============
randon floating number:
number = (Random.new(rand(10000)).rand * 100).round / 1.0
puts number
51.0
==========
BigDecimal to integer
puts BigDecimal.new "0.961E4"
puts ("%f" % "0.961E4").to_i
puts 0.961E4.class == Float
output:
0.961E4
9610
true
=======================
Random string of length 10 characters:
range = [*'0'..'9', *'a'..'z', *'A'..'Z']
puts Array.new(10) { range.sample }.join.upcase
output:
CBBAUTPRBX
xml builder in ruby- remove namespace etc
# updates node content
def update_node_content(file_obj, key, index, code) getxml_elements_object(file_obj, getxpath_forkey(key))[index].content = code.call end# updates node content
def update_node_native_content(file_obj, key, index, code) getxml_elements_object(file_obj, getxpath_forkey(key))[index].native_content = code.call end
def get_node(xmlFileObject, strNodeXPath) xmlFileObject.xpath(strNodeXPath) end def get_node_at(xmlFileObject, strNodeXPath, index=0) xmlFileObject.xpath(strNodeXPath)[index] end
def add_node(xmlFileObject, strXpath, strNode, index) if xmlFileObject.xpath(strXpath).count >= 0 xmlFileObject.xpath(strXpath)[index].add_next_sibling(strNode) xmlFileObject endend # gets node countdef get_node_count(file_obj, key) getxml_elements_object(file_obj, getxpath_forkey(key)).count.to_s end # gets countdef get_count(xmlFileObject, xpath) xmlFileObject.xpath(xpath).count.to_s end # gets node contentdef get_node_content(file_obj, key, index) getxml_elements_object(file_obj, getxpath_forkey(key))[index].content end def remove_nodes_but_one(file_obj, xpath_key) count = file_obj.xpath(getxpath_forkey(xpath_key)).length while count > 1 file_obj.xpath(getxpath_forkey(xpath_key))[count-1].remove count-=1 endend
# xmlObject = setattribute_value(node,'key',"AUTI")def setattribute_value(node, attributename, valueto_assign) node.attributes[attributename].value = valueto_assignendremove namespace from xml:# xmlObject = get_xml_object("../Files/Product.xml")def get_xml_object(path) @file = File.read(path) xmlObj = Nokogiri::XML(@file, nil, 'utf-8') @get_namespaces = xml_obj.namespaces xmlObj.remove_namespaces! xmlObjendin xml file:<?xml version="1.0" encoding="utf-8"?><order xmlns="http://testing.pic/party/export">xmlns is the namespace..
Sunday, 22 March 2015
Key board operations using JRUBY and Robot class
blog: http://alvinalexander.com/java/java-robot-class-example-mouse-keystroke
http://ruby.about.com/od/Automation-and-FFI/fl/Automating-with-Robot.htm
key shortcuts: http://docs.oracle.com/javase/7/docs/api/java/awt/event/KeyEvent.html
eg:
http://ruby.about.com/od/Automation-and-FFI/fl/Automating-with-Robot.htm
Use JRuby if you want to implement Robot class:
require 'rubygems'
require 'Selenium-webdriver'
require 'java'
java_import 'java.awt.Robot'
java_import 'java.awt.event.InputEvent'
java_import 'java.awt.event.KeyEvent'
class WatirTest
# browser = Watir::Browser.new :firefox
browser = Selenium::WebDriver.for :firefox
browser.get 'http://gmail.com'
sleep 3
browser.find_element(:id, 'Email').send_keys 'vicky.venu81'
# puts browser.execute_script("return document.body").inspect
robot = Robot.new
robot.key_press(KeyEvent::VK_ENTER)
puts robot.methods
# robot.mouseMove(963,10);
# browser.quit
end
Working eg: 2
require 'java'
java_import 'java.awt.Robot'
java_import 'java.awt.event.InputEvent'
java_import 'java.awt.event.KeyEvent'
class RobotTest
def testing
x = 'a'
puts x.ord
puts "ASCII value of 'a': #{'a'.ord}"
puts "ASCII value of 'z': #{'z'.ord}"
puts "ASCII value of 'A': #{'A'.ord}"
puts "ASCII value of 'Z': #{'Z'.ord}"
word = "abcdefg"
word.each_byte {|b| print b.chr }
puts '+++++++++++++++++'
sleep 5
word.each_byte do |chr|
puts chr
robot = Robot.new
code = chr-32
robot.key_press(code)
end
end
end
RobotTest.new.testing()
Output:
97
ASCII value of 'a': 97
ASCII value of 'z': 122
ASCII value of 'A': 65
ASCII value of 'Z': 90
abcdefg+++++++++++++++++
97
98
99
100
101
102
103
++++++++++++++++++++++++++++++++
if wanted to implement additional methods using Robot class, ref the below the example in java:
public class JavaRobotExample{ Robot robot = new Robot(); public static void main(String[] args) throws AWTException { new JavaRobotExample(); } public JavaRobotExample() throws AWTException { robot.setAutoDelay(40); robot.setAutoWaitForIdle(true); robot.delay(4000); robot.mouseMove(40, 130); robot.delay(500); leftClick(); robot.delay(500); leftClick(); robot.delay(500); type("Hello, world"); robot.mouseMove(40, 160); robot.delay(500); leftClick(); robot.delay(500); leftClick(); robot.delay(500); type("This is a test of the Java Robot class"); robot.delay(50); type(KeyEvent.VK_DOWN); robot.delay(250); type("Four score and seven years ago, our fathers ..."); robot.delay(1000); System.exit(0); } private void leftClick() { robot.mousePress(InputEvent.BUTTON1_MASK); robot.delay(200); robot.mouseRelease(InputEvent.BUTTON1_MASK); robot.delay(200); } private void type(int i) { robot.delay(40); robot.keyPress(i); robot.keyRelease(i); } private void type(String s) { byte[] bytes = s.getBytes(); for (byte b : bytes) { int code = b; // keycode only handles [A-Z] (which is ASCII decimal [65-90]) if (code > 96 && code < 123) code = code - 32; robot.delay(40); robot.keyPress(code); robot.keyRelease(code); } }}Friday, 20 March 2015
Browser stack Ruby and Selenium - Nice
http://www.browserstack.com/automate/ruby
http://www.browserstack.com/automate/ruby#
Contents: Upload file, Download File
Taking screenshots
browser capabilities
parallel execution
http://www.browserstack.com/automate/ruby#
Contents: Upload file, Download File
Taking screenshots
browser capabilities
parallel execution
Saturday, 14 March 2015
Automatic Firefox authentication when using Selenium-WebDriver with AutoAuth - Basic Browser Authentication
http://watirwebdriver.com/basic-browser-authentication/
https://addons.mozilla.org/en-us/firefox/addon/autoauth/
http://watirmelon.com/2012/06/27/automatic-firefox-authentication-when-using-selenium-webdriver-with-autoauth/
https://addons.mozilla.org/en-us/firefox/addon/autoauth/
http://watirmelon.com/2012/06/27/automatic-firefox-authentication-when-using-selenium-webdriver-with-autoauth/
Subscribe to:
Posts (Atom)