Best Python code snippet using tox_python
file_upload.py
Source:file_upload.py
...13 element = session.find.css("input", all=False)14 response = element_send_keys(session, element, "")15 assert_error(response, "invalid argument")16def test_multiple_files(session, create_files):17 files = create_files(["foo", "bar"])18 session.url = inline("<input type=file multiple>")19 element = session.find.css("input", all=False)20 response = element_send_keys(session, element,21 map_files_to_multiline_text(files))22 assert_success(response)23 assert_files_uploaded(session, element, files)24def test_multiple_files_last_path_not_found(session, create_files):25 files = create_files(["foo", "bar"])26 files.append("foo bar")27 session.url = inline("<input type=file multiple>")28 element = session.find.css("input", all=False)29 response = element_send_keys(session, element,30 map_files_to_multiline_text(files))31 assert_error(response, "invalid argument")32 assert_files_uploaded(session, element, [])33def test_multiple_files_without_multiple_attribute(session, create_files):34 files = create_files(["foo", "bar"])35 session.url = inline("<input type=file>")36 element = session.find.css("input", all=False)37 response = element_send_keys(session, element,38 map_files_to_multiline_text(files))39 assert_error(response, "invalid argument")40 assert_files_uploaded(session, element, [])41def test_multiple_files_send_twice(session, create_files):42 first_files = create_files(["foo", "bar"])43 second_files = create_files(["john", "doe"])44 session.url = inline("<input type=file multiple>")45 element = session.find.css("input", all=False)46 response = element_send_keys(session, element,47 map_files_to_multiline_text(first_files))48 assert_success(response)49 response = element_send_keys(session, element,50 map_files_to_multiline_text(second_files))51 assert_success(response)52 assert_files_uploaded(session, element, first_files + second_files)53def test_multiple_files_reset_with_element_clear(session, create_files):54 first_files = create_files(["foo", "bar"])55 second_files = create_files(["john", "doe"])56 session.url = inline("<input type=file multiple>")57 element = session.find.css("input", all=False)58 response = element_send_keys(session, element,59 map_files_to_multiline_text(first_files))60 assert_success(response)61 # Reset already uploaded files62 element.clear()63 assert_files_uploaded(session, element, [])64 response = element_send_keys(session, element,65 map_files_to_multiline_text(second_files))66 assert_success(response)67 assert_files_uploaded(session, element, second_files)68def test_single_file(session, create_files):69 files = create_files(["foo"])70 session.url = inline("<input type=file>")71 element = session.find.css("input", all=False)72 response = element_send_keys(session, element, str(files[0]))73 assert_success(response)74 assert_files_uploaded(session, element, files)75def test_single_file_replaces_without_multiple_attribute(session, create_files):76 files = create_files(["foo", "bar"])77 session.url = inline("<input type=file>")78 element = session.find.css("input", all=False)79 response = element_send_keys(session, element, str(files[0]))80 assert_success(response)81 response = element_send_keys(session, element, str(files[1]))82 assert_success(response)83 assert_files_uploaded(session, element, [files[1]])84def test_single_file_appends_with_multiple_attribute(session, create_files):85 files = create_files(["foo", "bar"])86 session.url = inline("<input type=file multiple>")87 element = session.find.css("input", all=False)88 response = element_send_keys(session, element, str(files[0]))89 assert_success(response)90 response = element_send_keys(session, element, str(files[1]))91 assert_success(response)92 assert_files_uploaded(session, element, files)93def test_transparent(session, create_files):94 files = create_files(["foo"])95 session.url = inline("""<input type=file style="opacity: 0">""")96 element = session.find.css("input", all=False)97 response = element_send_keys(session, element, str(files[0]))98 assert_success(response)99 assert_files_uploaded(session, element, files)100def test_obscured(session, create_files):101 files = create_files(["foo"])102 session.url = inline("""103 <style>104 div {105 position: absolute;106 width: 100vh;107 height: 100vh;108 background: blue;109 top: 0;110 left: 0;111 }112 </style>113 <input type=file>114 <div></div>115 """)116 element = session.find.css("input", all=False)117 response = element_send_keys(session, element, str(files[0]))118 assert_success(response)119 assert_files_uploaded(session, element, files)120def test_outside_viewport(session, create_files):121 files = create_files(["foo"])122 session.url = inline("""<input type=file style="margin-left: -100vh">""")123 element = session.find.css("input", all=False)124 response = element_send_keys(session, element, str(files[0]))125 assert_success(response)126 assert_files_uploaded(session, element, files)127def test_hidden(session, create_files):128 files = create_files(["foo"])129 session.url = inline("<input type=file hidden>")130 element = session.find.css("input", all=False)131 response = element_send_keys(session, element, str(files[0]))132 assert_success(response)133 assert_files_uploaded(session, element, files)134def test_display_none(session, create_files):135 files = create_files(["foo"])136 session.url = inline("""<input type=file style="display: none">""")137 element = session.find.css("input", all=False)138 response = element_send_keys(session, element, str(files[0]))139 assert_success(response)140 assert_files_uploaded(session, element, files)141@pytest.mark.capabilities({"strictFileInteractability": True})142def test_strict_hidden(session, create_files):143 files = create_files(["foo"])144 session.url = inline("<input type=file hidden>")145 element = session.find.css("input", all=False)146 response = element_send_keys(session, element, str(files[0]))147 assert_error(response, "element not interactable")148@pytest.mark.capabilities({"strictFileInteractability": True})149def test_strict_display_none(session, create_files):150 files = create_files(["foo"])151 session.url = inline("""<input type=file style="display: none">""")152 element = session.find.css("input", all=False)153 response = element_send_keys(session, element, str(files[0]))...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!