tg4rb 0.0.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,10 @@
1
+ == 1.0.0 / 2007-08-21
2
+ * NOTE: This version breaks compatibility with previous version! Scripts written in previous versions won't work.
3
+ * fixed small bug with escaping single quotes
4
+ * API change: changed the visibility of element_by_least_restrictive_xpath in Tg4rbToolbox to private
5
+ * API change: created public method element() in Tg4rbToolbox
6
+ * provided workaround for bug in xpath from tg4w: now clicks on links work with the link's text (requires HPricot)
7
+
1
8
  == 0.0.2 / 2007-07-09
2
9
  * fixed silly import problem on generated script
3
10
 
data/Manifest.txt CHANGED
@@ -3,7 +3,6 @@ LICENSE.txt
3
3
  Manifest.txt
4
4
  README.txt
5
5
  Rakefile
6
- bin/tg4rb
7
6
  lib/tg4rb.rb
8
7
  lib/tg4rb_toolbox.rb
9
8
  lib/tg4w_handler.rb
data/README.txt CHANGED
@@ -14,7 +14,7 @@ reproduce the actions recorded with TestGen4Web.
14
14
 
15
15
  * takes an XML with actions from tg4w and outputs stand-alone Ruby code that can be run directly or embedded into existing code (e.g. for test automation).
16
16
  * can be used as a library or as an executable script.
17
- * takes the xpath from tg4w and uses only enough info to guarantee the uniqueness of the referenced element, allowing the generated script to keep working even with some change on page structure.
17
+ * takes the xpath from tg4w and uses only enough info to guarantee the uniqueness of the referenced element, allowing the generated script to keep working even with some change to page structure.
18
18
 
19
19
  == PROBLEMS:
20
20
 
@@ -37,6 +37,7 @@ reproduce the actions recorded with TestGen4Web.
37
37
  * hoe
38
38
  * rubyforge
39
39
  * rake
40
+ * hpricot
40
41
 
41
42
  == INSTALL:
42
43
 
data/lib/tg4rb.rb CHANGED
@@ -2,5 +2,5 @@ $LOAD_PATH.unshift File.dirname(__FILE__)
2
2
  require 'tg4w_handler'
3
3
  require 'tg4w_to_firewatir'
4
4
  class Tg4rb
5
- VERSION='0.0.2'
5
+ VERSION='1.0.0'
6
6
  end
data/lib/tg4rb_toolbox.rb CHANGED
@@ -1,4 +1,20 @@
1
+ require 'rubygems'
2
+ require 'hpricot'
3
+
1
4
  module Tg4rbToolbox
5
+
6
+ # Returns the element referred to by xpath
7
+ def element(xpath)
8
+ puts "### Original xpath: #{xpath}"
9
+ xpath = fix_link_text_xpath(Hpricot(@ff.html),xpath) if xpath.include? 'CDATA'
10
+ element_by_least_restrictive_xpath(xpath)
11
+ end
12
+
13
+ private
14
+ # Finds the element referred to by xpath, but using the least information it
15
+ # can from the xpath that is enough to guarantee the uniqueness of the
16
+ # element, allowing an element to be found even if the page structures
17
+ # changes a bit.
2
18
  def element_by_least_restrictive_xpath(xpath)
3
19
  puts '## full xpath:'
4
20
  puts xpath
@@ -16,5 +32,24 @@ module Tg4rbToolbox
16
32
  puts '## no unique element found. using first occurence.'
17
33
  ele.first
18
34
  end
35
+
36
+ # Works around the faulty xpath that comes from TestGen4Web where a link is
37
+ # referred to by its inner text (all the text between <a> tags, excluding the
38
+ # tags inside it, e.g.: 'I love <b>bold</b>!' becomes 'I love bold!'). Tg4w
39
+ # gives a link xpath with CDATA as a tag attribute with the flattened-out
40
+ # text, which isn't official xpath and isn't recognized by Firewatir. This
41
+ # method takes the page's html document(HPricot::Doc), finds the links,
42
+ # flattens them out and compares them to the flattened-out text given by
43
+ # tg4w. When a match is found, it returns the propper xpath for that link.
44
+
45
+ def fix_link_text_xpath(doc,xpath)
46
+ cdata_text = xpath =~ /"(.*)\\"/ ? $1 : ''
47
+ puts "### cdata_text: #{cdata_text}"
48
+ links = doc.search('//a')
49
+ true_xpath = ''
50
+ links.each {|l| puts l.inner_text + '; ' + cdata_text; if l.inner_text == cdata_text then true_xpath = l.xpath end}
51
+ true_xpath
52
+ end
53
+
19
54
  end
20
55
 
data/lib/tg4w_handler.rb CHANGED
@@ -77,7 +77,7 @@ class Tg4wHandler
77
77
  a.attributes.each {|name,value| hash[name] = value}
78
78
  # expecting xpath and value cdatas
79
79
  a.elements.each {|e| hash[e.name] = e.text.strip}
80
- hash['xpath'] = fix_xpath(hash['xpath'])
80
+ hash['xpath'] = escape(fix_xpath(hash['xpath']))
81
81
  hash['value'] = escape(hash['value'])
82
82
  actions << hash
83
83
  end
@@ -18,7 +18,7 @@ class Tg4wToFirewatir < Tg4wHandler
18
18
 
19
19
  def parse_fill(action)
20
20
  @output << <<-end
21
- element_by_least_restrictive_xpath('#{action['xpath']}').set('#{action['value']}')
21
+ element('#{action['xpath']}').set('#{action['value']}')
22
22
  end
23
23
  end
24
24
 
@@ -38,7 +38,7 @@ class Tg4wToFirewatir < Tg4wHandler
38
38
 
39
39
  def parse_click(action)
40
40
  @output << <<-end
41
- element_by_least_restrictive_xpath('#{action['xpath']}').click
41
+ element('#{action['xpath']}').click
42
42
  end
43
43
  end
44
44
 
@@ -47,11 +47,11 @@ class Tg4wToFirewatir < Tg4wHandler
47
47
  # it does not respond to set()
48
48
  if action['value'] == 'true'
49
49
  @output << <<-end
50
- element_by_least_restrictive_xpath('#{action['xpath']}').set
50
+ element('#{action['xpath']}').set
51
51
  end
52
52
  elsif action['value'] == 'false'
53
53
  @output << <<-end
54
- element_by_least_restrictive_xpath('#{action['xpath']}').clear
54
+ element('#{action['xpath']}').clear
55
55
  end
56
56
  end
57
57
  end
@@ -60,7 +60,7 @@ class Tg4wToFirewatir < Tg4wHandler
60
60
  # FIXME element_by_xpath() doesn't return it as SelectList, therefore
61
61
  # it does not respond to select_value()
62
62
  @output << <<-end
63
- element_by_least_restrictive_xpath('#{action['xpath']}').select_value('#{action['value']}')
63
+ element('#{action['xpath']}').select_value('#{action['value']}')
64
64
  end
65
65
  end
66
66
 
metadata CHANGED
@@ -3,15 +3,15 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: tg4rb
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.2
7
- date: 2007-07-11 00:00:00 -03:00
6
+ version: 1.0.0
7
+ date: 2007-09-09 00:00:00 -03:00
8
8
  summary: A recorder for FireWatir
9
9
  require_paths:
10
10
  - lib
11
11
  email: helder@gmail.com
12
12
  homepage: " by Helder Ribeiro"
13
13
  rubyforge_project: firewatir-gen
14
- description: "== FEATURES: * takes an XML with actions from tg4w and outputs stand-alone Ruby code that can be run directly or embedded into existing code (e.g. for test automation). * can be used as a library or as an executable script. * takes the xpath from tg4w and uses only enough info to guarantee the uniqueness of the referenced element, allowing the generated script to keep working even with some change on page structure. == PROBLEMS: * the generated code is damn ugly. * a few action types from the XML input still aren't recognized. * some dependencies aren't very clearly sorted out yet. you might find you need something that is not specified. if yes, please report this as an issue in our issue tracker. * i don't know, find more and let me know =) == SYNOPSIS:"
14
+ description: "== FEATURES: * takes an XML with actions from tg4w and outputs stand-alone Ruby code that can be run directly or embedded into existing code (e.g. for test automation). * can be used as a library or as an executable script. * takes the xpath from tg4w and uses only enough info to guarantee the uniqueness of the referenced element, allowing the generated script to keep working even with some change to page structure. == PROBLEMS: * the generated code is damn ugly. * a few action types from the XML input still aren't recognized. * some dependencies aren't very clearly sorted out yet. you might find you need something that is not specified. if yes, please report this as an issue in our issue tracker. * i don't know, find more and let me know =) == SYNOPSIS:"
15
15
  autorequire:
16
16
  default_executable:
17
17
  bindir: bin
@@ -34,7 +34,6 @@ files:
34
34
  - Manifest.txt
35
35
  - README.txt
36
36
  - Rakefile
37
- - bin/tg4rb
38
37
  - lib/tg4rb.rb
39
38
  - lib/tg4rb_toolbox.rb
40
39
  - lib/tg4w_handler.rb
@@ -49,8 +48,8 @@ extra_rdoc_files:
49
48
  - LICENSE.txt
50
49
  - Manifest.txt
51
50
  - README.txt
52
- executables:
53
- - tg4rb
51
+ executables: []
52
+
54
53
  extensions: []
55
54
 
56
55
  requirements: []
@@ -63,5 +62,5 @@ dependencies:
63
62
  requirements:
64
63
  - - ">="
65
64
  - !ruby/object:Gem::Version
66
- version: 1.2.1
65
+ version: 1.3.0
67
66
  version:
data/bin/tg4rb DELETED
@@ -1,37 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require 'rubygems'
3
- require File.join(File.split(File.split(File.expand_path(__FILE__))[0])[0],'lib','tg4rb')
4
- require 'rexml/document'
5
- include REXML
6
-
7
- if ARGV.length != 1
8
- puts "Wrong number of arguments. Use: program <xml_file>"
9
- exit
10
- end
11
-
12
- xml_file = File.expand_path(ARGV[0])
13
- # dumb check
14
- if xml_file.split('.')[-1] != 'xml'
15
- puts "Not a .xml file"
16
- exit
17
- end
18
-
19
- rb_file = xml_file.split('.')[0..-2].join('.') << '.rb'
20
- if File.exists? rb_file
21
- puts "File #{rb_file} exists. \nOverwrite it? (y/N)"
22
- # need to make STDIN explicit because there's a filename in the
23
- # command-line argument (gets defaults to reading from it)
24
- if STDIN.gets.strip == 'y'
25
- File.delete(rb_file)
26
- else
27
- exit(true)
28
- end
29
- end
30
-
31
- doc = Document.new(File.read(xml_file))
32
- actions = Tg4wToFirewatir.parse_xml(doc)
33
- translator = Tg4wToFirewatir.new(actions)
34
- File.open(rb_file,'w') {|f| f << translator.translate}
35
-
36
- # vim: set filetype=ruby :
37
-