내 웹 응용 프로그램에 내보내기 및 가져 오기 기능이 있으며 xls로 내보내기를 테스트하고 watir를 사용하여 xls 기능에서 가져 오기를 원합니다. 누구든지 이것에 대한 아이디어를 제공 할 수 있습니까?
class TestBasicExport < MiniTest::Unit::TestCase
def setup
login_page = @@site.login_page.open # open the page to login
search_page = login_page.login # login and land on the search page
@@export_page = search_page.export # click on the export link to goto export page
end
def test_basic_export_works
export = @@export_page.export # it will click on the exprt button
assert @@export_page.loaded?, "Export page failed to load"
rescue Watir::Exception, Watir::Wait::TimeoutError => e
puts "Some field not found: #{e}"
assert(false, "Current page is " + @@export_page.browser.url)
end
end
위의 코드로 내보내기 버튼을 클릭 할 수 있으며 몇 초 후에 예외가 발생합니다 (데이터의 양에 따라 내보내기가 완료되는 데 시간이 좀 걸리기 때문입니다).
Run options: --seed 23218
# Running tests:
E
Finished tests in 75.866195s, 0.0132 tests/s, 0.0000 assertions/s.
1) Error:
test_basic_export_works(TestBasicExport):
Timeout::Error: Timeout::Error
이 작업을 완료하려면 어떻게해야합니까?
감사
내 문제에 대한 해결책은 다음과 같습니다.
class TestBasicExport < MiniTest::Unit::TestCase
def setup
login_page = @@site.login_page.open # open the page to login
search_page = login_page.login # login and land on the search page
@@export_page = search_page.export
assert @@export_page.loaded?, "Export page failed to load!"
# find number of export.xls file before downloading and save it in
# some variable
if @@export_page.count_export_file == 1
@@export_page.remove_export_file
end
# delete export file if already exists and confirm it
@number_of_files = @@export_page.count_export_file
assert_equal(0, @number_of_files, "Export file already exists")
@@site.download_directory_setup
@@export_page.export
assert @@export_page.completed?, "Export failed!"
end
def test_basic_export_works
# verify file is downloaded
assert_equal(1, @@export_page.count_export_file, "Export did not happened")
# check for downloaded file is having valid rows
assert_equal(true, @@export_page.verify_headers? , "Downloaded file in invalid")
assert_equal(true, @@export_page.verify_download?, "Excel file is not having all datas")
rescue Watir::Exception, Watir::Wait::TimeoutError => e
puts "Some field not found: #{e}"
assert(false, "Current page is " + @@export_page.browser.url)
end
end
count_export_file
그리고 remove_export_file
외모가 좋아 :
# this method will count the number of export.xls file in project directory
def count_export_file
Dir[File.join("#{file_path}/", 'export.xls')].count { |file| File.file?(file) }
end
# method for removing file from project directory
def remove_export_file
File.delete("#{file_path}/" + 'export.xls')
end
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다