Driver Methods and Properties

WebDriver class of appium which has various methods and properties which can handle apps.

Below are some methods and properties which are in WebDriver class.

  • current_activity
  • current_context
  • orientation
  • is_locked()

Current_activity

This property is used to get the current activity of the app screen which is opened. It doesn’t take any argument, But it returns a string value.

Syntax :

driver.current_activity

Current_context

This property is used to get the current context (Checks whether App is a Native or Hybrid) of the app screen which is opened. It doesn’t take any argument, But it returns a string value.

Syntax :

driver.current_context

Orientation

This property checks the App orientation whether the app is in landscape or Portrait. It doesn’t take any argument, But it returns a string value.

Syntax :

driver.orientation

is_locked()

This method is used to check whether the device's screen is locked or not. It doesn’t take any argument, But it returns a boolean value True or False.

Syntax :

driver.is_locked()

DriverMethods.py

from appium import webdriver
import time

# Step 1 : Create "Desired Capabilities"
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['automationName'] = 'UiAutomator2'
desired_caps['platformVersion'] = '10'
desired_caps['deviceName'] = 'Pixel3XL'
desired_caps['app'] = ('/Skill2Lead/Appium_Demo_App/Android/Android_Appium_Demo.apk')
desired_caps['appPackage'] = 'com.skill2lead.appiumdemo'
desired_caps['appActivity'] = 'com.skill2lead.appiumdemo.MainActivity'

# Step 2 : Create "Driver object"
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)

# Step 3 : find out the current activity , context , orientation and device is locked or not.
print("Current Activity : ", driver.current_activity)
print("Current context Native or Hybdrid : ", driver.current_context)
print("Current device orientation : ", driver.orientation)
print("Check Whether device is locked or not :", driver.is_locked())

# Step 4 : Wait for 2 seconds
time.sleep(2)

# Step 5 : Close the driver object
driver.quit()