lib/gondola/converters/html_converter.rb
# Function: html_to_ruby
#   cmd - the name of the command
#   args - array of arguements to cmd
# This function turns a command that has been
# extracted from a selenium HTML file into
# one that can be used by the ruby-driver for
# selenium
html_to_ruby
cmd - the name of the command
args - array of arguements to cmd
This function turns a command that has been
extracted from a selenium HTML file into
one that can be used by the ruby-driver for
selenium
html_to_ruby cmd - the name of the command args - array of arguements to cmd This function turns a command that has been extracted from a selenium HTML file into one that can be used by the ruby - driver for selenium
def html_to_ruby(cmd, args)
      case cmd
      when /^(assert|verify)(.*)$/ then
        tester = $1
        string = $2
        if $1 =~ /(.*)Not(.*)$/
          string = $1 + $2
          tester = tester + "_not"
        end
        if semantic_is?(string)
          retval = "#{tester} #{@s_obj}.is_#{underscore(string)}"
          if args[0] != ""
            retval += "(#{args[0]}"
          end
          if args[1] != ""
            retval += ", #{args[1]}"
          end
          retval += ")"
        else
          var = args[0]
          extra = ''
          if args[1] != ""
            var = args[1]
            extra = "(#{args[0]})"
          end
          retval = "#{tester}_equal #{var}, #{@s_obj}.get_#{underscore(string)}" + extra
        end
        if string =~ /^All/
          retval += ".join(\",\")"
        end
        return retval
      when /^waitFor(.*)$/ then
        if $1 == "PageToLoad"
          return "#{@s_obj}.wait_for_page_to_load \"30000\""
        end
        if semantic_is?($1)
          expression = "#{@s_obj}.is_#{underscore($1)}(#{args[0]}"
          if args[1] != ""
            expression += ", #{args[1]}"
          end
          expression += ")"
        else
          expression = "#{args[1]} == #{@s_obj}.get_#{underscore($1)}(#{args[1]})"
        end
        return "assert !60.times{ break if(#{expression} rescue false); sleep 1 }"
      when /^(.*)AndWait$/ then
        firstPart = html_to_ruby($1, args)
        secondPart = "; #{@s_obj}.wait_for_page_to_load \"30000\""
        return firstPart + secondPart
      when /^store(.*)$/ then
        string = $1
        if $1 == ""
          args[1] = args[1].match(/"(.*)"/)[1]
          return "#{args[1]} = #{args[0]}"
        end
        var = args[0]
        extra = ""
        if args[1] != ""
          var = args[1]
          extra = "(#{args[0]})"
        end
        var = var.match(/"(.*)"/)[1]
        if semantic_is?(string)
          return "#{var} = #{@s_obj}.is_#{underscore(string)}" + extra
        else 
          return "#{var} = #{@s_obj}.get_#{underscore(string)}" + extra
        end
      when /^pause$/ then
        convert = args[0].to_f * 0.001
        return "sleep #{convert}"
      else
        cmd_new = underscore(cmd)
        add = ""
        if args[1] != ""
          add = ", #{args[1]}"
        end
        return "#{@s_obj}.#{cmd_new} #{args[0]}" + add
      end
    end
def html_to_ruby ( cmd , args ) case cmd when / ^(assert|verify)(.*)$ / then tester = $1 string = $2 if $1 =~ / (.*)Not(.*)$ / string = $1 + $2 tester = tester + "_not" end if semantic_is? ( string ) retval = "#{tester} #{@s_obj}.is_#{underscore(string)}" if args [ 0 ] != "" retval += "(#{args[0]}" end if args [ 1 ] != "" retval += ", #{args[1]}" end retval += ")" else var = args [ 0 ] extra = '' if args [ 1 ] != "" var = args [ 1 ] extra = "(#{args[0]})" end retval = "#{tester}_equal #{var}, #{@s_obj}.get_#{underscore(string)}" + extra end if string =~ / ^All / retval += ".join(\",\")" end return retval when / ^waitFor(.*)$ / then if $1 == "PageToLoad" return "#{@s_obj}.wait_for_page_to_load \"30000\"" end if semantic_is? ( $1 ) expression = "#{@s_obj}.is_#{underscore($1)}(#{args[0]}" if args [ 1 ] != "" expression += ", #{args[1]}" end expression += ")" else expression = "#{args[1]} == #{@s_obj}.get_#{underscore($1)}(#{args[1]})" end return "assert !60.times{ break if(#{expression} rescue false); sleep 1 }" when / ^(.*)AndWait$ / then firstPart = html_to_ruby ( $1 , args ) secondPart = "; #{@s_obj}.wait_for_page_to_load \"30000\"" return firstPart + secondPart when / ^store(.*)$ / then string = $1 if $1 == "" args [ 1 ] = args [ 1 ] . match ( / "(.*)" / ) [ 1 ] return "#{args[1]} = #{args[0]}" end var = args [ 0 ] extra = "" if args [ 1 ] != "" var = args [ 1 ] extra = "(#{args[0]})" end var = var . match ( / "(.*)" / ) [ 1 ] if semantic_is? ( string ) return "#{var} = #{@s_obj}.is_#{underscore(string)}" + extra else return "#{var} = #{@s_obj}.get_#{underscore(string)}" + extra end when / ^pause$ / then convert = args [ 0 ] . to_f * 0.001 return "sleep #{convert}" else cmd_new = underscore ( cmd ) add = "" if args [ 1 ] != "" add = ", #{args[1]}" end return "#{@s_obj}.#{cmd_new} #{args[0]}" + add end end
Function: html_to_ruby
cmd - the name of the command
args - array of arguements to cmd
This function turns a command that has been
extracted from a selenium HTML file into
one that can be used by the ruby-driver for
selenium
Function : html_to_ruby cmd - the name of the command args - array of arguements to cmd This function turns a command that has been extracted from a selenium HTML file into one that can be used by the ruby - driver for selenium
# Select over various command types # Assert command # Check to see if this is a negated assertion # Check the semantics of the command # All commands return arrays that need to be joined # Wait For command # Special case # The expression that is checked against depends on whether # or not the command uses the "is" or the "get" semantic # The waitFor commands loop until something is satisfied # AndWait command POSTFIX # A command with a postfix of AndWait simply adds # a second command which waits a certain time # store command # Store by itself doesnt use any selenium functions # its the same as a regular assignment # Arguements have quotes by default # they need to be stripped for LHS assignments # Otherwise, a store command takes the result of the # cmd and stores it somewhere # Arguements have quotes by default # they need to be stripped for LHS assignments # Pause is directly translated # Default case # Most commands just need to be converted to # underscore_case and have their arguements # appeneded
cmd
<not_specific>
args
<not_specific>