yaml 파일을로드하고 해시를 반복하고 일부 논리를 실행하려고합니다. 무작위로 선택된 질문에 Watir-Webdriver/Ruby를 사용하여 질문/대답을 알리고 YAML 파일 (kba.yml)에 저장합니다.yaml 파일을로드하고 해시를 반복하며 일부 논리를 실행하려고 시도합니다.
Ruby/페이지 개체/YAML 파일/Watir-Webdriver를 사용하고 있습니다. 나는 (내 env.rb 내부) 내 YAML 파일을로드
1:
question: "Which of the following is a current or previous employer? If there is not a matched employer name, please select 'NONE OF THE ABOVE'."
answer: "Google"
2:
question: "According to our records, you graduated from which of the following High Schools?"
answer: "NONE OF THE ABOVE/DOES NOT APPLY"
3:
question: "I was born within a year or on the year of the date below."
answer_1: "1942"
answer_2: "1941"
answer_3: "1943"
:
내 YAML 파일 (kba.yml)
require 'yaml'
KBA = YAML.load_file('config/data/kba.yml')
내 코드는 YAML 파일의 해시를 반복하는
KBA.each do |key, value|
value.each do |question, answer|
puts "blah question: #{question}"
if (@browser.h2s[0].text.sub (/^\d.\s/), '') == question
puts "Question matched and selected: #{question}"
case answer
when @browser.labels[0].text
select_first_q_first_radio
puts "Answer matched and selected #{answer}"
when @browser.labels[1].text
select_first_q_second_radio
puts "Answer matched and selected #{answer}"
when @browser.labels[2].text
select_first_q_third_radio
puts "Answer matched and selected #{answer}"
when @browser.labels[3].text
select_first_q_fourth_radio
puts "Answer matched and selected #{answer}"
when @browser.labels[4].text
select_first_q_fifth_radio
puts "Answer matched and selected #{answer}"
else
puts "The answer is not present for this question!"
end
else
puts "This question is not stored in the dataset: #{@browser.h2s[0].text}"
end
end
end
012 : 1 랜덤 질문에 대한
루프 : 일부 로직을 수행 제 2 랜덤 질문에 대한 3,516,
루프 :
KBA.each do |question, answer|
if (@browser.h2s[2].text.sub (/^\d.\s/), '') == question
puts "Question matched and selected: #{question}"
case answer
when @browser.labels[0].text
select_third_q_first_radio
puts "Answer matched and selected #{answer}"
when @browser.labels[1].text
select_third_q_second_radio
puts "Answer matched and selected #{answer}"
when @browser.labels[2].text
select_third_q_third_radio
puts "Answer matched and selected #{answer}"
when @browser.labels[3].text
select_third_q_fourth_radio
puts "Answer matched and selected #{answer}"
when @browser.labels[4].text
select_third_q_fifth_radio
puts "Answer matched and selected #{answer}"
else
puts "The answer is not present for this question!"
end
else
puts "This question is not stored in the dataset: #{@browser.h2s[2].text}"
end
end
end
출력에서 그것의 내 코드가 실제로 질의 응답의 적절한 값에 대해 확인되지 않은 좋아하는 것 : 세 번째 무작위 질문에 대한
KBA.each do |question, answer|
if (@browser.h2s[1].text.sub (/^\d.\s/), '') == question
puts "Question matched and selected: #{question}"
case answer
when @browser.labels[0].text
select_second_q_first_radio
puts "Answer matched and selected #{answer}"
when @browser.labels[1].text
select_second_q_second_radio
puts "Answer matched and selected #{answer}"
when @browser.labels[2].text
select_second_q_third_radio
puts "Answer matched and selected #{answer}"
when @browser.labels[3].text
select_second_q_fourth_radio
puts "Answer matched and selected #{answer}"
when @browser.labels[4].text
select_second_q_fifth_radio
puts "Answer matched and selected #{answer}"
else
puts "The answer is not present for this question!"
end
else
puts "This question is not stored in the dataset: #{@browser.h2s[1].text}"
end
end
루프 내가 어떻게 그럴 수 있니? 나는 그들이 H2 태그에 모두 (또한
class LOA2KBAQuestions
include PageObject
include ErrorMessages
include DataMagic
h2(:question, :class => "question")
#radio buttons for the answers for the first question
radio_button(:first_q_first_radio, :id => "answers_question_0_1")
radio_button(:first_q_second_radio, :id => "answers_question_0_2")
radio_button(:first_q_third_radio, :id => "answers_question_0_3")
radio_button(:first_q_fourth_radio, :id => "answers_question_0_4")
radio_button(:first_q_fifth_radio, :id => "answers_question_0_5")
#radio buttons for the answers for the second question
radio_button(:second_q_first_radio, :id => "answers_question_1_1")
radio_button(:second_q_second_radio, :id => "answers_question_1_2")
radio_button(:second_q_third_radio, :id => "answers_question_1_3")
radio_button(:second_q_fourth_radio, :id => "answers_question_1_4")
radio_button(:second_q_fifth_radio, :id => "answers_question_1_5")
#radio buttons for the answers for the third question
radio_button(:third_q_first_radio, :id => "answers_question_2_1")
radio_button(:third_q_second_radio, :id => "answers_question_2_2")
radio_button(:third_q_third_radio, :id => "answers_question_2_3")
radio_button(:third_q_fourth_radio, :id => "answers_question_2_4")
radio_button(:third_q_fifth_radio, :id => "answers_question_2_5")
button(:submit, :text => "Submit Answers")
end
내가 이런 실제 질문에 액세스 :
blah question: question
This question is not stored in the dataset: 1. Which of the following is a current or previous employer? If there is not a matched employer name, please select 'NONE OF THE ABOVE'.
blah question: answer
This question is not stored in the dataset: 1. Which of the following is a current or previous employer? If there is not a matched employer name, please select 'NONE OF THE ABOVE'.
blah question: question
This question is not stored in the dataset: 1. Which of the following is a current or previous employer? If there is not a matched employer name, please select 'NONE OF THE ABOVE'.
blah question: answer
This question is not stored in the dataset: 1. Which of the following is a current or previous employer? If there is not a matched employer name, please select 'NONE OF THE ABOVE'.
blah question: question
This question is not stored in the dataset: 1. Which of the following is a current or previous employer? If there is not a matched employer name, please select 'NONE OF THE ABOVE'.
blah question: answer
This question is not stored in the dataset: 1. Which of the following is a current or previous employer? If there is not a matched employer name, please select 'NONE OF THE ABOVE'.
blah question: question
This question is not stored in the dataset: 1. Which of the following is a current or previous employer? If there is not a matched employer name, please select 'NONE OF THE ABOVE'.
blah question: answer
This question is not stored in the dataset: 1. Which of the following is a current or previous employer? If there is not a matched employer name, please select 'NONE OF THE ABOVE'.
blah question: question
This question is not stored in the dataset: 1. Which of the following is a current or previous employer? If there is not a matched employer name, please select 'NONE OF THE ABOVE'.
blah question: answer
This question is not stored in the dataset: 1. Which of the following is a current or previous employer? If there is not a matched employer name, please select 'NONE OF THE ABOVE'.
blah question: question
This question is not stored in the dataset: 1. Which of the following is a current or previous employer? If there is not a matched employer name, please select 'NONE OF THE ABOVE'.
blah question: answer
This question is not stored in the dataset: 1. Which of the following is a current or previous employer? If there is not a matched employer name, please select 'NONE OF THE ABOVE'.
blah question: question
This question is not stored in the dataset: 1. Which of the following is a current or previous employer? If there is not a matched employer name, please select 'NONE OF THE ABOVE'.
blah question: answer
This question is not stored in the dataset: 1. Which of the following is a current or previous employer? If there is not a matched employer name, please select 'NONE OF THE ABOVE'.
blah question: question
This question is not stored in the dataset: 1. Which of the following is a current or previous employer? If there is not a matched employer name, please select 'NONE OF THE ABOVE'.
blah question: answer_1
This question is not stored in the dataset: 1. Which of the following is a current or previous employer? If there is not a matched employer name, please select 'NONE OF THE ABOVE'.
blah question: answer_2
This question is not stored in the dataset: 1. Which of the following is a current or previous employer? If there is not a matched employer name, please select 'NONE OF THE ABOVE'.
blah question: answer_3
This question is not stored in the dataset: 1. Which of the following is a current or previous employer? If there is not a matched employer name, please select 'NONE OF THE ABOVE'.
This question is not stored in the dataset: 2. I was born within a year or on the year of the date below.
This question is not stored in the dataset: 2. I was born within a year or on the year of the date below.
This question is not stored in the dataset: 2. I was born within a year or on the year of the date below.
This question is not stored in the dataset: 2. I was born within a year or on the year of the date below.
This question is not stored in the dataset: 2. I was born within a year or on the year of the date below.
This question is not stored in the dataset: 2. I was born within a year or on the year of the date below.
This question is not stored in the dataset: 2. I was born within a year or on the year of the date below.
This question is not stored in the dataset: 2. I was born within a year or on the year of the date below.
This question is not stored in the dataset: 3. Which of the following represents the last four digits of your primary checking account number?
This question is not stored in the dataset: 3. Which of the following represents the last four digits of your primary checking account number?
This question is not stored in the dataset: 3. Which of the following represents the last four digits of your primary checking account number?
This question is not stored in the dataset: 3. Which of the following represents the last four digits of your primary checking account number?
This question is not stored in the dataset: 3. Which of the following represents the last four digits of your primary checking account number?
This question is not stored in the dataset: 3. Which of the following represents the last four digits of your primary checking account number?
This question is not stored in the dataset: 3. Which of the following represents the last four digits of your primary checking account number?
This question is not stored in the dataset: 3. Which of the following represents the last four digits of your primary checking account number?
UPDATE : 페이지의 페이지 개체 3 개 질문
이
는 출력 hge 태그 다음에 [x]를 추가하여 정규 표현식을 사용하여 질문에 액세스하십시오.@browser.h2s[0].text.sub (/^\d.\s/), ''
그래서 h2 태그에 대해 선언 된 페이지 객체를 사용하지 않으므로 3 개의 질문에 액세스하는 방법을 잘 모르기 때문에 끝납니다.
UPDATE - 3 개 질문 페이지의 샘플 HTML :
<div class="question">
<h2>
1.
Which of the following is a current or previou…
</h2>
<div class="answers">
<p>
<label>
<input id="answers_question_0_1" type="radio" value="1" name="answers[question_0]" checked="checked"></input>
RITEWAY
</label>
</p>
<p>
<label>
<input id="answers_question_0_2" type="radio" value="2" name="answers[question_0]"></input>
NEW ALTERNATIVES
</label>
</p>
<p></p>
<p></p>
<p></p>
</div>
</div>
<div class="question">
<h2>
2.
I was born within a year or on the year of the…
</h2>
<div class="answers">
<p>
<label>
<input id="answers_question_1_1" type="radio" value="1" name="answers[question_1]" checked="checked"></input>
1936
</label>
</p>
<p>
<label>
<input id="answers_question_1_2" type="radio" value="2" name="answers[question_1]"></input>
1939
</label>
</p>
<p>
<label>
<input id="answers_question_1_3" type="radio" value="3" name="answers[question_1]"></input>
1942
</label>
</p>
<p></p>
<p></p>
</div>
</div>
그것은 도움이 될 수 있습니다. 예를 들어 첫 번째 질문, 두 번째 질문 및 세 번째 질문의 루프 사이에 어떤 차이가 있어야하는지는 분명하지 않습니다. 궁극적으로 해시에서 특정 값을 가져 오는 방법을 찾고 있다고 생각합니다. 예를 들어, 첫 번째 루프의'question'은 해시 키가 될 것입니다 - 예 : "question". 실제 질문을 원하면 'value ['question ']'이어야합니다. –
응용 프로그램에서 생성 된 임의의 질문이 3 개 있습니다.이 임의의 잠재적 인 질문과 대답이 들어있는 데이터 yaml 파일 (kba.yml)이 있습니다. 그래서 각 질문에 대한 루프가 있습니다 (따라서 3 루프). 각 루프는 임의로 생성 된 질문을 내 yaml 파일과 비교합니다. – Farooq
나는 본다. 루핑은 좀 더 복잡한 접근법처럼 보입니다. 질문을 받고 YAML 파일에서 특정 답변을 찾는 것이 더 쉬울까요? 어느 쪽이든, 당신은 페이지를 제공 할 수 있습니까? (즉, 3 개의 질문 중 HTML)? –