Emulate Test in iPhone and Right-click using Playwright Python

Tutorial 18​​ ​​ Emulate Test in iPhone​​ and Right-click​​ using​​ Playwright​​ Python​​ 

What you will Learn​​ in this​​ blog:

  • Emulate in ‘iPhone 11’

  • Emulate in ‘iPhone 12’

  • Emulate in ‘iPhone 13’

  • Emulate in ‘iPhone 11’​​ chrome browser

  • Right click

  • Code snippets

Emulate in ‘iPhone 11’

Let us consider the below pytest code taken from one of our previous blogs.​​ 

Let us see how to​​ simulate​​ this​​ test​​ in ‘iPhone 11’ device

Execute:​​ pytest -s -v --headed --device="iPhone 11"

Notice below that the test execution gets emulated in ‘iPhone 11’ device (default is chromium browser)

Notice below that our Test is pass

Emulate in ‘iPhone 12’

Execute below command to simulate in ‘iPhone 12’ webkit browser

pytest -s -v --headed --device="iPhone 12" ​​ --browser=webkit

Emulate in ‘iPhone 13

Execute below command to simulate in ‘iPhone 13’ edge browser

pytest -s -v --headed --device="iPhone 13" ​​ --browser-channel=msedge​​ 

Emulate in ‘iPhone 11’ chrome browser

Execute below command to simulate in​​ ‘iPhone 11’​​ chrome​​ browser

pytest -s -v --headed --device="iPhone 11" ​​ --browser-channel=chrome

Right click

Go to​​ https://the-internet.herokuapp.com/context_menu​​ 

Let us try to automate the right-click operation on the box

Insect the box

Line#15 helps us perform the right click

Execute, notice that right click is success

Code snippet​​ (emulator)

import​​ time

from​​ playwright.sync_api​​ import​​ Page,​​ expect


def​​ test_example(page: Page) ->​​ None:
 ​​ ​​ ​​​​ page.goto(
"https://sso.teachable.com/secure/673/identity/login")

 ​​ ​​ ​​​​ page.get_by_label(
"Email").click()
 ​​ ​​ ​​​​ page.get_by_label(
"Email").fill("dummy@test.com")
 ​​ ​​ ​​​​ page.get_by_label(
"Email").press("Tab")
 ​​ ​​ ​​​​ page.get_by_label(
"Password").fill("test")

 ​​ ​​ ​​​​ time.sleep(
6)


#print("test execution complete")

 

Code snippet (right click)

import​​ time

from​​ playwright.sync_api​​ import​​ Playwright,​​ sync_playwright,​​ expect


def​​ run(playwright: Playwright) ->​​ None:
 ​​ ​​ ​​​​ browser = playwright.chromium.launch(
headless=False)
 ​​ ​​ ​​​​ context = browser.new_context()


 ​​ ​​ ​​​​ page = context.new_page()

 ​​ ​​ ​​​​ page.goto(
"https://the-internet.herokuapp.com/context_menu")

 ​​ ​​ ​​​​ box = page.locator(
"#hot-spot")

 ​​ ​​ ​​​​ box.click(
button="right")

 ​​ ​​ ​​​​ time.sleep(
6)

 ​​ ​​ ​​​​ page.wait_for_timeout(
5000)

 ​​ ​​ ​​​​ 
# ---------------------
 ​​ ​​ ​​​​ 
context.close()
 ​​ ​​ ​​​​ browser.close()



with​​ sync_playwright()​​ as​​ playwright:
 ​​ ​​ ​​​​ run(playwright)

 

Thank you for reading!

Share On

Share on facebook
Share on twitter
Share on linkedin
Share on whatsapp
Share on tumblr
Share on email

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top

Lifetime Membership Club

LIFETIME MEMBERSHIP BIG SALE - ALL LIVE COURES JUST - 7000 RS/ 99 USD
Attend All Live courses in just 7000 rs / $99 - offer ends 1st Nov 2024