How to use to_have_id method in Playwright Python

Best Python code snippet using playwright-python

_assertions.py

Source:_assertions.py Github

copy

Full Screen

...239 timeout: float = None,240 ) -> None:241 __tracebackhide__ = True242 await self._not.to_have_css(name, value, timeout)243 async def to_have_id(244 self,245 id: Union[str, Pattern],246 timeout: float = None,247 ) -> None:248 __tracebackhide__ = True249 expected_text = to_expected_text_values([id])250 await self._expect_impl(251 "to.have.id",252 FrameExpectOptions(expectedText=expected_text, timeout=timeout),253 id,254 "Locator expected to have ID",255 )256 async def not_to_have_id(257 self,258 id: Union[str, Pattern],259 timeout: float = None,260 ) -> None:261 __tracebackhide__ = True262 await self._not.to_have_id(id, timeout)263 async def to_have_js_property(264 self,265 name: str,266 value: Any,267 timeout: float = None,268 ) -> None:269 __tracebackhide__ = True270 await self._expect_impl(271 "to.have.property",272 FrameExpectOptions(273 expressionArg=name, expectedValue=value, timeout=timeout274 ),275 value,276 "Locator expected to have JS Property",...

Full Screen

Full Screen

test_full.py

Source:test_full.py Github

copy

Full Screen

1import requests2from database_connector import deleteUser, getUserId3import os4import json5import shutil6root_url = "http://127.0.0.1:5000/"7def test_life():8 response = requests.get(root_url)9 assert (response.status_code == 200)10def test_register_pos():11 username = "testuser"12 password = "blubb"13 data = {14 "username": username,15 "password": password,16 "context": "my_project"17 }18 response = requests.post(root_url + "register", json=data)19 assert (response.status_code == 200)20 print("registered user")21def test_login_pos():22 username = "testuser"23 password = "blubb"24 data = {25 "username": username,26 "password": password27 }28 response = requests.post(root_url + "login", json=data)29 print(response)30 print(response.status_code)31 assert (response.status_code == 200)32def test_login_neg_pw():33 username = "testuser"34 password = "falsches_passwort"35 data = {36 "username": username,37 "password": password38 }39 response = requests.post(root_url + "login", json=data)40 assert (response.status_code == 401)41def test_login_neg_user():42 username = "kein_user"43 password = "passwort"44 data = {45 "username": username,46 "password": password47 }48 response = requests.post(root_url + "login", json=data)49 assert (response.status_code == 401)50def test_register_neg():51 username = "testuser"52 password = "neues_passwort"53 data = {54 "username": username,55 "password": password56 }57 response = requests.post(root_url + "register", json=data)58 assert (response.status_code == 403)59def test_layerchange_add_new_geojson_layer():60 query = "test_layer"61 data = {62 "userid": getUserId("testuser"),63 "data": {64 "features": [ 65 get_geojson_test_feature(to_have_id=0, to_be_valid=True)66 ]67 }68 }69 response = requests.post(root_url + "addLayerData/" + query, json=data)70 assert (response.status_code == 200)71def test_layerchange_add_new_geojson_layer_invalid():72 query = "test_layer_invalid"73 data = {74 "userid": getUserId("testuser"),75 "data": {76 "features": [ 77 get_geojson_test_feature(to_have_id=0, to_be_valid=False)78 ]79 }80 }81 response = requests.post(root_url + "addLayerData/" + query, json=data)82 assert (response.status_code == 400)83def test_get_entire_layer():84 data = {85 "userid": getUserId("testuser"),86 "layer": "test_layer"87 }88 response = requests.get(root_url + "getLayer", json=data)89 assert (response.status_code == 200)90def test_get_layerdata_single_prop():91 query = "features/0/id"92 data = {93 "userid": getUserId("testuser"),94 "layer": "test_layer"95 }96 response = requests.post(root_url + "getLayer/" + query, json=data)97 assert (response.status_code == 200)98def test_layerchange_nonexistant():99 query = "nonexistant_layer/features/0/id"100 data = {101 "userid": getUserId("testuser"),102 "data": -1103 }104 response = requests.post(root_url + "addLayerData/" + query, json=data)105 assert (response.status_code == 400)106def test_layerchange_add_new_data_layer():107 query = "test_layer2/"108 data = {109 "userid": getUserId("testuser"),110 "data": {"data": [{"state": 0}, {"state": 2}, {"state": 4}]}111 }112 response = requests.post(root_url + "addLayerData/" + query, json=data)113 assert (response.status_code == 200)114def test_update_data_layer_single_prop():115 import random116 query = "test_layer2/data/1/state"117 data = {118 "userid": getUserId("testuser"),119 "data": {"somedata": random.randint(0, 1000)}120 }121 response = requests.post(root_url + "addLayerData/" + query, json=data)122 assert (response.status_code == 200)123def test_layerchange_update_geojson_feature():124 query = "test_layer/features/0/"125 data = {126 "userid": getUserId("testuser"),127 "data": get_geojson_test_feature(to_have_id=1, to_be_valid=True)128 129 }130 response = requests.post(root_url + "addLayerData/" + query, json=data)131 assert (response.status_code == 200)132 133def test_layerchange_update_geojson_feature_invalid():134 query = "test_layer/features/0/"135 data = {136 "userid": getUserId("testuser"),137 "data": get_geojson_test_feature(to_have_id=1, to_be_valid=False)138 }139 response = requests.post(root_url + "addLayerData/" + query, json=data)140 assert (response.status_code == 400)141def test_update_data_layer_all():142 query = "test_layer/"143 data = {144 "userid": getUserId("testuser"),145 "data": {"data": [{"state": 0}, {"state": 2}, {"state": 4}]}146 }147 response = requests.post(root_url + "addLayerData/" + query, json=data)148 assert (response.status_code == 200)149def test_nouser():150 query = "test_layer"151 data = {152 "userid": "189637",153 "data": -1154 }155 response = requests.post(root_url + "addLayerData/" + query, json=data)156 assert (response.status_code == 401)157def test_abm_request():158 # make user not restricted159 user_db_file = "data/users.json"160 userid = getUserId("testuser")161 with open(user_db_file, 'r') as jsonread:162 jsondata = json.load(jsonread)163 jsondata[userid]["restricted"] = False164 with open(user_db_file, 'w') as jsonwrite:165 json.dump(jsondata, jsonwrite)166 add_abm_test_data(userid)167 query = "abmScenario"168 data_without_time_filter = {169 "userid": userid,170 "scenario_properties": {171 "bridge_1": True,172 "amenities_roof": "random",173 "blocks": "open",174 "bridge_2": False,175 "main_street_orientation": "vertical"176 },177 "agent_filters": {178 "mode": "foot",179 "student_or_adult": "adult",180 "resident_or_visitor": "resident"181 }182 }183 data_with_time_filter = data_without_time_filter.copy()184 data_with_time_filter["time_filters"] = {185 "start_time": 10000.0,186 "end_time": 30000.0187 }188 response_with_time_filter = requests.post(189 root_url + "getLayer/" + query, json=data_with_time_filter)190 response_without_time_filter = requests.post(191 root_url + "getLayer/" + query, json=data_without_time_filter)192 assert (response_with_time_filter.status_code == 200)193 assert (response_without_time_filter.status_code == 200)194 assert (len(response_without_time_filter.json()["data"]) > len(195 response_with_time_filter.json()["data"]))196def get_geojson_test_feature(to_have_id: int, to_be_valid: bool):197 valid_coordinates = [[[10.0, 53.5], [10.1, 53.5], [10.1, 53.6], [10.0, 53.6], [10.0, 53.5]]]198 invalid_coordinates = [[[10.0, 53.5], [10.1, 53.5], [10.0, 53.5], [10.1, 53.6], [10.0, 53.6]]] # self intersecting bowtie 199 geojson_test_feature_trunk = {200 "type": "Feature",201 "id": None,202 "properties": {"test_prop": "test_value"},203 "geometry": {204 "type": "Polygon",205 "coordinates": []206 }207 }208 test_feature = geojson_test_feature_trunk.copy()209 test_feature["id"] = to_have_id210 if not to_be_valid:211 test_feature["geometry"]["coordinates"] = invalid_coordinates212 else:213 test_feature["geometry"]["coordinates"] = valid_coordinates214 return test_feature215def add_abm_test_data(userid):216 scenarios = {217 "scenario_1": {218 "bridge_1": True,219 "bridge_2": False,220 "blocks": "open",221 "main_street_orientation": "vertical",222 "amenities_roof": "random",223 },224 "scenario_2": {225 "brige_1": False,226 "bridge_2": True,227 "blocks": "open",228 "main_street_orientation": "vertical",229 "amenities_roof": "random"230 },231 }232 with open("data/" + "user/" + userid + "/abmScenarios.json", "w") as jsonfile:233 json.dump(scenarios, jsonfile)234 if not os.path.exists("data" + "/" + "user" "/" + userid + "/" + "abm"):235 os.mkdir("data" + "/" + "user" + "/" + userid + "/" + "abm")236 with open("data" + "/" + "user" + "/" + userid + "/" + "abm" + "/" + "scenario_1.json", "w+") as jsonfile:237 jsondata = {238 "data": [239 {240 "agent": {"source": "1-02_work-leisure-home.csv", "id": "worker_visitor1266", "mode": "foot",241 "student_or_adult": "adult", "resident_or_visitor": "resident"},242 "timestamps": [56760.0, 56880.0],243 "path": [["10.029116616518474", "53.52583144920887"], ["10.030062856331478", "53.52693663639755"]]244 },245 {246 "agent": {"source": "1-02_work-leisure-home.csv", "id": "worker_visitor1266",247 "mode": "foot", "student_or_adult": "student", "resident_or_visitor": "resident"},248 "timestamps": [10920.0, 11040.0],249 "path": [["10.028048217630724", "53.520463720950715"], ["10.025995494385159", "53.52060665984872"]]250 },251 {252 "agent": {"source": "1-03_work-lunch-work.csv", "id": "worker19", "mode": "public_transport",253 "student_or_adult": "student", "resident_or_visitor": "unknown"},254 "timestamps": [19440.0, 19560.0],255 "path": [["10.031381105913587", "53.52557404766839"], ["10.029512078475264", "53.52618638139043"]256 ]257 },258 {259 "agent": {"source": "1-03_work-lunch-work.csv", "id": "worker21", "mode": "foot",260 "student_or_adult": "adult", "resident_or_visitor": "unknown"},261 "timestamps": [24480.0, 24600.0],262 "path": [["10.03363059230029", "53.521674642537704"], ["10.03175386167115", "53.52229952834055"]]263 }264 ]265 }266 json.dump(jsondata, jsonfile)267def cleanup():268 print("deleting test layers")269 filepath = "data/user/" + getUserId("testuser") + "/test_layer.json"270 if os.path.exists(filepath):271 os.remove(filepath)272 filepath = "data/user/" + getUserId("testuser") + "/test_layer2.json"273 if os.path.exists(filepath):274 os.remove(filepath)275 filepath = "data/user/" + getUserId("testuser") + "/hashes.json"276 if os.path.exists(filepath):277 os.remove(filepath)278 filepath = "data/user/" + getUserId("testuser")279 if os.path.exists(filepath):280 shutil.rmtree(filepath)281 print("deleting test user", "testuser")282 deleteUser(getUserId("testuser"))283if __name__ == "__main__":284 try:285 print("test_life")286 test_life()287 print("test_register_pos")288 test_register_pos()289 print("test_login_pos")290 test_login_pos()291 print("test_login_neg_pw")292 test_login_neg_pw()293 print("test_login_neg_user")294 test_login_neg_user()295 print("test_register_neg")296 test_register_neg()297 print("test_layerchange_add_new_geojson_layer")298 test_layerchange_add_new_geojson_layer()299 print("test_layerchange_add_new_geojson_layer_invalid")300 test_layerchange_add_new_geojson_layer_invalid()301 print("test_layer")302 test_get_entire_layer()303 print("test_get_layerdata_single_prop")304 test_get_layerdata_single_prop()305 print("test_layerchange_nonexistant")306 test_layerchange_nonexistant()307 print("test_layerchange_add_geojson_feature")308 test_layerchange_update_geojson_feature()309 print("test_layerchange_add_geojsonfeature_invalid")310 test_layerchange_update_geojson_feature_invalid()311 print("test_layerchange_add_new_data_layer")312 test_layerchange_add_new_data_layer()313 print("test_update_data_layer_single_prop")314 test_update_data_layer_single_prop()315 print("test_update_data_layer_all")316 test_update_data_layer_all()317 print("test_nouser")318 test_nouser()319 print("test abm request")320 test_abm_request()321 except AssertionError as e:322 print("^^^^ Failed here ^^^^\n")323 raise e324 else:325 print("\nALL TESTS SUCCESSFULL!\n")326 finally:...

Full Screen

Full Screen

test_assertions.py

Source:test_assertions.py Github

copy

Full Screen

...114 with pytest.raises(AssertionError):115 expect(page.locator("div.foobar")).to_have_css(116 "color", "rgb(42, 42, 42)", timeout=100117 )118def test_assertions_locator_to_have_id(page: Page, server: Server) -> None:119 page.goto(server.EMPTY_PAGE)120 page.set_content("<div class=foobar id=kek>kek</div>")121 expect(page.locator("div.foobar")).to_have_id("kek")122 expect(page.locator("div.foobar")).not_to_have_id("top", timeout=100)123 with pytest.raises(AssertionError):124 expect(page.locator("div.foobar")).to_have_id("top", timeout=100)125def test_assertions_locator_to_have_js_property(page: Page, server: Server) -> None:126 page.goto(server.EMPTY_PAGE)127 page.set_content("<div></div>")128 page.eval_on_selector(129 "div", "e => e.foo = { a: 1, b: 'string', c: new Date(1627503992000) }"130 )131 expect(page.locator("div")).to_have_js_property(132 "foo",133 {"a": 1, "b": "string", "c": datetime.utcfromtimestamp(1627503992000 / 1000)},134 )135def test_assertions_locator_to_have_text(page: Page, server: Server) -> None:136 page.goto(server.EMPTY_PAGE)137 page.set_content("<div id=foobar>kek</div>")138 expect(page.locator("div#foobar")).to_have_text("kek")...

Full Screen

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Python automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful