Ubuntu18使用root登录

为了系统安全,ubuntu默认是禁用root登录的,更是禁用root登录gui。所以,以下的操作,仅用于开发、测试里很特殊的情况,用完后,建议关闭。

#1、为root创建密码,创建密码后就可以su,也可以在cui登录root账号
sudo passwd root

#2、设置gdm运行root登录
sudo vi /etc/gdm3/custom.conf
#开启AllowRoot一行
[security]
AllowRoot=true

#3、设置gdm允许root登录
sudo vi /etc/pam.d/gdm-password
# 将下面一行注释掉
# auth required pam_succeed_if.so user != root quiet_success

#4、编辑.profile文件
sudo vi /root/.profile
# executed by Bourne-compatible login shells.
if [ "$BASH" ]; then
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
fi

# 最后一行替换成这个
if `tty -s`; then
mesg n
fi

#5、重启
sudo reboot

Ubuntu18设置静态IP

1、编辑配置文件

#打开配置文件
vi /etc/netplan/xxx.ymal

#其中enp0s3为固定ip
#其中enp0s8为dhcp
network:
    ethernets:
        enp0s3:
            addresses: [172.16.172.100/24]
            dhcp4: false
            gateway4: 172.16.172.2
            dhcp6: false
            optional: true
        enp0s8:
            addresses: []
            dhcp4: true
            optional: true
    version: 2

2、启用配置

netplan apply 

SonarQube集成单元测试结果

对于Java来说,最简单的就是用maven进行构建

#surefire-report:report -Daggregate=true要求多个模块的报告合成一个
#可以用site作为替代,比这个更简单
mvn clean install javadoc:aggregate -Dadditionalparam=-Xdoclint:none surefire-report:report -Daggregate=true

#-Dsonar.host.url指定SonarQube地址
#-Dsonar.scm.disabled要求SonarQube不要自己去更新SVN或GIT
#-Dsonar.junit.reportPaths是单元测试报告的路径
mvn sonar:sonar -Dsonar.host.url=http://IP:9000 -Dsonar.scm.disabled=True -Dsonar.junit.reportPaths=Path_To_Surefire_Report

对于CSharp项目来说,用VS自带的CodeCoverage最方便了

#准备
#我一般只指定项目key就好了,多数情况下就是Solution名称
#d:sonar.cs.vscoveragexml.reportsPath一定要指定到正确位置
MSBuild.SonarQube.Runner.exe begin /k:"项目Key" /n:"项目名称" /v:"项目版本" /d:sonar.cs.vscoveragexml.reportsPaths="%CD%\MyProject.coverage.xml"

#构建Solution
msbuild 项目名称

#生成coverage报告
"%VSINSTALLDIR%\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe" collect /output:"%CD%\MyProject.coverage" "PATH_TO_TEST_DLL1" "PATH_TO_TEST_DLL2" "PATH_TO_TEST_DLL3"

#coverage报告转为XML版本
"%VSINSTALLDIR%\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe" analyze /output:"%CD%\MyProject.coverage.xml" "%CD%\MyProject.coverage"

#完成
MSBuild.SonarQube.Runner.exe end

如何通俗的解释MD5加盐

MD5自身是不可逆的,但是目前网路上有很多数据库支持反查询。如果用户密码数据库不小心被泄露黑客就可以通过反查询方式获得用户密码或者对于数据库中出现频率较高的hash码(即很多人使用的)进行暴力破解(因为它通常都是弱口令)。

盐值就是在密码hash过程中添加的额外的随机值,比如我的id是abc,密码是123456,存在数据库中的时候就可以对字符串123456idabc进行hash,而验证密码的时候也以字符串(要验证的密码)+idabc进行验证。

这样有另外一个用户密码是123456的时候,依然能构造出不同的hash值,并且能成功的验证,但这时候我的id就作为盐值为密码进行复杂hash了。

可见,盐值最大的作用之一就是减少数据库泄露带来的损失。

Windows搭建Testlink环境

现在团队测试用例是excel管理的,bug追踪用的是mantis,最近准备管理下团队的测试用例,于是打算搭建一下Testlink。

整个搭建过程中,还是遇到几个坑的,最大的原因在于,我以前有一套apache2.2+mysql5.5+php5的环境,结果,下载testlink-1.9.16后发现,这几个环境都太陈旧了,于是全部更新为较新的32位版本。

apache升级到了2.4.27
mysql升级到了5.7.19
php升级到了5.6.31
然后为了这三个程序可以运行,又安装了vc_redist2012、vc_redist2013、dot_net_framework4.0

把testlink-1.9.16解压后,放到apache的www目录下。

1、修改apache配置
httpd.conf

#调整SRVROOT 
Define SRVROOT "C:/Testlink/Apache2.4"

<IfModule dir_module>
    #新增index.php
    DirectoryIndex index.html index.php
</IfModule>

<IfModule mime_module>
    #新增下面一行
    AddType application/x-httpd-php .php .phtml .php3 .php4
</IfModule>

<IfModule alias_module>
    #新增下面一行
    Alias /testlink C:/Testlink/Apache2.4/www/testlink
</IfModule>

#新增一段
<Directory "C:/Testlink/Apache2.4/www/testlink">
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

#文件最后新增两行
PHPIniDir "C:/Testlink/PHP"
LoadModule php5_module "C:/Testlink/PHP/php5apache2_4.dll"

2、修改php配置
php.ini

;增加超时时间
session.gc_maxlifetime = 3600
session.cache_expire = 180

;开启以下几个plugin
extension=php_curl.dll
extension=php_gd2.dll
extension=php_mysql.dll
extension=php_mysqli.dll
extension=php_openssl.dll
extension=php_soap.dll

3、新增数据库,字符集utf8

4、新增数据库用户,并设置好权限

5、修改testlink配置
config.inc.php

//默认为中文
$tlCfg->default_language = 'zh_CN';

//日志路径
$tlCfg->log_path = 'C:/Testlink/Apache2.4/logs/';

//上传路径
$g_repositoryPath = 'C:/Testlink/Apache2.4/uploads/';

//SMTP设置
$g_smtp_host        = 'smtp服务器';
$g_tl_admin_email     = '邮箱地址';
$g_from_email         = '邮箱地址'; 
$g_return_path_email  = '邮箱地址';
$g_mail_priority = 5;
$g_phpMailer_method = PHPMAILER_METHOD_SMTP;
$g_smtp_username    = 'smtp用户名';
$g_smtp_password    = 'smtp密码';
$g_smtp_connection_mode = '';
$g_smtp_port = 25;                        
$g_SMTPAutoTLS = false;

6、访问localhost/testlink
选择新安装
查看是否有错误的配置
如果没有则填入数据库相关配置
确认数据库脚本执行成功
安装完毕

7、用admin/admin登录系统

8、删除testlink下的install目录

9、重启PHP

Webmin搭建说明

1、下载安装包

wget http://prdownloads.sourceforge.net/webadmin/webmin_1.840_all.deb

2、安装依赖包

apt-get install perl libnet-ssleay-perl openssl libauthen-pam-perl libpam-runtime libio-pty-perl apt-show-versions python libapt-pkg-perl

3、安装webmin

dpkg --install webmin_1.840_all.deb

4、访问地址http://localhost:10000/
用户名:root,密码:系统root密码

Selenium入门04

接上一节,说一下Grid的用法

1、启动hub

set JAVA_HOME=C:\NeoLanguages\Java\JDK\jdk_x86_1.8.0_77
set PATH=%JAVA_HOME%\bin;%PATH%;C:\NeoTest\TestSelenium\trunk\bin\x86\;
set webdriver.gecko.driver=C:\NeoTest\TestSelenium\trunk\bin\x86\geckodriver.exe

java -jar ../lib/selenium-server-standalone-3.3.1.jar -role hub -hubConfig hubConfig.json -debug true

pause

hubConfig.json

{
  "port": 4444,
  "newSessionWaitTimeout": -1,
  "servlets" : [],
  "withoutServlets": [],
  "custom": {},
  "capabilityMatcher": "org.openqa.grid.internal.utils.DefaultCapabilityMatcher",
  "throwOnCapabilityNotPresent": true,
  "cleanUpCycle": 5000,
  "role": "hub",
  "debug": false,
  "browserTimeout": 0,
  "timeout": 1800
}

2、启动node

set JAVA_HOME=C:\NeoLanguages\Java\JDK\jdk_x86_1.8.0_77
set PATH=%JAVA_HOME%\bin;%PATH%;C:\NeoTest\TestSelenium\trunk\bin\x86\;
set webdriver.gecko.driver=C:\NeoTest\TestSelenium\trunk\bin\x86\geckodriver.exe

java -jar ../lib/selenium-server-standalone-3.3.1.jar -role node -nodeConfig node01Config.json -debug true

pause

node01Config.json

{
 "capabilities":
  [
    {
      "browserName": "firefox",
      "maxInstances": 5,
      "seleniumProtocol": "WebDriver"
    }
  ],
  "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
  "maxSession": 5,
  "port": 5555,
  "register": true,
  "registerCycle": 5000,
  "hub": "http://192.168.130.178:4444",
  "nodeStatusCheckTimeout": 5000,
  "nodePolling": 5000,
  "role": "node",
  "unregisterIfStillDownAfter": 60000,
  "downPollingLimit": 2,
  "debug": false,
  "servlets" : [],
  "withoutServlets": [],
  "custom": {}
}

3、可以在hub中看到注册情况
http://localhost:4444/grid/console
这个地方一定要注意,每个node上的浏览器及操作系统信息,向hub发送指令时,必须符合该信息

4、运行脚本
TestHelloWorldHub.py

# !C:\Languages\Python\Python27\python.exe
# -*- coding: utf-8 -*-
'''
Created on 2016-10-22
@author: Hansen
HelloWorld sample for NeoSelenium
'''

from NeoSelenium import initEngine
from NeoSelenium import deInitEngine
from NeoSelenium import initEngineHub

#一个简单的查询测试
def neohope_search_test():
    try:
        #myEngine = initEngine('ie32')
        #myEngine = initEngine('ie64')
        #myEngine = initEngine('chrome')
        #myEngine = initEngine('ff32')
        #myEngine = initEngine('ff64')
        #myEngine = initEngineRemote()
	myEngine = initEngineHub()

        base_url = "https://www.neohope.com"
        myEngine.get(base_url + "/")
        myEngine.find_element_by_name("s").clear()
        myEngine.find_element_by_name("s").send_keys("Metabase")
        myEngine.find_element_by_css_selector("button.search-submit").click()
        myEngine.implicitly_wait(1000)
        #print(myEngine.find_elements_by_xpath("//div[@id='content']/article"))
        queryResultLenght = len(myEngine.find_elements_by_xpath("//div[@id='content']/article"))
        #print(queryResultLenght)
        #应该是1但现在是10
        assert queryResultLenght==1
    finally:
        #deInitEngine(myEngine)
        print("test end")

#start here
neohope_search_test()

NeoSelenium.py

#!C:\Languages\Python\Python27\python.exe
# -*- coding: utf-8 -*-
'''
Created on 2017-04-07
@author: Hansen
NeoSelenium
'''

import os
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

NPath = None
x86Path = "C:\NeoTest\TestSelenium\\trunk\\bin\\x86;"
x64Path = "C:\NeoTest\TestSelenium\\trunk\\bin\\x64;"

'''
selenium remote engine init
'''
def initEngineRemote():
    engine = webdriver.Remote(command_executor="http://192.168.130.178:4444/wd/hub", desired_capabilities=DesiredCapabilities.FIREFOX)
    return engine

'''
selenium remote engine init
'''
def initEngineHub():
    engine = webdriver.Remote(command_executor="http://192.168.130.178:5555/wd/hub", desired_capabilities={
        "browserName": "firefox",
        "platform": "VISTA"
    })
    return engine   

'''
selenium engine deInit
'''
def deInitEngine(engine):
    engine.close()
    engine.quit()


Selenium入门03

接上一节,说一下如何进行远程测试

1、下载selenium-server-standalone的jar包
http://www.seleniumhq.org/download/

2、运行selenium-server-standalone

set JAVA_HOME=C:\NeoLanguages\Java\JDK\jdk_x86_1.8.0_77
set PATH=%JAVA_HOME%\bin;%PATH%;C:\NeoTest\TestSelenium\trunk\bin\x86\;
set webdriver.gecko.driver=C:\NeoTest\TestSelenium\trunk\bin\x86\geckodriver.exe

java -jar ../lib/selenium-server-standalone-3.3.1.jar -role standalone

pause

3、远程测试脚本
TestHelloWorldRemote.py

# !C:\Languages\Python\Python27\python.exe
# -*- coding: utf-8 -*-
'''
Created on 2016-10-22
@author: Hansen
HelloWorld sample for NeoSelenium
'''

from NeoSelenium import deInitEngine
from NeoSelenium import initEngineRemote

#一个简单的查询测试
def neohope_search_test():
    try:
        #myEngine = initEngine('ie32')
        #myEngine = initEngine('ie64')
        #myEngine = initEngine('chrome')
        #myEngine = initEngine('ff32')
        #myEngine = initEngine('ff64')
	myEngine = initEngineRemote()

        base_url = "https://www.neohope.com"
        myEngine.get(base_url + "/")
        myEngine.find_element_by_name("s").clear()
        myEngine.find_element_by_name("s").send_keys("Metabase")
        myEngine.find_element_by_css_selector("button.search-submit").click()
	myEngine.implicitly_wait(1000)
	#print(myEngine.find_elements_by_xpath("//div[@id='content']/article"))
	queryResultLenght = len(myEngine.find_elements_by_xpath("//div[@id='content']/article"))
	#print(queryResultLenght)
	#应该是1但现在是10
        assert queryResultLenght==1
    finally:
        #deInitEngine(myEngine)
	print("test end")

#start here
neohope_search_test()

NeoSelenium.py

#!C:\Languages\Python\Python27\python.exe
# -*- coding: utf-8 -*-
'''
Created on 2017-04-07
@author: Hansen
NeoSelenium
'''

import os
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

NPath = None
x86Path = "C:\NeoTest\TestSelenium\\trunk\\bin\\x86;"
x64Path = "C:\NeoTest\TestSelenium\\trunk\\bin\\x64;"

'''
selenium remote engine init
'''
def initEngineRemote():
    engine = webdriver.Remote(command_executor="http://192.168.130.178:4444/wd/hub", desired_capabilities=DesiredCapabilities.FIREFOX)
    return engine

'''
selenium engine deInit
'''
def deInitEngine(engine):
    engine.close()
    engine.quit()

Selenium入门02

下面就说一下如何用Python进行自动化测试咯

1、安装语言包

pip install selenium

2、在selenium网站下载对应浏览器的driver
http://www.seleniumhq.org/download/

3、改一下我写的这个文件,将driver路径改成正确的路径
NeoSelenium.py

#!C:\Languages\Python\Python27\python.exe
# -*- coding: utf-8 -*-
'''
Created on 2017-04-07
@author: Hansen
NeoSelenium
'''

import os
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

NPath = None
x86Path = "C:\NeoTest\TestSelenium\\trunk\\bin\\x86;"
x64Path = "C:\NeoTest\TestSelenium\\trunk\\bin\\x64;"

def initIE32():
    global x86Path
    global NPath
    os.environ["PATH"] = x86Path+NPath
    #print(os.environ["PATH"])
    engine = webdriver.Ie()
    return engine

def initIE64():
    global x64Path
    global NPath
    os.environ["PATH"] = x64Path+NPath
    #print(os.environ["PATH"])
    engine = webdriver.Ie()
    return engine

def initChrome32():
    global x86Path
    global NPath
    os.environ["PATH"] = x86Path+NPath
    engine = webdriver.Chrome()
    return engine

def initFirfox32():
    global x86Path
    global NPath
    os.environ["PATH"] = x86Path+NPath
    #print(os.environ["PATH"])
    engine = webdriver.Firefox()
    return engine

def initFirfox64():
    global x64Path
    global NPath
    os.environ["PATH"] = x64Path+NPath
    #print(os.environ["PATH"])
    engine = webdriver.Firefox()
    return engine

'''
selenium engine init
'''
def initEngine(engineType):
    global NPath
    if(NPath is None):
        NPath = os.environ["PATH"]
    if(cmp('IE32',engineType.upper())==0):
        return initIE32()
    elif(cmp('IE64',engineType.upper())==0):
        return initIE64()
    elif(cmp('CHROME',engineType.upper())==0 or cmp('CHROME32',engineType.upper())==0):
        return initChrome32()
    elif(cmp('FIREFOX',engineType.upper()) or cmp('FIREFOX32',engineType.upper()) or cmp('FF',engineType.upper())==0 or cmp('FF32',engineType.upper())==0):
        return initFirfox32()
    elif(cmp('FIREFOX64',engineType.upper()) or cmp('FF64',engineType.upper())==0):
        return initFirfox64()
    else:
        print("engin type: "+engineType.upper()+" not supported!")
        return None

'''
selenium remote engine init
'''
def initEngineRemote():
    engine = webdriver.Remote(command_executor="http://localhost:4444/wd/hub", desired_capabilities=DesiredCapabilities.FIREFOX)
    return engine
    

'''
selenium engine deInit
'''
def deInitEngine(engine):
    engine.close()
    engine.quit()

4、第一个自动化测试脚本
TestHelloWorld.py

# !C:\Languages\Python\Python27\python.exe
# -*- coding: utf-8 -*-
'''
Created on 2016-10-22
@author: Hansen
HelloWorld sample for NeoSelenium
'''

from NeoSelenium import initEngine
from NeoSelenium import deInitEngine

#一个简单的查询测试
def neohope_search_test():
    try:
        #myEngine = initEngine('ie32')
        #myEngine = initEngine('ie64')
        #myEngine = initEngine('chrome')
        myEngine = initEngine('ff32')
        #myEngine = initEngine('ff64')

        base_url = "https://www.neohope.com"
        myEngine.get(base_url + "/")
        myEngine.find_element_by_name("s").clear()
        myEngine.find_element_by_name("s").send_keys("Metabase")
        myEngine.find_element_by_css_selector("button.search-submit").click()
	myEngine.implicitly_wait(1000)
	#print(myEngine.find_elements_by_xpath("//div[@id='content']/article"))
	queryResultLenght = len(myEngine.find_elements_by_xpath("//div[@id='content']/article"))
	#print(queryResultLenght)
	#应该是1但现在是10
        assert queryResultLenght==1
    finally:
        #deInitEngine(myEngine)
	print("test end")

#start here
neohope_search_test()

5、运行脚本

PS:
IE驱动抛出异常解决方案

"Unexpected error launching Internet Explorer. Protected Mode settings are not the same for all zones. Enable Protected Mode must be set to the same value (enabled or disabled) for all zones."

解决方法:

     
打开IE->Internet options->Security->Enable Protected Mode
这个框,在四个域下面要是一致的(要么都勾上,要么都不勾上)