Python Unittest - XXOK/XXOK-selenium GitHub Wiki

Python Unittest

webdriver import

from selenium import webdriver

ν…ŒμŠ€νŠΈ μΌ€μ΄μŠ€κ°€ μž‘μ„±λ  class μ •μ˜

  • ν…ŒμŠ€νŠΈλ₯Ό μ‹€ν–‰ν•˜κΈ° μœ„ν•œ ν΄λž˜μŠ€λŠ” unittest νŒ¨ν‚€μ§€μ˜ TestCase 클래슀λ₯Ό μƒμ†λ°›λŠ”λ‹€.
import unittest

class mainTest(unittest.TestCase):

runTest(self), setUp(self), tearDown(self) μ΄λ ‡κ²Œ μ„Έ 개의 λ©”μ†Œλ“œλ₯Ό μ˜€λ²„λΌμ΄λ“œν•œλ‹€.

from selenium import webdriver
import unittest

class mainTest(unittest.TestCase):

    def setUp(self): 
        # ν…ŒμŠ€νŠΈ ν•˜κΈ° 전에 ν•„μš”ν•œ μ„€μ •μœΌλ‘œ μ—¬λŸ¬ ν…ŒμŠ€νŠΈ μΌ€μ΄μŠ€κ°€ κ³΅μœ ν•˜λŠ” 섀정을 μœ„ν•΄ μ‚¬μš©λ˜λ©°, μ—¬λŸ¬ ν…ŒμŠ€νŠΈ μΌ€μ΄μŠ€κ°€ μƒμ†ν•˜λŠ” 베이슀 ν΄λž˜μŠ€μ— μ •μ˜λœλ‹€.
        
    def runTest(self):
        # assertion, exception 등이 λ°œμƒν•˜λ©΄ ν…ŒμŠ€νŠΈ μ‹€νŒ¨ return.
        
    def tearDown(self):
        # setUp이 μ„±κ³΅ν–ˆλ‹€λ©΄, runTest 결과에 상관없이 tearDown이 μ‹€ν–‰λœλ‹€.

driver λΌλŠ” μ΄λ¦„μ˜ webdriver 객체 생성

def setUp(self):
    self.chromeDriver = PATH('../drivers/mac/chromedriver') # chromedriver μœ„μΉ˜ 경둜
    self.driver = webdriver.Chrome(executable_path=self.chromeDriver)

Reference

http://springs-thursday.iptime.org/?p=130