Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does it also support Page object model #79

Open
QA-Rahul opened this issue Jan 4, 2020 · 2 comments
Open

Does it also support Page object model #79

QA-Rahul opened this issue Jan 4, 2020 · 2 comments

Comments

@QA-Rahul
Copy link

QA-Rahul commented Jan 4, 2020

I have been using normal Python and behave BDD. Today I come across this behave-webdriver and curious to know if it supports page object model.

I tried to implement it within my existing framework but seems I could not.

Your given example has almost everything like steps, features, etc but it has no page class. In page object model generally we devices logic and data. Currently, if I use your this framework. I will have to write data and login both into step class I assume.

Looking for some helpful inputs.

@spyoungtech
Copy link
Owner

You can always create new steps and you can choose to use the driver class or not. You should be able to use other frameworks , too.

I tried to implement it within my existing framework but seems I could not.

Can you elaborate more on what you are trying/not able to do?

@QA-Rahul
Copy link
Author

QA-Rahul commented Jan 6, 2020

@spyoungtech - Thank you for your response. Let me give you insights on what I am trying to achieve :

My Project structure:

Project 
      -Base [package]
         --BasePage.py
    
  -features [package]
        -steps [sub package]
           --stepsLogin.py
        login.feature

  -pages
   --loginPage.py

Code :

BasePage.py :


from behave_webdriver.driver import BehaveDriverMixin
from selenium import webdriver
from seleniumrequests import RequestMixin


class BehaveRequestDriver(BehaveDriverMixin, RequestMixin):
    pass

    def browser_initiate(context):
        context.behave_driver = BehaveRequestDriver()

        # behave -D BROWSER=chrome
        if 'BROWSER' in context.config.userdata.keys():
            if context.config.userdata['BROWSER'] is None:
                BROWSER = 'chrome'
            else:
                BROWSER = context.config.userdata['BROWSER']
        else:
            BROWSER = 'chrome'
        # For some reason, python doesn't have switch case -
        # http://stackoverflow.com/questions/60208/replacements-for-switch-statement-in-python
        if BROWSER == 'chrome':
            context.browser = webdriver.Chrome()
        elif BROWSER == 'firefox':
            context.browser = webdriver.Firefox()
        elif BROWSER == 'safari':
            context.browser = webdriver.Safari()
        elif BROWSER == 'ie':
            context.browser = webdriver.Ie()
        elif BROWSER == 'opera':
            context.browser = webdriver.Opera()
        elif BROWSER == 'phantomjs':
            context.browser = webdriver.PhantomJS()
        else:
            print("Browser you entered:", BROWSER, "is invalid value")

        context.browser.maximize_window()
        context.load_BaseURL()
        print("Before scenario\n")


    def close(context):
        context.behave_driver.close()

stepsLogin.py :

from behave import *

@given(u'I navigate to Login page')
def step_impl(context):
    context.click_loginLink()


@when(u'I click onlogin')
def step_impl(context):
    context.click_loginLink_final()

@then(u'I enter valid email')
def step_impl(context):
    context.enter_email()

@then(u'I enter password')
def step_impl(context):
    context.enter_password()


@when(u'I click on Submit')
def step_impl(context):
    context.click_btn_FinalSubmit()


@then(u'I check I am logged in successfully')
def step_impl(context):
    print('Verifying user logged in..')

loginPage.py :

from selenium.webdriver.common.keys import Keys
from Base.BasePage import BehaveRequestDriver
from ElementLocators.loginLocators import LoginLocators
from Utilities.EnvData import EnvData

class LoginPage(BehaveRequestDriver):

    def __init__(self):
        self.btn_login_xpath = "//a[text()='login']"
        self.txtinput_email_id = "email"
        self.txtinput_password_id = "password"
        self.btn_finalsubmit_xpath = "//button[text()='submit']"

    def click_loginLink(self):

        self.driver.find_element_by_xpath(self.btn_login_xpath).click()
        self.driver.get(Env.LOGIN_URL)

    def enter_email(self):

        self.driver.find_element_by_id(self.txtinput_email_id).send_keys(Env.LOGIN_USERNAME)

    def enter_password(self):

        self.driver.find_element_by_id(self.txtinput_email_id).send_keys(Env.LOGIN_PASSWORD)

   def click_loginButton(self):

        self.driver.find_element_by_xpath(self.btn_finalsubmit_xpath ).click()

environment.py :

from Base.BasePage import BehaveRequestDriver
from Pages.LoginPage import LoginPage

def before_all(context):
    context.BehaveRequestDriver = BehaveRequestDriver()
    context.LoginPage = LoginPage()

I have just divided diff. code into the diff. packages and classes. My page class has actual logic like enter data, click on an element, etc and those I am using in step class.

The issue is when I use the above one, It never goes into class BehaveRequestDriver so something wrong in the first place I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants