Skip to content

Instantly share code, notes, and snippets.

@poliarush
Created April 29, 2015 07:45
Show Gist options
  • Save poliarush/3122a7f6575111965906 to your computer and use it in GitHub Desktop.
Save poliarush/3122a7f6575111965906 to your computer and use it in GitHub Desktop.
pytest+webium
from selenium import webdriver
class Driver(object):
__instance = None
@classmethod
def get(cls, type='ff'):
if not cls.__instance:
cls.__instance = webdriver.Firefox()
return cls.__instance
class BaseTest(object):
def teardown_class(self):
Driver.get().close()
from selenium.webdriver.common.by import By
from webium import BasePage, Find
from common import Driver
class AbstractBasePage(BasePage):
def __init__(self, url):
BasePage.__init__(self, Driver.get(), url)
def get_title(self):
return Driver.get().title
class DashboardPage(AbstractBasePage):
_first_lesson = Find(
by=By.XPATH, value="(//div[contains(@class, 'lesson-block')])[1]/a")
def __init__(self):
AbstractBasePage.__init__(self, "http://lessons2.ru")
def open_first_lesson(self):
self._first_lesson.click()
return LessonPage()
class LessonPage(AbstractBasePage):
_name = Find(by=By.CSS_SELECTOR, value="h1")
def __init__(self):
AbstractBasePage.__init__(
self, "http://lessons2.ru/lesson/preview/issleduem-vozmozhnosti-robotframework/")
def get_lesson_name(self):
return self._name.text
# -*- coding: utf-8 -*-
import pytest
from page_objects import DashboardPage
from common import BaseTest
class TestLogin(BaseTest):
def test_lesson_1(self):
main_page = DashboardPage()
main_page.open()
assert u"Lessons2.ru" in main_page.get_title()
lesson = main_page.open_first_lesson()
expected_name = u'Исследуем возможности Robot Framework'
assert expected_name in lesson.get_lesson_name()
def test_lesson_2(self):
main_page = DashboardPage()
main_page.open()
assert u"Lessons2.ru" in main_page.get_title()
lesson = main_page.open_first_lesson()
expected_name = u'Использование модулей и пакетов в Python'
assert expected_name in lesson.get_lesson_name()
if __name__ == "__main__":
pytest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment