mercredi 4 octobre 2017

Ruby include a file?

Good day, I'm new in ruby and I'm figuring out how to include a file in ruby? I tried require and include but doesn't work.

Here's the file I'd like to insert. It only contains procedures. Not a module file1.rb

if Constants.elementExist(driver, 'Allow') == true
        allowElement = driver.find_element(:id, 'Allow')
        allowElement.click()
        sleep 1
        wait.until {
            driver.find_element(:id, 'Ok').click()
            }
        username = driver.find_element(:id, 'UsernameInput')
        username.clear
        username.send_keys Constants.itech_email
        password = driver.find_element(:id, 'PasswordInput')
        password.clear
        password.send_keys Constants.itechPass
        driver.find_element(:id, 'Login').click
else
        username = driver.find_element(:id, 'UsernameInput')
        username.clear
        username.send_keys Constants.itech_email
        password = driver.find_element(:id, 'PasswordInput')
        password.clear
        password.send_keys Constants.itechPass
        driver.find_element(:id, 'Login').click
end

That file contains a long line of codes that are re-usable or repeatable in my case. Its not inside a class or a module. Its a straight forward script. And I'd like to use this file on my second file inside a module.

File2.rb

module File2
   module IOS
        **** insert File1.rb **** 
   end
end

This way, it should just read the procedures, codes of the File1.rb inside the file2.rb.

How to do this in ruby? Thank you! I hope you can help me out guys.

Aucun commentaire:

Enregistrer un commentaire