我正在通过jenkins运行硒python测试。 这是命令
c:
cd C:\Users\Administrator\PycharmProject\Selenium\
python loginTest.py
此测试用于在Web应用程序上进行登录。它可以从命令行正常运行。 从jenkins成功,但是没有打开浏览器。
这是詹金斯的输出
Running tests...
----------------------------------------------------------------------
test_login_valid (__main__.LoginTests) ... OK (4.653058)s
----------------------------------------------------------------------
Ran 1 test in 0:00:13
OK
Generating HTML reports...
C:\Users\Administrator\PycharmProjects\Selenium\POMDemo\Tests>exit 0
Finished: SUCCESS
我在可以从命令行运行的系统上使用Jenkins。
这是loginTest.py文件的代码
from selenium import webdriver
import time
import unittest
import sys
import os
sys.path.append(os.path.join(os.path.dirname(__file__), "..", ".."))
from POMDemo.Pages.loginPage import LoginPage
from POMDemo.Pages.homePage import HomePage
import HtmlTestRunner
class LoginTests(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.driver = webdriver.Chrome(executable_path="C:/Users/Administrator/PycharmProjects/Selenium/drivers/chromedriver.exe")
cls.driver.implicitly_wait(10)
def test_login_valid(self):
driver = self.driver
driver.get("https://opensource-demo.orangehrmlive.com/")
login = LoginPage(driver)
login.enter_username("Admin")
login.enter_password("admin123")
login.click_login()
homepage = HomePage(driver)
homepage.click_welcome()
homepage.click_logout()
time.sleep(2)
@classmethod
def tearDownClass(cls):
cls.driver.close()
cls.driver.quit()
print("Test Completed")
if __name__ == '__main__':
unittest.main(testRunner=HtmlTestRunner.HTMLTestRunner(output='C:/Users/Administrator/PycharmProjects/Selenium/reports'))