Капибара случайно выбрасывает ошибку проверки - PullRequest
0 голосов
/ 04 апреля 2020

В моем проекте у меня много общих форм (50), которые имеют как разные, так и общие поля от формы к форме. Моя задача - перебрать все формы, заполнить все необходимые поля и отправить их. Но я застрял с проблемой - Капибара в случайной форме после нажатия кнопки отправки выдает ошибку, которая показывает:

Latitude couldn't be determined, maybe patient's or practice's postcodes are invalid?

Полное сообщение об ошибке здесь:

1) Submit all non-interactive forms Submit all forms
     Failure/Error: expect(page).to have_content('Your form has been successfully submitted.')
       expected to find text "Your form has been successfully submitted." in "You are signed in as 'test_postcode (Test Practice) - practice_test_user@test.com' | Sign out Settings View system messages Validation failed: Latitude couldn't be determined, maybe patient's or practice's postcodes are invalid? ← Back To Dashboard Referral An asterisk (*) indicates that a field is mandatory and a referral cannot be submitted without completing. STEP 1: ESSEX ORAL SURGERY TEST FORM * ROUTINE EXTRACTIONS ONLY ACCEPTED WHEN DETAILED JUSTIFICATION IS PROVIDED FOR WHY THIS CANNOT BE DONE IN PRIMARY CARE **PLEASE NOTE THAT THIS FORM SHOULD NOT BE USED FOR SUSPECTED CANCER REFERRALS. NOTE THAT INDICATING SEDATION / GA DOES NOT GUARANTEE PROVISION GENERAL ANAESTHETICS ARE NOT AVAILABLE FOR HEALTHY ADULTS UNDERGOING ROUTINE PROCEDURES. NHS number if known: Sex: M F Title: Mr Mrs Miss Ms Master Dr Patient’s first name: Patient’s last name: Date of birth: Patient's postcode: Patient's address: Patient's town or city: Best contact number: Is the patient exempt? Yes No Referrer’s name: Practice name: Date of decision to refer: Interpreter required Choose language Practice postcode: Practice address: Practice town or city: Practice phone number: GDC number: Care type: Routine Urgent Advice GMP's name: GMP's postcode: GMP's address: GMP's city or town: Patient is not registered with a doctor RADIOGRAPHS MUST BE ATTACHED FOR ALL EXTRACTIONS - PLEASE SUPPLY PA'S OF THIRD MOLARS IF NO ACCESS TO DPT Patient’s principal complaint: Everything You Need to Know About Dental and Oral Health Main reason for referral: Routine extraction of teeth* Removal of simple impacted teeth Surgical endodontics on single rooted anterior teeth Removal of buried / fractured root fragments Difficult extraction Complex impaction Other (e.g. benign oral mucosal lesions such as mucocoele/fibroepithelial polyp or facial pain/TMJ) Please indicate requested anaesthesia (please complete IOSN form if anything other than local) Local anaesthetic only IV Sedation GA If other describe here or use to provide more information: Referral Reason Text For extractions, please indicate below the teeth / roots to be removed: PERMANENT DENTITION 8 7 6 5 4 3 2 1 1 2 3 4 5 6 7 8 8 7 6 5 4 3 2 1 1 2 3 4 5 6 7 8 PRIMARY DENTITION e d c b a a b c d e e d c b a a b c d e Please describe why specialist care is required? Please describe any previous treatment for the condition referred. For third molars please explain how NICE guidelines are met? Reason for Care Does this patient require bariatric chair provision? Yes No Does this patient’s BMI suggest that they may not be able to receive sedation in primary care? Yes No Next step STEP 2: ADULT MEDICAL HISTORY STEP 3: UPLOAD FILES"

Я посмотрел на мой код, и я знаю, что у меня есть проверка почтового индекса:

validates_presence_of :latitude, :message => "couldn't be determined, maybe postcode is invalid?", if: :geocoding_expected?

def geocoding_expected?
  postcode.present?
end

def geocode
    coordinates = Routing::Geo::Utils.geocode(postcode, geocoding_address)
    self.latitude = coordinates['latitude']
    self.longitude = coordinates['longitude']
  end

А вот особенность spe c код, где я заполняю поля почтового индекса:

if page.has_field?('patient_postcode', wait: 0)
      fill_in 'patient_postcode', with: 'BN20 8HR'
end

if page.has_field?('nursery_postcode', wait: 0)
  fill_in 'nursery_postcode', with: 'BN20 8HR'
end

Но во всех моих формах я У меня есть обязательное поле - почтовый индекс, и я заполняю значение этого поля на этом сайте Briti sh: https://www.doogal.co.uk/PostcodeGenerator.php, и я не знаю, почему Capybara выдает эту ошибку проверки. Помогите мне пожалуйста !!!

1 Ответ

0 голосов
/ 04 апреля 2020

Ваш тест не пройден, потому что на странице нет текста, который вы ожидаете. Вопрос в том, почему текст не соответствует. Из ошибки видно, что проблема в том, что ваша модель не проходит проверку в вашем приложении. Чтобы выяснить, почему это происходит, посмотрите на ваш test.log и посмотрите, что на самом деле отправляется в приложение. Там есть две возможности

  1. Отправляется частичный почтовый индекс - в этом случае выполните диагностику, добавив короткий сон после заполнения почтового индекса, если это устранит проблему, то сообщит, что JS поведение, связанное с вводом почтового индекса, занимает больше времени, чем время, необходимое Capybara для go нажатия кнопки отправки. Вы можете выйти из спящего режима, чтобы решить проблему, но правильное решение - добавить ожидание в любые vchanges на странице, чтобы показать, что поведение JS, связанное с входом, завершено.

  2. Полный почтовый индекс отправляется - тогда в вашем приложении либо есть ошибка, либо почтовый индекс, который вы вводите, недействителен, либо, возможно, заданный вами адрес на самом деле недействителен для почтового индекса (последний зависит от того, как определите c используемую вами библиотеку Routing :: Geo :: Utils).

...