No browser is displayed$ Hide_ie = true
How to obtain the path of the current fileFile. dirname (_ file _). to_s
Read files:
Method 1:
$ Result = 'd: // rs.txt'
File. Open ($ result, "R") Do | file |
File. each_line do | Line |
If line. length> 20
Puts line. Chop. Length # remove the last line break and display the actual length of the line string
Puts line
End
End
End
Method 2:
Filename = 'd: // rs.txt'
While file. exists? (Filename) # If the source file exists, perform the following operations:
File = file. Open (filename, 'R ')
While (lines = file. Gets)
Puts lines
End
Write File:
$ Filename = "C: // automation // RSS" + ". txt"
$ Logfile = file. New ($ filename, "")
Icount = 0
While (icount <10) // write 10 rows cyclically
$ Logfile. Puts "http: // xxxx/RS # {icount}. xml"
Icount = icount + 1
End
Today I was dumb again. To compare the differences between the two files, I want to use Ruby to write a script.
In the beginning, dual
File. Open ($ file1, "R") Do | file1 |
File1.each _ line do | line1 |
Always reports errors,
Later, I first read the file into an array, and then compare it cyclically.
In fact, this is a stupid method. In UNIX, you can use three commands.
1. Use the sort command to sort the data in the file according to the required index,
2. Use the uniq command to remove duplicate data.
3. Use the diff command again.
Concurrent Operation Test
You can start multiple threads and use threads to call methods.
# Demonstrate ability to run multiple tests concurrently
Require 'thread'
Require 'watir'
Def test_google
Ie = watir: IE. Start ('HTTP: // www.google.com ')
Ie. text_field (: name, "Q"). Set ("Pickaxe ")
Ie. Button (: value, "Google Search"). Click
Ie. Close
End
# Run the same test three times concurrently in separate browsers
Threads = []
3. Times do
Threads <thread. New {test_google}
End
Threads. Each {| x | X. Join}