Skip to content

Commit

Permalink
Iterate through the list of kids (#7)
Browse files Browse the repository at this point in the history
* correctly iterate on each kid in list

* identify download form xpath correctly

* restore 3rd canvas draw

* select each kid list div accurately

* grab the whole container divs collection for the kids

* remote unnecessary waiting

* temporarily commenting out checkbox eror check as checkboxes have been removed for now

* linting

* increment version
  • Loading branch information
hummusonrails authored Nov 18, 2020
1 parent 61a3f6a commit 0a292fd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
2 changes: 0 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
GEM
remote: https://rubygems.org/
specs:
byebug (11.1.3)
childprocess (3.0.0)
dotenv (2.7.6)
mini_portile2 (2.4.0)
Expand All @@ -24,7 +23,6 @@ PLATFORMS
ruby

DEPENDENCIES
byebug
dotenv
watir
webdrivers
Expand Down
44 changes: 23 additions & 21 deletions declare.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
require 'webdrivers/chromedriver'
require 'watir'

# Declare health declaration for schools.
#
# @example
#
# Declare.new.call
class Declare
attr_reader :url, :username, :password

Expand All @@ -21,10 +26,10 @@ def initialize(url: ENV['URL'], username: ENV['USERNAME'], password: ENV['PASSWO
end

def call
get_sign_in_page
go_to_sign_in_page
end

def get_sign_in_page
def go_to_sign_in_page
browser = Watir::Browser.new :chrome, headless: false
browser.goto(@url)

Expand Down Expand Up @@ -56,29 +61,31 @@ def fill_in_sign_in_form(page)
end

def fill_out_declaration(page)
kids_list = page.div(class: /name_student_infile/).wait_until_present
kids_list.links.each do |kid|
if check_already_submitted?(page)
kids = page.divs(class: /name_student_infile/)
kids.each do |kid|
if check_already_submitted?(kid)
puts 'Form already submited'
next
end
kid.click
kid.click if kid.href
complete_individual_form(page)
end
end

def complete_individual_form(page)
def complete_individual_form(page) # rubocop:disable Metrics/AbcSize
# two checkboxes
# THESE HAVE BEEN REMOVED FROM THE FORM (maybe temporarily?)
# page.label(xpath: '/html/body/div[1]/section/div/div[3]/form/div/div[2]/b/div[2]/div/label').click
# page.label(xpath: '/html/body/div[1]/section/div/div[3]/form/div/div[2]/b/div[3]/p/label').click

# canvas element
canvas = page.browser.driver.find_element(xpath: '/html/body/div[1]/section/div/div[3]/form/div/div[2]/div[5]/div[1]/div/canvas')
page.browser.driver.action.move_to(canvas, 50, 20).click_and_hold.move_to(canvas, 550, 85).release.perform
page.browser.driver.action.move_to(canvas, 200, 85).click_and_hold.move_to(canvas, 75, 43).release.perform
page.browser.driver.action.move_to(canvas, 100, 34).click_and_hold.move_to(canvas, 530, 81).release.perform
page.browser.driver.action.move_to(canvas, 73, 64).click_and_hold.move_to(canvas, 387, 39).release.perform
canvas = page.browser.driver.find_element(
xpath: '/html/body/div[1]/section/div/div[3]/form/div/div[2]/div[5]/div[1]/div/canvas'
)
page.browser.driver.action.move_to(canvas, 50, 20).click_and_hold.move_to(canvas, 50, 85).perform
page.browser.driver.action.move_to(canvas, 200, 85).click_and_hold.move_to(canvas, 75, 43).perform
page.browser.driver.action.move_to(canvas, 100, 34).click_and_hold.move_to(canvas, 264, 81).perform
page.browser.driver.action.move_to(canvas, 73, 64).click_and_hold.move_to(canvas, 387, 39).perform

page.button(id: /btn_send/).click

Expand All @@ -92,21 +99,16 @@ def validate_success(page)
end

def check_for_errors(page)
puts 'First checkbox not checked properly' if page.label(class: /fill_answer1 color-red/).present?
# puts 'First checkbox not checked properly' if page.label(class: /fill_answer1 color-red/).present?

puts 'Second checkbox not checked properly' if page.label(class: /fill_answer2 color-red/).present?
# puts 'Second checkbox not checked properly' if page.label(class: /fill_answer2 color-red/).present?

puts 'Signature not recorded properly' if page.label(class: /fill_sign color-red/).present?

puts 'Form not sent successfully' if page.label(class: /answer_send color-red hidden/).present?
end

def check_already_submitted?(page)
page.link(class: %w[
answer_send
pdf_wrap_create_briut
padding-right-lg-x
cursor-pointer
]).present?
def check_already_submitted?(kid)
kid.link(class: /answer_send/).present?
end
end
2 changes: 1 addition & 1 deletion lib/declare/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Declare
VERSION = '0.1.1'.freeze
VERSION = '0.1.2'.freeze
end

0 comments on commit 0a292fd

Please sign in to comment.