[Ruby] tips

Source: Internet
Author: User
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}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.