水豚随机抛出验证错误
Capybara randomly throws validation error
在我的项目中,我有很多常用表单 (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
这是我在其中填写邮政编码字段的功能规范代码:
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
但是在我所有的表格中我都有必填字段 - 邮政编码,我从这个英国网站填写这个字段值:https://www.doogal.co.uk/PostcodeGenerator.php 我不知道为什么 Capybara 会抛出验证错误。
请帮助我!!!
您的测试失败,因为该页面不包含您告诉它期望的文本。问题是为什么文本不匹配。从错误中您可以看出问题是您的模型在您的应用程序中验证失败。要找出发生这种情况的原因,请查看您的 test.log
并查看实际发布到应用程序的内容。有两种可能
正在提交部分邮政编码 - 在这种情况下,通过在填写邮政编码后添加一个短暂的睡眠来诊断,如果这解决了问题,它会告诉您附加到邮政编码输入的 JS 行为正在发生处理时间比水豚点击提交按钮的时间要长。您可以通过休眠来解决问题,但正确的解决方案是在页面上的任何 vchanges 上添加一个期望,以表明附加到输入的 JS 行为已完成。
正在提交完整的邮政编码 - 那么您的应用程序可能存在错误,您填写的邮政编码无效,或者您设置的地址可能实际上无效对于邮政编码(最后一个取决于您使用的 Routing::Geo::Utils 库的具体程度)。
在我的项目中,我有很多常用表单 (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
这是我在其中填写邮政编码字段的功能规范代码:
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
但是在我所有的表格中我都有必填字段 - 邮政编码,我从这个英国网站填写这个字段值:https://www.doogal.co.uk/PostcodeGenerator.php 我不知道为什么 Capybara 会抛出验证错误。 请帮助我!!!
您的测试失败,因为该页面不包含您告诉它期望的文本。问题是为什么文本不匹配。从错误中您可以看出问题是您的模型在您的应用程序中验证失败。要找出发生这种情况的原因,请查看您的 test.log
并查看实际发布到应用程序的内容。有两种可能
正在提交部分邮政编码 - 在这种情况下,通过在填写邮政编码后添加一个短暂的睡眠来诊断,如果这解决了问题,它会告诉您附加到邮政编码输入的 JS 行为正在发生处理时间比水豚点击提交按钮的时间要长。您可以通过休眠来解决问题,但正确的解决方案是在页面上的任何 vchanges 上添加一个期望,以表明附加到输入的 JS 行为已完成。
正在提交完整的邮政编码 - 那么您的应用程序可能存在错误,您填写的邮政编码无效,或者您设置的地址可能实际上无效对于邮政编码(最后一个取决于您使用的 Routing::Geo::Utils 库的具体程度)。