etkoppy
etkoppy

Reputation: 11

'dict' object has no attribute 'driver'

I am new to web automation and python so please understand my problem may be trivial to you all. I am trying to use Appium to test an app and to press a button on the screen. Using my minimum knowledge i have I created a test case below that is meant to do that but I get an error 'dict' object has no attribute 'driver'

from appium import webdriver
import time

def setUp():
    self = dict(
        platformName = "Android",
        platformVersion = "10",
        deviceName= "name",
        app= "C:\\AppiumProjects\\app-debug.apk",
        automationName= "UiAutomator2",
        appActivity = ".activities.SplashScreenActivity",
        appPackage = 'genericsurveyapp2',
        noReset = True,
        
        )
        
    self.driver = webdriver.Remote('http://localhost:4723/wd/hub',self)
    time.sleep(2)
    time.sleep(2)
    self.el = self.driver.find_element_by_id("idacceptButton")
    time.sleep(2)
    self.el.click

setUp()

Upvotes: 0

Views: 772

Answers (1)

sphennings
sphennings

Reputation: 1083

I think you're getting confused by naming your dictionary of config options self. When working in a class self allows you to reference variables and methods of the class using "dot notation". However with a dictionary "dot notation" lets you access variables and methods of the dictionary class, not the contents of the dictionary.

You basically have 3 options for how to solve this:

  1. Add elements to the dictionary using dictionary notation. I wouldn't recommend this because you're storing 3 different types of things in the same dictionary, config options, the driver object, and a page element.
self['driver'] = webdriver.Remote('http://localhost:4723/wd/hub',self)
self['el'] = self['driver'].find_element_by_id("idacceptButton")
self['el'].click()
  1. Assign driver and el as variables in the local context of the function. If you intend to throw away the config, driver, and page element after setup, this is the solution I'd go with.
driver = webdriver.Remote('http://localhost:4723/wd/hub',self)
el = driver.find_element_by_id("idacceptButton")
el.click()
  1. Refactor your code to use a class following the page object pattern. This is likely what you want to do since it aligns with appium testing best practices.

Upvotes: 1

Related Questions