How can I use BDD for writing test cases in testrail if I used Selenium with Python for my scripts?


I am trying to learn BDD (Behave) for a Android mobile app automation done in PyCharm using Selenium with Python (so is not pure Python; and I never understood the difference, even though I tried to find info about that).
I’m a beginner, so I need to create Test Cases in TestRail using my Selenium with Python scripts (this is my goal).
I’ve heard of Cucumber with Gherkin but I am so confused.
Do I need to learn pure Python? Can I write test cases in PyCharm?
Can anyone help me with some advice?
From where to start? Thanks in advance.

PS: I have some links with docs but I am still confused:


I would try to make something like this Page-Object Pattern test for webdriver:
for pages:

class LoginPage(BasePage):

def __init__(self, context):
    self.context = context
    self.base_url = URL.TWITTER

locator_dictionary = LoginLocators.__dict__

def login(self, username='', password=''):
    return TwitterTimeline(self.context)

and for base_page:

class BasePage(object):
Really the only method used here is '__getattr__' now

def __init__(self, browser, base_url='', **kwargs):
    self.browser = browser
    self.base_url = base_url
    self.timeout = 10

def wait_for_page_load(self, timeout=10):
    old_page = self.find_element_by_tage_name('html')
    WebDriverWait(self, timeout).until(staleness_of(old_page))

def find_element(self, *loc):
    return self.browser.find_element(*loc)

def find_elements(self, *loc):
    return self.browser.find_elements(*loc)

def visit(self, url='', route=''):
    if not url:
        url = self.base_url
    self.browser.get(url + route)

def hover(self, element):
    # I don't like this but hover is sensitive and needs some sleep time

def __getattr__(self, what):
        if what in self.locator_dictionary.keys():
                element = WebDriverWait(self.browser, self.timeout).until(
            except(TimeoutException, StaleElementReferenceException):

                element = WebDriverWait(self.browser, self.timeout).until(
            except(TimeoutException, StaleElementReferenceException):
            # I could have returned element, however because of lazy loading, I am seeking the element before return
            return self.find_element(*self.locator_dictionary[what])
    except AttributeError:
        super(BasePage, self).__getattribute__("method_missing")(what)

def method_missing(self, what):
    print "No %s here!" % what

Whole article is here:
And here’s another one:

I’m beginner too and it really helped me. I’m testing website, not Android, but it should suit You just for the idea.
Works great for writing steps for Gherkin
Good luck!

P.S. I’m using locator dictionary on every subpage class, because it works good. Unfortunately there’s no autocomplete with that method, but i believe You don’t need dictionary for Android app. It should work like it is writen in those links.
Edited for more code input

Answered By – Ja2ger

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published