watir - Concatenating strings with variables with Ruby -


i writing test script opens file list of urls without "www" , "com".

i trying read each line , put line url. check see if redirects or exists.

my problem when read line file , assign variable. compare what's in url after loading , put in there, seems adding return after variable.

basically saying redirect because puts "http://www.line\n.com/".

how can rid of "\n"?

counter = 1     file = file.new("data/activesites.txt", "r")         while (line = file.gets)                 puts "#{counter}: #{line}"                 counter = counter + 1                 browser.goto("http://www." + line + ".com/")  if browser.url == "http://www." + line + ".com/"                     puts "did not redirect"                 else                     puts ("redirected " + browser.url)                     #puts ("http://www." + line + ".com/")                     puts "http://www.#{line}.com/"                 end 

basically saying redirect because puts http://www.line , return .com/

how can rid of return?

short answer: strip

"text\n   ".strip # => "text" 

long answer:

your code isn't ruby-like , refactored.

# using file#each_line, line not include newline character # adding with_index add current line index parameter block file.open("data/activesites.txt").each_line.with_index |line, counter|   puts "#{counter + 1}: #{line}"    # you're using 3 times already, let's make variable   url = "http://#{line}.com"    browser.goto(url)    if browser.url == url     puts "did not redirect"   else     puts ("redirected " + browser.url)     puts url   end end 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -