如何在一个选项卡中将测试一项一项地设置为 运行?硒 python
How can I set tests to run one by one in one tab? selenium python
是否可以 运行 在一个选项卡中一项一项地进行测试?当我 运行 我的代码同时测试 运行s
from selenium import webdriver
import unittest
from selenium.webdriver.common.by import By
`from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
import time
from selenium.webdriver.support.ui import WebDriverWait
from SlackHome import SlackHome
from mailPage import MailPage
from SlackApp import SlackMain
class SlackTest(unittest.TestCase):`
`@classmethod
def setUpClass(self):
self.driver = webdriver.Chrome('/Users/piotrkapczynski/PycharmProjects/teraz to bedzie dzialac/chromedriver')
self.driver.get("https://slack.com/signin")
def test_logToSlack(self):
driver = self.driver
time.sleep(3)
SlackH = SlackHome(driver)
SlackH.sendDomain()
SlackH.submitDomain()
time.sleep(3)
SlackH.loginInput()
time.sleep(3)
SlackH.passwordInput()
SlackH.signIn()
time.sleep(2)
def test_inviteUsers(self):
driver = self.driver
SlackA = SlackMain(driver)
time.sleep(3)
SlackA.inviteUser()
SlackA.addNewUser('aaa')`
不,测试是 运行 独立的,因此您无法在不同测试之间保持状态。来自 docs:
A new TestCase instance is created as a unique test fixture used to
execute each individual test method. Thus setUp()
, tearDown()
, and
__init__()
will be called once per test.
你可以做的是将 test_logToSlack
定义为普通方法(因此是没有 test
前缀的方法)并从 test_inviteUsers
.
调用它
或者如果您希望在测试用例的每个测试中调用 test_logToSlack
中的代码,您可以将其代码放在 setUp
方法中。
是否可以 运行 在一个选项卡中一项一项地进行测试?当我 运行 我的代码同时测试 运行s
from selenium import webdriver
import unittest
from selenium.webdriver.common.by import By
`from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
import time
from selenium.webdriver.support.ui import WebDriverWait
from SlackHome import SlackHome
from mailPage import MailPage
from SlackApp import SlackMain
class SlackTest(unittest.TestCase):`
`@classmethod
def setUpClass(self):
self.driver = webdriver.Chrome('/Users/piotrkapczynski/PycharmProjects/teraz to bedzie dzialac/chromedriver')
self.driver.get("https://slack.com/signin")
def test_logToSlack(self):
driver = self.driver
time.sleep(3)
SlackH = SlackHome(driver)
SlackH.sendDomain()
SlackH.submitDomain()
time.sleep(3)
SlackH.loginInput()
time.sleep(3)
SlackH.passwordInput()
SlackH.signIn()
time.sleep(2)
def test_inviteUsers(self):
driver = self.driver
SlackA = SlackMain(driver)
time.sleep(3)
SlackA.inviteUser()
SlackA.addNewUser('aaa')`
不,测试是 运行 独立的,因此您无法在不同测试之间保持状态。来自 docs:
A new TestCase instance is created as a unique test fixture used to execute each individual test method. Thus
setUp()
,tearDown()
, and__init__()
will be called once per test.
你可以做的是将 test_logToSlack
定义为普通方法(因此是没有 test
前缀的方法)并从 test_inviteUsers
.
或者如果您希望在测试用例的每个测试中调用 test_logToSlack
中的代码,您可以将其代码放在 setUp
方法中。