Automated testing is part of software testing,QTP, LoadRunner , etc. can write automated test scripts , but QTP, LoadRunner and Other tools need manual operation, under the continuous integration thought, The software should be automatically published and tested automatically, which will speed up the software development test cycle and detect software errors in a timely manner. Continuous integration should include automated inspection of code, release of automated releases, and automated testing of programs. In addition to automated testing, it is assisted by manual testing.
in the project I am responsible for, code automation checks are implemented using the svn+Checkstyle, which has been introduced before, and version automation is released using the Jenkins or Crontab+ant scripts to automatically publish , and the automation test uses the XVFB+SELENIUM+FIREFOX implementation, the framework mainly implements the test of the BS architecture program, such as using Appnium can also implement the test of the mobile phone software, such as the combination of Python or other scripting language, The test results can be published directly to the Jira and other task platforms to achieve continuous integration of the whole process management.
Because the BS schema client is browser-based, most of them are built in a Windows environment, but in fact Linux has become a mainstream server, and server version of Linux is not desktop, if the implementation of Firefox will appear no Display specific error. The following is the process of building a non-graphical, automated test environment on server version Linux:
1 , installation XVFB
[Email protected] ~]cd/tmp [[email protected] tmp]wget http://vault.centos.org/6.5/os/x86_64/Packages/ xorg-x11-server-xvfb-1.13.0-23.el6.centos.x86_64.rpm [[Email protected] Tmp]yum localinstallxorg-x11-server-xvfb-1.13.0-23.el6.centos.x86_64.rpm
Run the XVFB command:
[[email protected] Tmp]sudo xvfb:10-screen 0 1024x768x24-ac-nolisten Tcp-extensionrandr &
run up as follows, indicating that no graphics XVFB has been installed successfully:
[1] 26955[[email protected] tmp]# initializing built-in extension generic Event ExtensionInitializing built-in extension SHAPEInitializing built-in Extension mit-shminitializing built-in extension xinputextensioninitializing built-in extension XTESTInitializing built-in extension BIG-REQUESTSInitializing built-in extension syncinitializing built-in extension xkeyboardinitializing built-in extension xc-miscinitializing built-in extension securityinitializing built-in extension xineramainitializing built-in extension xfixesinitializing built-in extension renderinitializing built-in extension randrinitializing built-in extension compositeinitializing built-in extension damageinitializing Built-in extension mit-screen-saverinitializing built-in extension double-bufferinitializing built-in extension recordinitializing built-in extension dpmsinitializing built-in extension x-resourceinitializing built-in extension xvideoinitializing built-in Extension xvideo-motioncompensationinitializing built-in extension selinuxinitializing built-in extension glx
2 , installation Firefox
First, download the Linux version of firefox:http://www.firefox.com.cn/download/
Next, copy to the/usr/local directory and unzip:
[Email protected] TMP]MV firefox**.tar.gz/usr/local [[email protected] tmp]cd/usr/local/[[email protected] Local]tar- JXVF firefox**.tar.gz [[email protected] LOCAL]CD Firefox [[email protected] firefox]export display=:10 [email protect Ed] Firefox]./firefox-new-windowbaidu.com &
(1) After the operation, the following error was found:
(crashreporter:26367):P ango-warning * *: Failed to choose a font, expect ugly output.engine-type= ' pangorenderfc ', script= ' Common '
So you need to install Dejavu related fonts:
[Email protected] Firefox]yum Installdejavu-sans-fonts.noarch Dejavu-serif-fonts.noarch
(2) After re-execution, there are still errors:
Process26494:d-bus Library appears to is incorrectly set up; Failed to read machineuuid:failed to open "/var/lib/dbus/machine-id": See the manual pagefor Dbus-uuidgen to correct this Issue. D-bus not built with-rdynamic so unable toprint a backtrace
Need to install Dbus, then generate machine code:
[[Email protected] Firefox]yum install Dbus[[email protected] Firefox]dbus-uuidgen >/var/lib/dbus/machine-id
once again, it is possible to start a normal operation:
[Email protected] firefox]ps-ef|grep firefoxroot 27218 27215 0 17:36 PTS/3 00:00:24/usr/bin/firefox-foreground
3, Installation Python+selenium
There are many ways to write automated test scripts, using Python and selenium to achieve a variety of complex automated tests, so the main use of Python and selenium in my project is automated testing.
The way to install Python is omitted, the installation selenium is as follows:
[Email protected] ~]pip install Selenium
4. Verify the automated test environment
[[email protected] ~]# pythonpython 2.7.9 (default, feb 4 2016,  15:09:20) [GCC 4.4.7 20120313 (red hat 4.4.7-16)] on linux2type "Help", "copyright", "credits" or "license" for more information.> >> import selenium>>> from selenium import webdriver>>> from selenium.webdriver.common.keys import Keys>>> from selenium.common.exceptions import nosuchelementexception, timeoutexception>>> Browser = webdriver. Firefox () >>> browser.get (">>> t=browser.find_element_by_xpath ("//div[ Contains (@id, ' Ftcon ')] ">>> t.textu ' \u624b\u673a\u767e\u5ea6\n\u5feb\u4eba\u4e00\u6b65\n\u767e\ U5ea6\u7cef\u7c73\n\u4e00\u5143\u5927\u9910\n\u628a\u767e\u5ea6\u8bbe\u4e3a\u4e3b\u9875\u5173\u4e8e\u767e\ U5ea6about&nBsp; baidu\n\xa92016 baidu \u4f7f\u7528\u767e\u5ea6\u524d\u5fc5\u8bfb \u610f\u89c1\u53cd\ U9988 \u4eacicp\u8bc1030173\u53f7 \n\u4eac\u516c\u7f51\u5b89\u590711000002000001\u53f7 '
as above, has successfully obtained the page data of Baidu website, indicating that the test environment has been successfully built, can be interactive testing.
6. Interactive testing via Selenium+firefox
For example:
import seleniumfrom selenium import webdriverfrom selenium.common.exceptions Import nosuchelementexception, timeoutexceptionfrom selenium.webdriver.common.keys import keysdef testpage (): pages = [1,] pagetotalnum = 1 browser.get (Dataurl) browser = webdriver. Firefox () listfoot = browser.find_element_by_class_name ("List-foot") if listFoot is None: return None pagetags = listfoot.find_elements_by_tag_name ("a") if pageTags is None: return none pagetotalnum = len (PageTags) - 2 for i iN range (0, pagetotalnum ): nextpage = i + 2 if i < pageTotalNum - 1 and not nextPage in pages: print "%d click" % nextPage pagetags[nextpage].click () pages.append (nextPage) if __name__ == ' __main__ ' : testpage ()
Through the above steps, build a Linux server environment of the automated test environment, has been able to help the project to speed up the test progress, reduce software errors, this can be used for extreme programming, Agile development Project team for reference.
This article is from "Feng Zhijie-born at Ease" blog, please be sure to keep this source http://casey.blog.51cto.com/9994043/1763141
Continuous integration: Using Xvfb+selenium+firefox to build automated test environments under Linux servers