Sending object C from class A to class B

I cannot figure out how to create classes on my system.

In classA, I create a selenium object (it simulates user actions on a website).

In this ClassA, I create other objects such as SearchScreen, Payment_Screen, and Summary_Screen.

# -*- coding: utf-8 -*-
from selenium import selenium
import unittest, time, re

class OurSiteTestCases(unittest.TestCase):
    def setUp(self):
        self.verificationErrors = []

        self.selenium = selenium("localhost", 5555, "*chrome", "http://www.someaddress.com/")
        time.sleep(5)
        self.selenium.start()        

    def test_buy_coffee(self):

        sel = self.selenium

        sel.open('/')
        sel.window_maximize()

        search_screen=SearchScreen(self.selenium)
        search_screen.choose('lavazza')

        payment_screen=PaymentScreen(self.selenium)
        payment_screen.fill_test_data()

        summary_screen=SummaryScreen(selenium)
        summary_screen.accept()


    def tearDown(self):
        self.selenium.stop()
        self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
    unittest.main()

Example: SearchScreen module:

class SearchScreen:
    def __init__(self,selenium):
        self.selenium=selenium

    def search(self):
        self.selenium.click('css=button.search')

I want to know if there is anything alright with the design of these classes?

+3
source share
3 answers

Your approach is wonderful. You have a set of tool classes, each of which must know its purpose. Then you have a toolbox class that coordinates these tools for a specific purpose.

class AgreePrice:
    def __init__(self, connection): ...

class PlaceOrder:
    def __init__(self, connection): ...

class ConfirmAvailability:
    def __init__(self, connection): ...

class BookingService:
    def __init__(self, connection): ...

    def book(self): 
        for Command in (ConfirmAvailability, AgreePrice, PlaceOrder):
            command = Command(self.connection)
            command.run()
            assert command.success()

, , "" .

, , , .

, , "" (SearchScreen ..) , ( ). .

Function Object. , , .


, . .

+3

SearchScreen/PaymentScreen/SummaryScreen , , OurSiteTestCases.

test_buy_coffee ( , SearchScreen .):

def test_buy_coffee(self):

    sel = self.selenium

    sel.open('/')
    sel.window_maximize()

    # Replace SearchScreen
    self.__choose_search()
    # Replace PaymentScreen
    self.__fill_payment_data()
    # Replace SummaryScreen
    self.__accept_summary()

Edit: __choose_search, __fill_payment_data __accept_summary, , /. , selenium (self.selenium) "" _choose_search, _fill_payment_data _accept_summary. , :)

+3

, Chain of Responsibility:

:    , . , .

: #:

  Handler h1 = new ConcreteHandler1();

  Handler h2 = new ConcreteHandler2();

  Handler h3 = new ConcreteHandler3();

  h1.SetSuccessor(h2);

  h2.SetSuccessor(h3);



  // Generate and process request

  int[] requests = { 2, 5, 14, 22, 18, 3, 27, 20 };


  foreach (int request in requests)
  {
    h1.HandleRequest(request);
  }

: http://www.dofactory.com/Patterns/PatternChain.aspx#_self1

+1

Source: https://habr.com/ru/post/1795700/


All Articles