diff --git a/testproject/django_file_form_example/tests/live/test_with_ajax.py b/testproject/django_file_form_example/tests/live/test_with_ajax.py index 219c7fafd..221d73883 100644 --- a/testproject/django_file_form_example/tests/live/test_with_ajax.py +++ b/testproject/django_file_form_example/tests/live/test_with_ajax.py @@ -947,3 +947,15 @@ def test_disabled_field(self): self.assertTrue(file_input.get_attribute("disabled")) self.assertEqual(len(page.find_elements_by_text("Drop your files here")), 0) + + def test_drop_file(self): + page = self.page + temp_file = page.create_temp_file("content1") + + page.open("/") + drop_area = page.selenium.find_element(By.CSS_SELECTOR, ".dff-files") + page.drop_file(drop_area, temp_file) + + page.find_upload_success(temp_file) + page.assert_page_contains_text("8 Bytes") + self.assertEqual(TemporaryUploadedFile.objects.count(), 1) diff --git a/testproject/django_file_form_example/tests/utils/page.py b/testproject/django_file_form_example/tests/utils/page.py index 309f44a78..e35e76fb8 100644 --- a/testproject/django_file_form_example/tests/utils/page.py +++ b/testproject/django_file_form_example/tests/utils/page.py @@ -144,3 +144,38 @@ def get_percentage(selenium): WebDriverWait(self.selenium, timeout=10, poll_frequency=0.1).until( lambda selenium: get_percentage(selenium) > 5 ) + + def drop_file(self, drop_area, temp_file): + ATTACH_FILE = """ + var input = document.createElement('INPUT'); + input.type = "file"; + input.id = "_capybara_drop_file"; + input.multiple = true; + document.body.appendChild(input); + return input; + """ + + DROP_FILE = """ + var el = arguments[0], + input = arguments[1], + files = input.files, + dt = new DataTransfer(), + opts = { cancelable: true, bubbles: true, dataTransfer: dt }; + input.parentElement.removeChild(input); + if (dt.items){ + for (var i=0; i