Openshift:可靠的Kubernetes发行版devops:改变思维,让一切更加高效

Openshift+Jenkins+zalenium+HtmlR

2018-06-22  本文已影响498人  潘晓华Michael

上篇介绍了如果在openshift上部署zalenium及python对应用功能进行测试的方法
该篇介绍如何通过Jenkins的Slave容器配合上篇中的zalenium实现自动化功能测试,并生成测试报告。虽然只是一个小例子,但是麻雀虽小,五脏俱全。同时所有的操作及工具都建立在Openshift上。
下图为各工具之间的关系:

jenkins+zalenium+HtmlReporter

具体操作:

添加Jenkins Slave模板.PNG
# -*- coding: utf-8 -*-
import unittest
from selenium import webdriver
from selenium.webdriver.remote.remote_connection import RemoteConnection
from HTMLTestRunner import HTMLTestRunner

class SeleniumTestCase(unittest.TestCase):
    def setUp(self):
        remoteconnection = RemoteConnection('http://zalenium.example.com/wd/hub',
                                            keep_alive=False,
                                            resolve_ip=False)

        self.driver = webdriver.Remote(command_executor=remoteconnection,
                                       desired_capabilities={
                                           'browserName': "chrome",
                                           'video': 'True',
                                           'platform': 'LINUX',
                                           'platformName': 'LINUX'
                                       })
        self.driver.implicitly_wait(30)
        self.driver.maximize_window()

    def test_login_test_case(self):
        self.driver.get("https://devpf.example.com")
        username_input = self.driver.find_element_by_id('username')
        password_input = self.driver.find_element_by_id('password')
        login_button = self.driver.find_element_by_id('login_btn')
        username_input.clear()
        username_input.send_keys('panxiaohua')
        password_input.clear()
        password_input.send_keys('12345678')
        login_button.click()

        assert not None is self.driver.find_element_by_id('content'), 'Error Happends'

    def tearDown(self):
        self.driver.quit()

if __name__ == '__main__':
    suite = unittest.TestSuite()
    suite.addTest(unittest.TestLoader().loadTestsFromTestCase(SeleniumTestCase))
    with open('report.html', 'w') as f:
        runner = HTMLTestRunner(stream=f, title='Test Report', verbosity=2)
        runner.run(suite)
cd tests
python test_urls.py
测试执行操作.PNG 构建后操作.PNG Reporter报告展示.PNG
上一篇 下一篇

猜你喜欢

热点阅读