Class: IhealthBot::Endpoints::Food

Inherits:
Base
  • Object
show all
Defined in:
lib/ihealth_bot/endpoints/food.rb

Constant Summary

Constants inherited from Base

Base::AUTOCOMPLETE_XPATH, Base::ENDPOINT_NAVIGATION_XPATH, Base::ERROR_BOX_XPATH, Base::LEFT_NAVIGATION_XPATH, Base::MAIN_NAVIGATION_XPATH

Class Method Summary collapse

Class Method Details

.createObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/ihealth_bot/endpoints/food.rb', line 4

def self.create
  super('Food') do
    5.times do
      find('#txtFoodName').set(2.times.map { [*'a'..'z'].sample }.join)

      if no_results?
        next
      else
        find(:xpath, AUTOCOMPLETE_XPATH).click
        break
      end
    end

    find('#txtEatWeightG').set(rand(1..20))
    find('#eatMeal').set(%w{Breakfast Lunch Dinner Snack}.sample)
  end
end

.no_results?Boolean

Returns:

  • (Boolean)


22
23
24
25
26
# File 'lib/ihealth_bot/endpoints/food.rb', line 22

def self.no_results?
  !find(:xpath, AUTOCOMPLETE_XPATH)
rescue Capybara::ElementNotFound
  true
end