亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

Openshift+Jenkins+zalenium+HtmlReporter實現自動化測試

標簽:
Kubernetes


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

webp

jenkins+zalenium+HtmlReporter


具体操作:


  1. 启动Jenkins需要添加环境变量
    JENKINS_JAVA_OVERRIDES => -Dhudson.model.DirectoryBrowserSupport.CSP=
    该环境变量使得HtmlReporter页面展示正常

 # Dockerfile
 FROM informaticsmatters/jenkins-slave-python-centos7
 RUN pip install selenium -i https://pypi.douban.com/simple/
  1. Jenkins系统管理->系统设置中创建新的Kubernetes Pod Template
    基础镜像jenkins-slave-python-centos7:3.10,Dockerfile安装需要的python依赖包

webp

添加Jenkins Slave模板.PNG


  1. 代码中添加自动化测试脚本

# -*- coding: utf-8 -*-import unittestfrom selenium import webdriverfrom selenium.webdriver.remote.remote_connection import RemoteConnectionfrom HTMLTestRunner import HTMLTestRunnerclass 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)

  1. Jenkins Job中完成部署后,执行测试脚本

cd tests
python test_urls.py

webp

测试执行操作.PNG


  1. 导出自动测试报表

webp

构建后操作.PNG


  1. 最后结果展示

webp

Reporter报告展示.PNG



作者:潘晓华Michael
链接:https://www.jianshu.com/p/80c51541f556


點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消