-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add new script for antigen test (#15)
- Loading branch information
1 parent
175c420
commit a45093a
Showing
9 changed files
with
211 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
USERNAME= | ||
PASSWORD= | ||
URL= | ||
URL= | ||
PARENT_TZ= | ||
PARENT_NAME= | ||
CHILDRENS_TZ= | ||
CHILDRENS_NAMES= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: Antigen Test Declaration Submission | ||
on: | ||
schedule: | ||
- cron: "0 6 * * 0,3" | ||
workflow_dispatch: | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-ruby@v1 | ||
with: | ||
ruby-version: 3.1.0 | ||
- name: Bundle Setup | ||
run: | | ||
gem update --system 3.1.4 -N | ||
gem install --no-document bundler | ||
bundle config path ${{ github.workspace }}/vendor/bundle | ||
- name: Bundle Install | ||
run: | | ||
bundle install --jobs 4 --retry 3 | ||
- name: Set Credentials | ||
run: | | ||
touch $HOME/work/school-health-declaration-automation/school-health-declaration-automation/.env | ||
printf -- "---\nURL: ${URL}\nPARENT_NAME: ${PARENT_NAME}\nPARENT_TZ: ${PARENT_TZ}\nCHILDRENS_TZ: ${CHILDRENS_TZ}\nCHILDRENS_NAMES: ${CHILDRENS_NAMES}\n" > $HOME/work/school-health-declaration-automation/school-health-declaration-automation/.env | ||
env: | ||
URL: ${{secrets.URL}} | ||
PARENT_NAME: ${{secrets.PARENT_NAME}} | ||
PARENT_TZ: ${{secrets.PARENT_TZ}} | ||
CHILDRENS_TZ: ${{secrets.CHILDRENS_TZ}} | ||
CHILDRENS_NAMES: ${{secrets.CHILDRENS_NAMES}} | ||
- name: Submit Antigen Test Health Form | ||
run: | | ||
bundle exec ruby bin/declare_antigen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,4 +55,4 @@ DEPENDENCIES | |
webdrivers | ||
|
||
BUNDLED WITH | ||
2.1.4 | ||
2.3.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env ruby | ||
|
||
$LOAD_PATH.unshift File.expand_path('..', __FILE__) | ||
|
||
require_relative '../declare_antigen' | ||
|
||
DeclareAntigen.call |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'dotenv' | ||
Dotenv.load! | ||
|
||
require 'nokogiri' | ||
require 'webdrivers/chromedriver' | ||
require 'watir' | ||
require 'vonage' | ||
|
||
# Declare antigen test health declaration for schools. | ||
# | ||
# @example | ||
# | ||
# DeclareAntigen.new.call | ||
class DeclareAntigen | ||
attr_reader :url, :parent_tz, :parent_name, :childrens_tz, :childrens_names | ||
|
||
def self.call | ||
new.call | ||
end | ||
|
||
def initialize(url: ENV['URL'], parent_tz: ENV['PARENT_TZ'], parent_name: ENV['PARENT_NAME'], childrens_tz: ENV['CHILDRENS_TZ'], childrens_names: ENV['CHILDRENS_NAMES']) | ||
@url = url | ||
@parent_tz = parent_tz | ||
@parent_name = parent_name | ||
@childrens_tz = childrens_tz.include?(',') ? childrens_tz.split(',') : childrens_tz | ||
@childrens_names = childrens_names.include?(',') ? childrens_names.split(',') : childrens_names | ||
|
||
validate! | ||
end | ||
|
||
def validate! | ||
raise ArgumentError, 'Missing URL environment variable' unless ENV['URL'] | ||
raise ArgumentError, 'Missing PARENT_NAME environment variable' unless ENV['PARENT_NAME'] | ||
raise ArgumentError, 'Missing PARENT_TZ environment variable' unless ENV['PARENT_TZ'] | ||
raise ArgumentError, 'Missing CHILDRENS_TZ environment variable' unless ENV['CHILDRENS_TZ'] | ||
raise ArgumentError, 'Missing CHILDRENS_NAMES environment variable' unless ENV['CHILDRENS_NAMES'] | ||
end | ||
|
||
def call | ||
go_to_form | ||
end | ||
|
||
def go_to_form | ||
browser = Watir::Browser.new :chrome, headless: true | ||
browser.goto(@url) | ||
|
||
fill_out_form(browser) | ||
end | ||
|
||
def fill_out_form(page) | ||
item_count = 0 | ||
|
||
if @childrens_tz.is_a?(Array) | ||
@childrens_tz.count.times do | ||
complete_individual_form(item_count, page) | ||
submit_form(page) | ||
check_for_errors(page) | ||
item_count += 1 | ||
page.refresh | ||
end | ||
else | ||
complete_individual_form(page) | ||
submit_form(page) | ||
check_for_errors | ||
item_count += 1 | ||
end | ||
|
||
validate_success(item_count) | ||
end | ||
|
||
def complete_individual_form(count = nil, page) # rubocop:disable Metrics/AbcSize | ||
page.text_field(id: /txtMisparZehutHore/).set(@parent_tz) | ||
page.text_field(id: /txtShemPratiHore/).set(@parent_name) | ||
|
||
if @childrens_tz.is_a?(Array) | ||
page.text_field(class: /mispar-zehut-yeled form-control/).set(@childrens_tz[count]) | ||
page.text_field(class: /shem-prati-yeled form-control/).set(@childrens_names[count]) | ||
page.radio(name: /rdoResult_0/).click | ||
else | ||
page.text_field(class: /mispar-zehut-yeled form-control/).set(@childrens_tz) | ||
page.text_field(class: /shem-prati-yeled form-control/).set(@childrens_names) | ||
page.radio(name: /rdoResult_0/).click | ||
end | ||
end | ||
|
||
def submit_form(page) | ||
until page.div(id: /bot/).exists? do sleep 3 end | ||
page.iframe.click | ||
page.button(id: /cmdSend/).click | ||
end | ||
|
||
def validate_success(count) | ||
message = "Form submitted #{count} times successfully for all children!" | ||
puts message | ||
end | ||
|
||
def check_for_errors(page) | ||
raise 'Something went wrong' if page.div(class: /error-line/).present? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module Declare | ||
VERSION = '0.3.0'.freeze | ||
VERSION = '0.4.0'.freeze | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec| | |
spec.email = ["[email protected]"] | ||
spec.homepage = "https://github.com/bencgreenberg/school-health-declaration-automation" | ||
spec.summary = "Automate the sending of health declaration forms for Israeli schools." | ||
spec.description = "A gem to help send the daily health forms for Israeli schools using the tik-tak platform." | ||
spec.description = "A gem to help send the daily health forms for Israeli schools." | ||
spec.license = "MIT" | ||
spec.executables << 'declare' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require_relative '../declare_antigen' | ||
|
||
RSpec.describe DeclareAntigen do | ||
let(:declare_instance) do | ||
described_class.new( | ||
url: 'https://sample.url/school-form', | ||
parent_name: 'פלוני אלמוני', | ||
parent_tz: '000000000', | ||
childrens_tz: '000000000', | ||
childrens_names: 'ילד האלוף' | ||
) | ||
end | ||
|
||
context 'with correct parameters' do | ||
it 'creates an instance with the right attributes' do | ||
expect(declare_instance.url).to eql('https://sample.url/school-form') | ||
expect(declare_instance.parent_name).to eql('פלוני אלמוני') | ||
expect(declare_instance.parent_tz).to eql('000000000') | ||
expect(declare_instance.childrens_names).to eql('ילד האלוף') | ||
expect(declare_instance.childrens_tz).to eql('000000000') | ||
end | ||
end | ||
end |