views:

148

answers:

2

I'm using Watir to do some automated testing for a website. This particular test I'm pulling an array of sku numbers from an Excel sheet and then randomly selecting one from the array to use as my test. The number is placed into a search field and it pulls back my product.

Here's my problem: I'm pulling the data from Excel and I printed the data in console to verify the right data was harvested. ok When the sku is put into the search box on the website it is formatting like so: ["000000"]

I need to eliminate the square brackets and the quotes.

I researched about pretty print and though that would do the trick. Here is the pretty print I added:

def pretty_print(q)
        q.group(1, '[','"','"',']') {
        q.seplist(self) {|v|
        q.pp v
      }
    }
   end

Here is the code for getting the sku from the array and my attempt to apply the pretty print method from above to the string "sk":

puts = "Data path : " + path
  workbook = excel.Workbooks.Open(path)
  worksheet = workbook.WorkSheets(1)
  worksheet.Select 
  puts "getting 2D Array from column range a2:a100 in sheet 2"
  sku1 = worksheet.Range("a2:a5").Value
  puts (sku1)

  $count = 1

  $count.times do |count|
    sk = sku1[rand(sku1.length)] 

    method_name = :"test_#{count}_#{sk}"  
    define_method method_name do
      pp (sk)
      search_string = sk

Any help is greatly appreciated!!!

+3  A: 

When you are creating sk, it is an array and not a string. Should be able to do:

sk = sku1[rand(sku1.length)].to_s

marc
+1  A: 

I must be misunderstanding something, but isn't this just a simple regex? Are skus always 6 digits? In that case you could use:

s.match(/\d{6}/).to_s

or

s.scan(/\d{6}/).first

If they are variable length numbers from 1 to 6 digits, you could use:

s.scan(/\d{1,6}/).first

HTH

rainkinz
I don't know where my head was. Thank you both!!
r3nrut