python + selenium 自动化测试框架
分享一个网站自动化测试框架
结构如下:
test_project
|--logs
|---pages
|---register_page.py
| |---base_page.py
|---test_case
|---web_test_case
|---test_register.py
| |---base.py
|---utilities
|---conn_db.py
|---conn_redis.py
|---operation.py
|---settings.py
|---settings_local.py
|---requirements.txt
一、requirements.txt
这个文件里面是需要安装的包,包名+版本号
nose==1.3.7 redis==2.10.5 selenium==3.4.3 PyMySQL==0.7.11 requests==2.18.1
在cmd 中直接运行 pip install -r requirements.txt ,自动安装所有需要的包
二、settings.py
项目配置文件,用于记录测试项目域名、全局等待时间、数据库地址、redis地址、log的存放目录等
# env config ENV = 'test' # test url test config WEB_TEST_BASE_URL = "http://www.abc.com" # global waiting time config WAIT_TIME = 10 # redis config REDIS_HOST = '' REDIS_PORT = '' # drive config GECKODRIVER_PATH = 'geckodriver' # mysql config DB_HOST = '' DB_PORT = '' DB_USER = '' DB_PASSWORD = '' # local debugging config import os BASE_DIR = os.path.dirname(os.path.abspath(__file__)) SNAPSHOT_DIRECTORY = os.path.join(BASE_DIR, 'logs') SETTING_LOCAL_DIR = os.path.join(BASE_DIR, "settings_local.py") if os.path.exists(SETTING_LOCAL_DIR): execfile(SETTING_LOCAL_DIR)
三、base,py
test_case目录下所有的case需要继承BaseSeleniumTestCase()这个类,此处需要说明一下,通过设置settings中ENV的值修改启动的浏览器,当ENV='dev'的时候,启动的是Firefox,否则启动PhantomJS。
import logging from unittest import TestCase from selenium import webdriver import settings logger = logging.getLogger(__name__) class BaseSeleniumTestCase(TestCase): def get_web_driver(self): driver = webdriver.Firefox(executable_path=settings.GECKODRIVER_PATH) if settings.ENV == "dev" else webdriver.PhantomJS() driver.maximize_window() return driver def setUp(self): self.selenium = self.get_web_driver() def tearDown(self): self.selenium.quit()
四、base_page.py
页面基类,主要是定位、判断元素等,所有pages目录下的各个页面的page文件需要继承BasePage()类。
fail_on_screenshot() 修饰器,当定位元素或者判断元素的方法报出 TimeoutException、NoSuchElementException、InvalidElementStateException 错误时,对当时的页面进行截图,并且保存在项目logs目录中,名称为当前时间。
# coding=UTF-8 import logging,os,settings from datetime import datetime from selenium.common.exceptions import NoSuchElementException, TimeoutException, InvalidElementStateException from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as expected from selenium.webdriver.support.wait import WebDriverWait from settings import WAIT_TIME logger = logging.getLogger(__name__) def fail_on_screenshot(function): def get_snapshot_directory(): if not os.path.exists(settings.SNAPSHOT_DIRECTORY): os.mkdir(settings.SNAPSHOT_DIRECTORY) return settings.SNAPSHOT_DIRECTORY def get_current_time_str(): return datetime.strftime(datetime.now(), "%Y%m%d%H%M%S%f") def wrapper(*args, **kwargs): instance, selector = args[0], args[1] try: return function(*args, **kwargs) except (TimeoutException, NoSuchElementException, InvalidElementStateException) as ex: logger.error("Could not find the selector: [{}].".format(selector)) filename = "{}.png".format(get_current_time_str()) screenshot_path = os.path.join(get_snapshot_directory(), filename) logger.debug(instance.selenium.page_source) instance.selenium.save_screenshot(screenshot_path) raise ex return wrapper class BasePage(object): url = "" base_url = settings.WEB_TEST_BASE_URL def __init__(self, selenium, url_params=None): if not url_params: url_params = [] self.selenium = selenium self.url_params = url_params self.go_to() def go_to(self): logger.debug("Goto page: [{}]".format(self.get_page_url())) return self._selenium_get_url(self.get_page_url()) def refresh(self): self.selenium.refresh() def navigate_back(self): self.selenium.back() def _selenium_get_url(self, url): try: self.selenium.get('about:blank') self.selenium.get(str(url)) except Exception as ex: logger.error("Can not open the url:[{}]".format(url)) raise ex return self def get_page_url(self): if not self.url: raise RuntimeError("no url been set") return self._get_url(self.url) def _get_url(self, url): format_url = url.format(*self.url_params) return "{0}{1}".format(self.base_url, format_url) def get_current_page_url(self): return self.selenium.current_url def get_page_title(self): return self.selenium.title def get_cookie_value(self): return self.selenium.get_cookie('client_identity')['value'] # --------------------------------------------------------------------------------------------------------------- '''判断某个元素是否被添加到了dom里并且可见,可见代表元素可显示且宽和高都大于0''' @fail_on_screenshot def find_element_by_css(self, selector, wait_time=WAIT_TIME): return WebDriverWait(self.selenium, wait_time).until( expected.visibility_of_element_located((By.CSS_SELECTOR, selector))) @fail_on_screenshot def find_element_by_link_text(self, selector, wait_time=WAIT_TIME): return WebDriverWait(self.selenium, wait_time).until( expected.visibility_of_element_located((By.LINK_TEXT, selector))) @fail_on_screenshot def find_element_by_partial_link_text(self, selector, wait_time=WAIT_TIME): return WebDriverWait(self.selenium, wait_time).until( expected.visibility_of_element_located((By.PARTIAL_LINK_TEXT, selector))) @fail_on_screenshot def find_element_by_id(self, selector, wait_time=WAIT_TIME): return WebDriverWait(self.selenium, wait_time).until( expected.visibility_of_element_located((By.ID, selector))) @fail_on_screenshot def find_element_by_xpath(self, selector, wait_time=WAIT_TIME): return WebDriverWait(self.selenium, wait_time).until( expected.visibility_of_element_located((By.XPATH, selector))) @fail_on_screenshot def find_element_by_name(self, selector, wait_time=WAIT_TIME): return WebDriverWait(self.selenium, wait_time).until( expected.visibility_of_element_located((By.NAME, selector))) @fail_on_screenshot def find_element_by_class_name(self, selector, wait_time=WAIT_TIME): return WebDriverWait(self.selenium, wait_time).until( expected.visibility_of_element_located((By.CLASS_NAME, selector))) @fail_on_screenshot def find_element_by_tag_name(self, selector, wait_time=WAIT_TIME): return WebDriverWait(self.selenium, wait_time).until( expected.visibility_of_element_located((By.TAG_NAME, selector))) # ---------------------------------------------------------------------------------------------------------------- '''判断是否至少有1个元素存在于dom树中,如果定位到就返回列表''' @fail_on_screenshot def find_elements_by_css(self, selector, wait_time=WAIT_TIME): return WebDriverWait(self.selenium, wait_time).until( expected.presence_of_all_elements_located((By.CSS_SELECTOR, selector))) @fail_on_screenshot def find_elements_by_class_name(self, selector, wait_time=WAIT_TIME): return WebDriverWait(self.selenium, wait_time).until( expected.presence_of_all_elements_located((By.CLASS_NAME, selector))) @fail_on_screenshot def find_elements_by_link_text(self, selector, wait_time=WAIT_TIME): return WebDriverWait(self.selenium, wait_time).until( expected.presence_of_all_elements_located((By.LINK_TEXT, selector))) @fail_on_screenshot def find_elements_by_xpath(self, selector, wait_time=WAIT_TIME): return WebDriverWait(self.selenium, wait_time).until( expected.presence_of_all_elements_located((By.XPATH, selector))) # ------------------------------------------------------------------------------------------------------------- '''判断某个元素在是否存在于dom或不可见,如果可见返回False,不可见返回这个元素''' @fail_on_screenshot def invisible_element_by_id(self, selector, wait_time=WAIT_TIME): return WebDriverWait(self.selenium, wait_time).until( expected.invisibility_of_element_located((By.ID, selector))) @fail_on_screenshot def invisible_element_by_xpath(self, selector, wait_time=WAIT_TIME): return WebDriverWait(self.selenium, wait_time).until( expected.invisibility_of_element_located((By.XPATH, selector))) @fail_on_screenshot def invisible_element_by_css(self, selector, wait_time=WAIT_TIME): return WebDriverWait(self.selenium, wait_time).until( expected.invisibility_of_element_located((By.CSS_SELECTOR, selector))) @fail_on_screenshot def invisible_element_by_link_text(self, selector, wait_time=WAIT_TIME): return WebDriverWait(self.selenium, wait_time).until( expected.invisibility_of_element_located((By.LINK_TEXT, selector))) @fail_on_screenshot def invisible_element_by_name(self, selector, wait_time=WAIT_TIME): return WebDriverWait(self.selenium, wait_time).until( expected.invisibility_of_element_located((By.NAME, selector))) @fail_on_screenshot def invisible_element_by_class_name(self, selector, wait_time=WAIT_TIME): return WebDriverWait(self.selenium, wait_time).until( expected.invisibility_of_element_located((By.CLASS_NAME, selector))) @fail_on_screenshot def invisible_element_by_tag_name(self, selector, wait_time=WAIT_TIME): return WebDriverWait(self.selenium, wait_time).until( expected.invisibility_of_element_located((By.TAG_NAME, selector))) @fail_on_screenshot def invisible_element_by_partial_link_text(self, selector, wait_time=WAIT_TIME): return WebDriverWait(self.selenium, wait_time).until( expected.invisibility_of_element_located((By.PARTIAL_LINK_TEXT, selector))) # ----------------------------------------------------------------------------------------------------------------- '''判断指定的元素中是否包含了预期的字符串,返回布尔值''' @fail_on_screenshot def text_to_be_present_in_element_by_id(self, selector, wait_time=WAIT_TIME,text=None): return WebDriverWait(self.selenium, wait_time).until( expected.text_to_be_present_in_element((By.ID, selector),text)) @fail_on_screenshot def text_to_be_present_in_element_by_name(self, selector, wait_time=WAIT_TIME,text=None): return WebDriverWait(self.selenium, wait_time).until( expected.text_to_be_present_in_element((By.NAME, selector),text)) @fail_on_screenshot def text_to_be_present_in_element_by_class_name(self, selector, wait_time=WAIT_TIME,text=None): return WebDriverWait(self.selenium, wait_time).until( expected.text_to_be_present_in_element((By.CLASS_NAME, selector),text)) @fail_on_screenshot def text_to_be_present_in_element_by_xpath(self, selector, wait_time=WAIT_TIME,text=None): return WebDriverWait(self.selenium, wait_time).until( expected.text_to_be_present_in_element((By.XPATH, selector),text)) @fail_on_screenshot def text_to_be_present_in_element_by_tag_name(self, selector, wait_time=WAIT_TIME,text=None): return WebDriverWait(self.selenium, wait_time).until( expected.text_to_be_present_in_element((By.TAG_NAME, selector),text)) @fail_on_screenshot def text_to_be_present_in_element_by_css(self, selector, wait_time=WAIT_TIME,text=None): return WebDriverWait(self.selenium, wait_time).until( expected.text_to_be_present_in_element((By.CSS_SELECTOR, selector),text)) # ----------------------------------------------------------------------------------------------------------------- '''判断指定元素的属性值中是否包含了预期的字符串,返回布尔值''' @fail_on_screenshot def text_to_be_present_in_element_value_by_css(self, selector, wait_time=WAIT_TIME,text=None): return WebDriverWait(self.selenium, wait_time).until( expected.text_to_be_present_in_element_value((By.CSS_SELECTOR, selector),text)) @fail_on_screenshot def text_to_be_present_in_element_value_by_id(self, selector, wait_time=WAIT_TIME,text=None): return WebDriverWait(self.selenium, wait_time).until( expected.text_to_be_present_in_element_value((By.ID, selector),text)) @fail_on_screenshot def text_to_be_present_in_element_value_by_name(self, selector, wait_time=WAIT_TIME,text=None): return WebDriverWait(self.selenium, wait_time).until( expected.text_to_be_present_in_element_value((By.NAME, selector),text)) @fail_on_screenshot def text_to_be_present_in_element_value_by_css_name(self, selector, wait_time=WAIT_TIME,text=None): return WebDriverWait(self.selenium, wait_time).until( expected.text_to_be_present_in_element_value((By.CLASS_NAME, selector),text)) @fail_on_screenshot def text_to_be_present_in_element_value_by_xpath(self, selector, wait_time=WAIT_TIME,text=None): return WebDriverWait(self.selenium, wait_time).until( expected.text_to_be_present_in_element_value((By.XPATH, selector),text)) @fail_on_screenshot def text_to_be_present_in_element_value_by_tag_name(self, selector, wait_time=WAIT_TIME,text=None): return WebDriverWait(self.selenium, wait_time).until( expected.text_to_be_present_in_element_value((By.TAG_NAME, selector),text)) # ----------------------------------------------------------------------------------------------------------------- '''判断title,返回布尔值''' @fail_on_screenshot def page_title_is(self, title, wait_time=WAIT_TIME): return WebDriverWait(self.selenium, wait_time).until(expected.title_is(title)) @fail_on_screenshot def page_title_contains(self, title, wait_time=WAIT_TIME): return WebDriverWait(self.selenium, wait_time).until(expected.title_contains(title)) # ----------------------------------------------------------------------------------------------------------------- '''判断某个元素中是否可见并且是enable的,代表可点击''' @fail_on_screenshot def element_to_be_click_able_by_id(self, selector, wait_time=WAIT_TIME): return WebDriverWait(self.selenium, wait_time).until( expected.element_to_be_clickable((By.ID, selector))) @fail_on_screenshot def element_to_be_click_able_by_name(self, selector, wait_time=WAIT_TIME): return WebDriverWait(self.selenium, wait_time).until( expected.element_to_be_clickable((By.NAME, selector))) @fail_on_screenshot def element_to_be_click_able_by_class_name(self, selector, wait_time=WAIT_TIME): return WebDriverWait(self.selenium, wait_time).until( expected.element_to_be_clickable((By.CLASS_NAME, selector))) @fail_on_screenshot def element_to_be_click_able_by_css(self, selector, wait_time=WAIT_TIME): return WebDriverWait(self.selenium, wait_time).until( expected.element_to_be_clickable((By.CSS_SELECTOR, selector))) @fail_on_screenshot def element_to_be_click_able_by_tag_name(self, selector, wait_time=WAIT_TIME): return WebDriverWait(self.selenium, wait_time).until( expected.element_to_be_clickable((By.TAG_NAME, selector))) @fail_on_screenshot def element_to_be_click_able_by_xpath(self, selector, wait_time=WAIT_TIME): return WebDriverWait(self.selenium, wait_time).until( expected.element_to_be_clickable((By.XPATH, selector))) @fail_on_screenshot def element_to_be_click_able_by_link_text(self, selector, wait_time=WAIT_TIME): return WebDriverWait(self.selenium, wait_time).until( expected.element_to_be_clickable((By.LINK_TEXT, selector))) # ----------------------------------------------------------------------------------------------------------------- '''判断元素是否可见,如果可见就返回这个元素,不可见返回False''' @fail_on_screenshot def visibility_of_element_by_id(self, selector, wait_time=WAIT_TIME): return WebDriverWait(self.selenium, wait_time).until( expected.visibility_of_element_located((By.ID, selector))) @fail_on_screenshot def visibility_of_element_by_name(self, selector, wait_time=WAIT_TIME): return WebDriverWait(self.selenium, wait_time).until( expected.visibility_of_element_located((By.NAME, selector))) @fail_on_screenshot def visibility_of_element_by_class_name(self, selector, wait_time=WAIT_TIME): return WebDriverWait(self.selenium, wait_time).until( expected.visibility_of_element_located((By.CLASS_NAME, selector))) @fail_on_screenshot def visibility_of_element_by_css(self, selector, wait_time=WAIT_TIME): return WebDriverWait(self.selenium, wait_time).until( expected.visibility_of_element_located((By.CSS_SELECTOR, selector))) @fail_on_screenshot def visibility_of_element_by_xpath(self, selector, wait_time=WAIT_TIME): return WebDriverWait(self.selenium, wait_time).until( expected.visibility_of_element_located((By.XPATH, selector))) @fail_on_screenshot def visibility_of_element_by_tag_name(self, selector, wait_time=WAIT_TIME): return WebDriverWait(self.selenium, wait_time).until( expected.visibility_of_element_located((By.TAG_NAME, selector))) def get_cookie_by_name(self, name): cookie = self.selenium.get_cookie(name) return cookie['value'] def get_session_id(self): return self.get_cookie_by_name("TSID")
五、utilities目录下主要存放数据库、redis等其他相关的操作
conn_db.py
连接数据库
import pymysql.cursors,settings def execute(sql, params=None, db='', is_fetchone=True): # Connect to the database connection = pymysql.connect(host=settings.DB_HOST, port=settings.DB_PORT, user=settings.DB_USER, password=settings.DB_PASSWORD, db=db, autocommit=True, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) try: with connection.cursor() as cursor: cursor.execute(sql, params) if is_fetchone: return cursor.fetchone() else: return cursor.fetchall() finally: connection.close()
conn_redis.py
连接redis(在redis中通过session获取图形验证码、清除缓存等)
import redis, settings def redis_connect(host=settings.CACHED_REDIS_HOST, port=settings.CACHED_REDIS_PORT): # Connect to the redis redis_client = redis.StrictRedis(host=host, port=port) return redis_client
下面是对注册功能的自动化,供参考:
在pages下创建register_page.py,封装注册页面中所需要的元素,内容如下:
# coding=UTF-8 from pages.base_page import BasePage from utilities import operation class RegisterPage(BasePage): url = '/register' def input_new_mobile(self,mobile): # 输入新注册手机号 element = self.find_element_by_id('phonenumber') element.clear() element.send_keys(mobile) return self def click_send_sms_captcha_bt(self): # 点击获取短信验证码 if self.element_to_be_click_able_by_id('get_code_btn'): self.find_element_by_id('get_code_btn').click() return self def judgement_sms_captcha_frame(self): # 校验发送验证码成功后弹框 self.visibility_of_element_by_css('.except-live-pop') return self def click_send_sms_captcha_affirm(self): # 点击发送短信验证码弹框上的确定按钮 self.find_element_by_css('.except-live-pop-btn').click() return self def input_sms_captcha(self,mobile): # 输入短信验证码 sms_captcha = operation.get_sms_captcha(mobile) element = self.find_element_by_id('r_valiedatecode') element.clear() element.send_keys(sms_captcha) return self def input_new_password(self,password): # 输入注册时密码 element = self.find_element_by_id('r_pwd') element.clear() element.send_keys(password) return self def click_submit_register(self): # 点击注册按钮 if self.element_to_be_click_able_by_id('btn_reg'): self.find_element_by_id('btn_reg').click() return self def judgement_input_nickname_frame(self): # 校验弹出输入用户昵称框 self.visibility_of_element_by_css('.c-name') return self def input_nickname(self,nickname): # 输入用户昵称 element = self.find_element_by_id('c_name_ipt') element.clear() element.send_keys(nickname) return self def click_nickname_bt(self): # 点击输入昵称框确定按钮 if self.element_to_be_click_able_by_css('.c-n-btn'): self.find_element_by_css('.c-n-btn').click() return self def register(self,mobile,password,nickname): # 注册流程 self.input_new_mobile(mobile).click_send_sms_captcha_bt() if self.judgement_sms_captcha_frame(): self.click_send_sms_captcha_affirm() self.input_sms_captcha(mobile) self.input_new_password(password).click_submit_register() if self.judgement_input_nickname_frame(): self.input_nickname(nickname).click_nickname_bt() return self
index_page.py
封装首页所需要的元素,主要是进行注册成功后用户昵称的校验
# coding=UTF-8 from page.base_page import BasePage class IndexPage(BasePage): url = '/index' def get_user_name(self): # 获取用户昵称 name = self.find_element_by_css('.yk-name').text return name
operation.py文件内容:
在数据库中获取短信验证码和删除新注册用户的sql
# -*- coding:utf-8 -*- import db def get_sms_captcha(mobile): # 获取短信验证码 sms_captcha = db.execute('select code from send_sms_code where mobile=%s order by id desc',params=(mobile)) return sms_captcha['code'] def delete_user(mobile): # 删除用户 db.execute('delete from user where mobile=%s',params=(mobile))
在test_case下新建test_register.py
下面是一个简单的测试注册成功的测试用例
# -*- coding:utf-8 -*- from pages.register_page import RegisterPage from pages.index_page import IndexPage from test_case.base import BaseSeleniumTestCase from utilities import operation import settings,time class TestRegister(BaseSeleniumTestCase): mobile = ' password = '123abc' nickname = 'autotester' def test_register_success(self): # 校验注册流程及注册成功后自动跳转到首页 after_register_url = RegisterPage(self.selenium).register(self.mobile, self.password,self.nickname).get_current_page_url() time.sleep(1.5) self.assertEqual(after_register_url, settings.WEB_TEST_BASE_URL + '/index') # 校验注册成功后页面title after_register_title = RegisterPage(self.selenium).get_page_title() self.assertEqual(after_register_title,u'Test-Title') # 校验注册成功后首页用户昵称是否与填写的一致 nickname = IndexPage(self.selenium).get_user_name() self.assertEqual(nickname,u'autotest...') def tearDown(self): super(TestRegister,self).tearDown() operation.delete_user(self.mobile)
用例执行结束后,通过teardown()方法将该用户在数据库中删除,下次执行的时候避免提示该手机号已注册。
python + selenium 自动化测试框架的更多相关文章
- 从零开始到设计Python+Selenium自动化测试框架-如何开始
如何开始学习web ui自动化测试?如何选择一门脚本语言?选择什么自动化测试工具? 本人已经做测试快5年,很惭愧,感觉积累不够,很多测试都不会,三年多功能测试,最近两年才开始接触和学习自动化测试.打算 ...
- Python selenium自动化测试框架入门实战--登录测试案例
本文为Python自动化测试框架基础入门篇,主要帮助会写基本selenium测试代码又没有规划的同仁.本文应用到POM模型.selenium.unittest框架.configparser配置文件.s ...
- 《一头扎进》系列之Python+Selenium自动化测试框架实战篇6 - 价值好几K的框架,呦!这个框架还真牛叉哦!!!
1. 简介 本文开始介绍如何通过unittest来管理和执行测试用例,这一篇主要是介绍unittest下addTest()方法来加载测试用例到测试套件中去.用addTest()方法来加载我们测试用例到 ...
- python+selenium 自动化测试框架-学习记录
本人小白一枚,想着把学习时的东西以博客的方式记录下来,文章中有不正确的地方请大佬多多指点!!共同学习 前期准备 安装python3.selenium.下载对应版本的webdriver:安装所需的第三 ...
- Eclipse+Python+Selenium自动化测试框架搭建
1.下载Eclipse:http://www.eclipse.org/downloads/ 2.下载JDK:http://www.oracle.com/technetwork/java/javaee/ ...
- 《Selenium自动化测试实战:基于Python》Selenium自动化测试框架入门
第1章 Selenium自动化测试框架入门 1.1 Selenium自动化测试框架概述 说到目前流行的自动化测试工具,相信只要做过软件测试相关工作,就一定听说过Selenium. 图1-1是某企业 ...
- Jenkins持续集成项目搭建与实践——基于Python Selenium自动化测试(自由风格)
Jenkins简介 Jenkins是Java编写的非常流行的持续集成(CI)服务,起源于Hudson项目.所以Jenkins和Hudson功能相似. Jenkins支持各种版本的控制工具,如CVS.S ...
- Selenium自动化测试框架入门整理
关注嘉为科技,获取运维新知 本文主要针对Selenium自动化测试框架入门整理,只涉及总体功能及框架要点介绍说明,以及使用前提技术基础要求整理说明.作为开发人员.测试人员入门参考. 本文参考:Se ...
- PO模式在selenium自动化测试框架有什么好处
PO模式是在UI自动化测试过程当中使用非常频繁的一种设计模式,使用这种模式后,可以有效的提升代码的复用能力,并且让自动化测试代码维护起来更加方便. PO模式的全称叫page object model( ...
随机推荐
- Eclipse rap 富客户端开发总结(2):rap项目目前的进度和存在的问题
1. Eclipse rap项目目前的进度 目前rap 的最新版本是 rap 1.5M4,最稳定版本是 rap 1.4.1,我们项目目前使用的版本是rap 1.4.1,Rap目前已经支持的部分是 sw ...
- Thinkphp3.2结合phpqrcode生成二维码(含Logo的二维码),附案例
首先,下载phpqrcode,将其解压到项目ThinkPHP\Library\Vendor目录下.Index_index.html(模板可自行配置) <form action="{:U ...
- JavaSE(十)之Map总结
上一篇是总结了Collection接口的各种实现类,这一篇我将分享的是Map的总结,希望大家点评! 一.Map接口 1.1.为什么Collection不能满足集合的所有功能? Collection接口 ...
- Java Map对象的遍历
一般情况下Map的实现类中用的最多的是 HashMap . Map的遍历也就是迭代 1. 在for-each循环中使用entries来遍历 (既要取键,又要取值) Map<String, St ...
- 使用Gateway-Worker实现多人分组实时聊天 结合第三方tp
一.基础知识1.Workerman是一款纯PHP开发的开源高性能的PHP socket 服务器框架.被广泛的用于手机app.移动通讯等领域的开发. 支持TCP长连接,支持Websocket.HTTP等 ...
- oracle pl/sql 简介
一.pl/sql 是什么pl/sql(procedural language/sql)是oracle在标准的sql语言上的扩展.pl/sql不仅允许嵌入sql语言,还可以定义变量和常量,允许使用条件语 ...
- Java 编程思想 Chapter_14 类型信息
本章内容绕不开一个名词:RTTI(Run-time Type Identification) 运行时期的类型识别 知乎上有人推断作者是从C++中引入这个概念的,反正也无所谓,理解并能串联本章知识才是最 ...
- java 反射 类装载器
前言: java语言允许通过程序化的方式间接对Class进行操作,Class文件由类装载器装载后,在jvm中将形成一份描述Class结构的元信息对象,通过该元信息对象可以获知Class的结构信息,如构 ...
- (一) .net core 2.0 初体验
1..net core 2.0环境 .net core 下载地址:https://www.microsoft.com/net/core#windowscmd 问题一:提示[Failed to load ...
- hdu4678 Mine 2013 Multi-University Training Contest 8 博弈题
Mine Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Submi ...