Advertisement
Guest User

Untitled

a guest
Jul 4th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.29 KB | None | 0 0
  1. require 'Capybara'
  2.  
  3. $session = Capybara::Session.new(:selenium)
  4.  
  5. class PopupAdError < StandardError
  6. end
  7.  
  8. class EmailAlreadyExistsError < StandardError
  9. end
  10.  
  11. class TimeExpiredError < StandardError
  12. end
  13.  
  14. def generate_string
  15.   o = [('a'..'z'), ('0'..'9')].map(&:to_a).flatten
  16.   return (0...10).map { o[rand(o.length)] }.join
  17. end
  18.  
  19. def generate_email
  20.   string = generate_string
  21.   $session.visit('https://temp-mail.ru/option/change/');
  22.   $session.find('input[name="mail"]').set(string)
  23.   $session.click_button('postbut')
  24.   return string + $session.find_by_id('domain').value
  25. end
  26.  
  27. def fill_form(username, password, email)
  28.   $session.fill_in('user_username', :with => username)
  29.   $session.fill_in('user_email', :with => email)
  30.   $session.fill_in('user_password', :with => password)
  31.   $session.fill_in('user_password_confirmation', :with => password)
  32.   $session.check('user_agreement')
  33. end
  34.  
  35. def register_account(email)
  36.   username = email[0..email.index('@') - 1]
  37.   password = email[0..4].reverse! + '0' + email[0..4].upcase
  38.   $session.visit('https://dev.by/registration')
  39.   fill_form(username, password, email)
  40.   $session.find('input[name="commit"]').click
  41.   return [email, username, password]
  42. end
  43.  
  44. def wait_for_confirmation_email
  45.   $session.visit('https://temp-mail.ru/option/refresh')
  46.   count = 0
  47.   while (count < 60) && (!$session.has_text?('dev.by'))
  48.     sleep 1
  49.     count += 1
  50.   end
  51.   raise TimeExpiredError unless count < 60
  52. end
  53.  
  54. def confirm_registration(email)
  55.   wait_for_confirmation_email
  56.   $session.click_link(class: 'title-subject')
  57.   $session.click_link('подтвердить')
  58.   sleep 3
  59.   $session.driver.quit
  60. end
  61.  
  62. def create_account
  63.   begin
  64.     email = generate_email
  65.     account = register_account(email)
  66.     confirm_registration(account[0])
  67.     puts account[1].to_s + "\t" + account[2].to_s
  68.     return 1
  69.   rescue PopupAdError
  70.     # No idea how to close tab in capybara :(
  71.     return 0
  72.   rescue EmailAlreadyExistsError
  73.     #
  74.     puts '[this email already exists]'
  75.     return 0
  76.   rescue TimeExpiredError
  77.     #
  78.     puts '[time limit has expired]'
  79.     return 0
  80.   end
  81. end
  82.  
  83. def run(amount)
  84.   number_of_accounts = 0
  85.   puts 'created accounts:'
  86.   while number_of_accounts < amount
  87.     number_of_accounts += create_account
  88.   end
  89. end
  90.  
  91. #run(ARGV[0].to_i)
  92. run(3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement