def to_application(self): allure.epic('SystemSeting') allure.feature('Application') self.driver.swipe(30, 1475, 30, 671, 300) self.find_element_and_click(self._application_locator) self.logger.info('_application_locator点击成功') return ApplicationPage(self.driver)
def in_car_page(self): allure.epic('Body Control') allure.feature('in car page') self.find_element(self._switch_in_car_locator).click() self.logger.info('跳转到车内页面成功') self.find_element(self._main_driver_seat_setting).click() self.logger.info('进入主驾驶座椅设置页面成功') self.find_element(self._copilot_seat_setting).click() self.logger.info('进入副驾驶座椅设置成功') return self
# @Author : LOUIE from utils.operation_json import OperationJson as Opt_json from common.common_tools import CommonTools as cotool from common.http_requests import httprequest from common.config_log import log from stream_tools.config.constant import GLOBAL_VAR from utils import generator from utils.operation_yaml import OperationYAML import pytest import allure import time data = OperationYAML().rafactor_data("/taoli/reception.yaml") allure.feature("【桃李系统】入学接待流程") class TestRefund(): def setup(self): time.sleep(1) def setup_class(self): GLOBAL_VAR["title"] = str("python测试%s" % generator.random_ean8()) GLOBAL_VAR["phoneNumber"] = str(generator.random_phone_number()) GLOBAL_VAR["transNo"] = str(generator.timestamp()) def teardown_class(self): Opt_json("reception.json").write_to_res_json(GLOBAL_VAR) @pytest.mark.parametrize(
# -*- coding: utf-8 -*- import pytest from rest_framework.status import HTTP_200_OK, HTTP_302_FOUND, HTTP_404_NOT_FOUND import allure from directory_tests_shared import URLs from tests.smoke.cms_api_helpers import get_and_assert pytestmark = [allure.suite("Invest"), allure.feature("Invest")] @pytest.mark.dev @pytest.mark.parametrize( "url", [ URLs.INVEST_INDUSTRIES_AEROSPACE.absolute, URLs.INVEST_INDUSTRIES_AUTOMOTIVE.absolute, URLs.INVEST_INDUSTRIES_CREATIVE_INDUSTRIES.absolute, URLs.INVEST_INDUSTRIES_HEALTH_AND_LIFE_SCIENCES.absolute, URLs.INVEST_INDUSTRIES_TECHNOLOGY.absolute, ], ) def test_invest_pages_redirects(url, basic_auth): response = get_and_assert(url=url, status_code=HTTP_302_FOUND, auth=basic_auth, allow_redirects=False) location = response.headers["location"] error = f"Expected redirect to https://... URL but got {location}" assert location.startswith("https://"), error
# -*- coding: utf-8 -*- import pytest from rest_framework.status import HTTP_200_OK import allure from directory_tests_shared import URLs from tests.smoke.cms_api_helpers import get_and_assert pytestmark = [allure.suite("Contact us"), allure.feature("Contact us")] @pytest.mark.dev @pytest.mark.parametrize( "market", [ "1688com", "amazon-canada", "amazon-china", "amazon-france", "amazon-germany", "amazon-italy", "amazon-japan", "amazon-spain", "amazon-usa", "cdiscount", "ebay", "etsy", "flipkart", "jd-worldwide", "kaola", "newegg-inc",
from common.commonDate import CommonData from conftest import http import allure allure.feature("登录模块") class Test_login(): @allure.story("登录成功") def test_login_success(self): path = "/api/auth/login" data = {'username': CommonData.mobile, 'password': CommonData.password} resp = http.post(path, data) assert resp['code'] == 200 assert resp['msg'] == '操作成功' @allure.story("登录失败") def test_login_fail(self): path = "/api/auth/login" data = {'username': 123, 'password': CommonData.password} resp = http.post(path, data) assert resp['code'] == 301 assert resp['msg'] == '用户不存在'
# -*- coding: utf-8 -*- import pytest from rest_framework.status import HTTP_302_FOUND import allure from directory_tests_shared import URLs from tests.smoke.cms_api_helpers import get_and_assert pytestmark = [allure.suite("FAS redirects"), allure.feature("FAS redirects")] @allure.issue("CMS-1834", "Links to legacy industry pages redirect to wrong place") @allure.issue("ED-4152", "404s on old industry pages & contact-us page") @pytest.mark.parametrize( "old_url,to_new_endpoint", [ ( URLs.FAS_INDUSTRIES_HEALTH.absolute, URLs.FAS_INCOMING_REDIRECT.absolute_template.format( endpoint="industries/health"), ), ( URLs.FAS_INDUSTRIES_TECH.absolute, URLs.FAS_INCOMING_REDIRECT.absolute_template.format( endpoint="industries/tech"), ), ( URLs.FAS_INDUSTRIES_CREATIVE.absolute, URLs.FAS_INCOMING_REDIRECT.absolute_template.format( endpoint="industries/creative"),
# -*- coding: utf-8 -*- from random import choice from rest_framework.status import HTTP_200_OK import allure from directory_tests_shared import URLs from directory_tests_shared.constants import SECTORS from directory_tests_shared.utils import rare_word from tests.smoke.cms_api_helpers import get_and_assert pytestmark = [allure.suite("FAS"), allure.feature("FAS")] def test_landing_page_200(basic_auth): url = URLs.FAS_LANDING.absolute get_and_assert(url=url, status_code=HTTP_200_OK, auth=basic_auth) def test_supplier_list_200(basic_auth): url = URLs.FAS_SUPPLIERS.absolute get_and_assert(url=url, status_code=HTTP_200_OK, auth=basic_auth, allow_redirects=True) def test_search_supplier_200(basic_auth): sector = choice(SECTORS) url = URLs.FAS_SEARCH.absolute_template.format(query=rare_word(), industries=sector)
# -*- coding: utf-8 -*- import pytest from rest_framework.status import ( HTTP_200_OK, HTTP_403_FORBIDDEN, HTTP_404_NOT_FOUND, HTTP_405_METHOD_NOT_ALLOWED, ) import allure from directory_tests_shared import URLs from directory_tests_shared.clients import FORMS_API_CLIENT, BasicAuthenticator from directory_tests_shared.settings import BASICAUTH_PASS, BASICAUTH_USER from tests.smoke.cms_api_helpers import status_error pytestmark = [allure.suite("Forms-API"), allure.feature("Forms-API")] BASIC_AUTHENTICATOR = BasicAuthenticator(BASICAUTH_USER, BASICAUTH_PASS) @pytest.mark.forms def test_forms_submissions_endpoint_accepts_only_post(): response = FORMS_API_CLIENT.get( URLs.FORMS_API_SUBMISSION.absolute, authenticator=BASIC_AUTHENTICATOR ) assert response.status_code == HTTP_405_METHOD_NOT_ALLOWED, status_error( HTTP_405_METHOD_NOT_ALLOWED, response ) assert response.headers["Allow"] == "POST, OPTIONS"
# -*- coding: utf-8 -*- import pytest from rest_framework.status import HTTP_200_OK import allure from directory_tests_shared import URLs from tests.smoke.cms_api_helpers import get_and_assert pytestmark = [ allure.suite("Export Opportunities"), allure.feature("Export Opportunities"), ] @pytest.mark.parametrize( "url", [ URLs.EXOPPS_LANDING.absolute, URLs.EXOPPS_OPPORTUNITY.absolute_template.format(slug="furniture-498"), URLs.EXOPPS_SEARCH.absolute_template.format(term="food"), ], ) def test_exopps_pages(url, basic_auth): get_and_assert(url=url, status_code=HTTP_200_OK, auth=basic_auth)
from utils.operation_json import OperationJson as Opt_json from common.common_tools import CommonTools as cotool from common.http_requests import httprequest from common.config_log import log from stream_tools.config.constant import GLOBAL_VAR from utils import generator from utils.operation_yaml import OperationYAML from utils import tools import pytest import time import allure data = OperationYAML().rafactor_data("mainlink.yaml") allure.feature("【平台】全链路流程测试") class TestMainLink(): def setup_class(self): GLOBAL_VAR["title"] = str("python测试%s" % generator.random_ean8()) GLOBAL_VAR["phoneNumber"] = str(generator.random_phone_number()) GLOBAL_VAR["transNo"] = str(generator.timestamp()) def setup(self): time.sleep(1) pass def teardown_class(self): Opt_json("mainlink.json").write_to_res_json(GLOBAL_VAR)
# -*- encoding=utf8 -*- __author__ = "wzq" import pytest from airtest.core.api import * import allure import os auto_setup(__file__) from poco.drivers.android.uiautomation import AndroidUiautomationPoco poco = AndroidUiautomationPoco(use_airtest_input=True, screenshot_each_action=False) connect_device("Android://192.168.1.100:5555/5631511") allure.feature('开关wifi') current_path = os.getcwd() print(current_path) def test(): """ wifi开关功能测试 :return: """ keyevent('home') with allure.step('点击设置'): poco(text="设置").click() with allure.step('打开wlan设置'): poco(text="WLAN").click() with allure.step('打开wlan开关'): poco("android:id/checkbox").click() with allure.step('关闭wlan开关'): poco("android:id/checkbox").click() snapshot(filename=r'./test.png') with open('./test.png',mode='rb') as f: file=f.read() allure.attach(file,'wlan页面')
import allure import pytest from src.generate_data import queries_positive, queries_negative, name_companies suite_serach = allure.feature('Проверка основного поиска') # @pytest.mark.env("not_run") @suite_serach @allure.title('WS-d-001 Поиск товаров/услуг и автокомплит') @pytest.mark.parametrize('words', queries_positive) def test_search_autocomplit_rubrics(man, words): check_query = man.search_goods.search_goods_autocomplit_to_rubrics(words) assert check_query >= 1, 'Не работает автокоплит или нет товаров согласно запроса' @suite_serach @allure.title( 'WS-d-003 Поиск товаров/услуг по кнопке "лупа" с негативными запросами') @pytest.mark.parametrize('words', queries_negative) def test_search_click_to_button(man, words): check_query = man.search_goods.search_goods_click_to_button(words) assert check_query >= 1 @suite_serach @allure.title('WS-d-003 Поиск компаний по кнопке "лупа"') @pytest.mark.parametrize('names', name_companies) def test_search_companies(man, names): check = man.search_goods.search_goods_click_to_button(names)
# -*- coding: utf-8 -*- import pytest import requests from rest_framework.status import ( HTTP_200_OK, HTTP_301_MOVED_PERMANENTLY, HTTP_302_FOUND, ) import allure from directory_tests_shared import URLs from tests.smoke.cms_api_helpers import get_and_assert, status_error pytestmark = [ allure.suite("Letter links"), allure.feature("Letter links"), allure.description( "Links to legacy pages which were used in physical letters sent to our users " "should redirect to appropriate new pages"), ] @pytest.mark.stage @pytest.mark.parametrize("url", [URLs.FAB_CONFIRM_IDENTITY.absolute]) def test_302_redirects_for_anon_user(url, basic_auth): get_and_assert(url=url, allow_redirects=False, status_code=HTTP_302_FOUND, auth=basic_auth)
def pytest_generate_tests(metafunc): allure.feature(metafunc.module.__name__)(metafunc.function) allure.story(metafunc.function.__name__)(metafunc.function)
# -*- coding: utf-8 -*- import pytest from bs4 import BeautifulSoup from rest_framework.status import HTTP_200_OK import allure from directory_tests_shared import URLs from directory_tests_shared.settings import BASICAUTH_PASS, BASICAUTH_USER from tests.smoke.cms_api_helpers import get_and_assert pytestmark = [ allure.suite("sitemap.xml"), allure.feature("sitemap.xml"), allure.description( "A service which handles our Top Level Domain should expose a valid sitemap.xml" " which enables various Search Engines/Web Crawlers (like Google) to discover " "what pages are present and which change frequently. This allows them to crawl " "our site accordingly" ), ] @allure.step("Check if sitemap.xml is present") def get_urls_from_sitemap(sitemap_url: str, *, ignore_404: bool = False) -> list: result = [] try: response = get_and_assert( url=sitemap_url, status_code=HTTP_200_OK, auth=(BASICAUTH_USER, BASICAUTH_PASS), )
# @Author : LOUIE from utils.operation_json import OperationJson as Opt_json from common.common_tools import CommonTools as cotool from common.http_requests import httprequest from common.config_log import log from stream_tools.config.constant import GLOBAL_VAR from utils import generator from utils.operation_yaml import OperationYAML import pytest import allure import time data = OperationYAML().rafactor_data("/taoli/refund.yaml") allure.feature("【桃李系统】投诉退款流程") class TestRefund(): def setup_class(self): GLOBAL_VAR["title"] = str("python测试%s" % generator.random_ean8()) GLOBAL_VAR["phoneNumber"] = str(generator.random_phone_number()) GLOBAL_VAR["transNo"] = str(generator.timestamp()) def setup(self): time.sleep(1) def teardown_class(self): Opt_json("refund.json").write_to_res_json(GLOBAL_VAR) @pytest.mark.parametrize(
import pytest import allure import os allure.feature('登陆模块的一级标签') class TestLogin: #登录模块的测试类 #很多操作是有前置条件的,比如买东西必须先登录。 def setup_class(self): print('在这个类执行之前我先执行') @pytest.mark.parametrize('a,b',[(1,2),(3,4),(5,6)]) @allure.story('登陆模块第二个用例的二级标签') @allure.title('登录模块第二个case的标题') def test_case02(self,a,b): print('---hahah---') assert 1+a==b def teardown_class(self): print('测试类的环境清除') if __name__ == '__main__': pytest.main(['test_func.py','-s','--alluredir','../report/tmp']) #加上参数s就可以显示打印信息了 os.system('allure generate ../report/tmp -o ../report/report --clean')
# -*- coding: utf-8 -*- import pytest from requests import Response from rest_framework.status import HTTP_200_OK import allure from directory_tests_shared import URLs from tests.smoke.cms_api_helpers import get_and_assert, status_error pytestmark = [ allure.suite("Secure Cookie flag"), allure.feature("Secure Cookie flag"), allure.description( "The Secure flag should be set on all cookies that are used for transmitting " "sensitive data when accessing content over HTTPS. If cookies are used to " "transmit session"), ] @allure.step("Assert that Secure Cookie flag is set") def assert_secure_cookie_flag_is_set(response: Response): cookie_dict = {c.name: c.__dict__ for c in response.cookies} insecure_cookies = [c.name for c in response.cookies if not c.secure] error = (f"Not all cookies on {response.url} are set with 'Secure' flag: " f"{insecure_cookies} → {cookie_dict}") assert all(c.secure for c in response.cookies), error @allure.issue("TT-1614", "Cookies Not Set With Secure Flag") @pytest.mark.parametrize( "url",
all_data.append(i) for i in milky_way_query_data: all_data.append(i) for i in haichuan_query_data: all_data.append(i) for i in shishuo_query_data: all_data.append(i) for i in xiaoka_query_data: all_data.append(i) for i in client_query_data: all_data.append(i) # for i in mobile_class_data: # all_data.append(i) allure.feature("【平台】查询接口测试") class TestQuery(): def setup(self): time.sleep(1) def teardown_class(self): Opt_json("query.json").write_to_res_json(GLOBAL_VAR) @pytest.mark.parametrize("caseid, desc, precondition, parameterize, url, method, header, data, shared, check", all_data) def test_mainlink(self, caseid, desc, precondition, parameterize, url, method, header, data, shared, check): log.info("CaseId: <- {} ->".format(caseid)) log.info("Desc: {}".format(desc)) header = cotool().set_header(header) params = cotool().set_params(parameterize, data) res = httprequest(url, method, header, params)
def to_voice(self): allure.epic('SystemSeting') allure.feature('VoicePage') self.find_element(self._voice_locator).click() self.logger.info('_voice_locator点击成功') return VoicePage(self.driver)
import allure query_com = 'Аутсорсинговый контакт-центр БИС-Новосибирск' query_goods = 'Услуги Call-центра' numeral = 1 name_suite = allure.feature('Проверка карточки компании') @name_suite @allure.title('WS-d-015-1 Открытие карточки компании и наличие товаров в разделе "Предложения компании:"') def test_check_company_tabs(man): check_prods = man.check_company.check_company_card(query_com) assert check_prods == 4, 'Нет товаров в разделе "Предложения компании:"' # вызываю окно и проверяю его появления report_error = man.check_company.check_form_error() assert report_error == 'Сообщить об ошибке или пожаловаться' @name_suite @allure.title('WS-d-015-2 проверяем в прайсе компании клики кнопок "Запомненные", "К сравнению"') def test_check_buttons_in_price(man): get_nums = man.check_company.check_company_price(query_com) for num in get_nums: assert num >= numeral, 'Нет счётчика товаров или не работают функции' @name_suite @allure.title('WS-d-015-3 проверяем в прайсе результат выдачи услуг') def test_check_result_in_price(man): check_relevant = man.check_company.check_search_price(query_com, query_goods)
import allure pytestmark = [ allure.epic("My first epic"), allure.feature("Quick start feature") ] @allure.id(1) @allure.story("Simple story") @allure.title("test_allure_simple_test displayName") def test_allure_simple_test(): with allure.step("Simple step"): pass with allure.step("Simple parent step"): with allure.step("Simple child step"): pass simple_step_func("function parameter") @allure.step("Simple function with step decorator") def simple_step_func(): with allure.step("Simple step inside test function"): pass
def outside_the_car_page(self): allure.epic('Body Control') allure.feature('outside the car page') self.find_element(self._switch_outside_the_car).click() self.logger.info('跳转到车外页面成功') return self
# -*- coding: utf-8 -*- import pytest from rest_framework.status import HTTP_200_OK, HTTP_301_MOVED_PERMANENTLY import allure from directory_tests_shared import URLs from tests.smoke.cms_api_helpers import get_and_assert, status_error pytestmark = [allure.suite("SSO"), allure.feature("SSO")] @pytest.mark.session_auth @pytest.mark.parametrize( "url", [URLs.SSO_LANDING.absolute, URLs.SSO_LOGIN.absolute, URLs.SSO_SIGNUP.absolute], ) def test_access_sso_endpoints_as_logged_in_user_w_redirect_to_sud( logged_in_session, url, basic_auth ): response = logged_in_session.get(url, allow_redirects=True, auth=basic_auth) assert response.status_code == HTTP_200_OK, status_error(HTTP_200_OK, response) @pytest.mark.prod @pytest.mark.parametrize( "url", [ URLs.SSO_LOGOUT.absolute, URLs.SSO_PASSWORD_CHANGE.absolute, URLs.SSO_PASSWORD_SET.absolute, URLs.SSO_PASSWORD_RESET.absolute,
#!/usr/bin/env python # encoding: utf-8 import allure import pytest from pages import gettoken allure.feature('测试审批功能') class TestApprovalByPO: get_token_interface = gettoken.GetTokenAPI( 'TJUU19T_yG_83tJQlXU8P3Fg37VCV2eTo8e574RUivc') get_wrong_token_interface = gettoken.GetTokenAPI('222') @allure.story('输入正确的securetID获取到access token') def test_get_access_token(self): res = TestApprovalByPO.get_token_interface.get_token_res_by_subpath() assert 'access_token' in res.keys() @allure.story('通过request传入parameters的方式获取到access token') def test_get_access_token_by_parameters(self): res = TestApprovalByPO.get_token_interface.get_token_by_parameters() pytest.assume('access_token' in res.keys()) pytest.assume(res.get('errcode') == 0) @allure.story('通过request传入parameters的方式获取到access token') def test_get_access_token_by_parameters(self): res = TestApprovalByPO.get_token_interface.get_token_res_by_parameters( ) pytest.assume('access_token' in res.keys()) pytest.assume(res.get('errcode') == 0)
# -*- coding: utf-8 -*- import pytest from rest_framework.status import HTTP_200_OK import allure from directory_tests_shared import URLs from tests.smoke.cms_api_helpers import get_and_assert pytestmark = [ allure.suite("International site"), allure.feature("International site") ] @pytest.mark.dev @pytest.mark.parametrize( "url", [ URLs.INTERNATIONAL_REGIONS_MIDLANDS.absolute, URLs.INTERNATIONAL_REGIONS_NORTH_ENGLAND.absolute, URLs.INTERNATIONAL_REGIONS_NORTHERN_IRELAND.absolute, URLs.INTERNATIONAL_REGIONS_SOUTH_ENGLAND.absolute, URLs.INTERNATIONAL_REGIONS_WALES.absolute, ], ) def test_region_pages(url, basic_auth): get_and_assert(url=url, status_code=HTTP_200_OK, auth=basic_auth, allow_redirects=True)
@allure.epic() epic描述 敏捷里面的概念,定义史诗,往下是feature @allure.feature() 模块名称 功能点的描述,往下是story @allure.story() 用户故事 用户故事,往下是title @allure.title(用例标题) 用例的标题 重命名html报告名称 @allure.testcase() 测试用例链接地址 对应功能测试用例系统里面的case @allure.issue() 缺陷 对应缺陷管理系统里面的链接 @allure.description() 用例描述 测试用例的描述 @allure.step() 操作步骤 测试用例的步骤 @allure.severity() 用例等级 blocker,critical,normal,minor,trivial @allure.link() 链接 定义一个链接,在测试报告展现 @allure.attachment() 附件 报告添加附件 """ data = OperationYAML().rafactor_data("Template.yaml") allure.feature("流程名称") class TestTemplates(): # 测试类必须以Test开头 def setup(self): # 在每个方法运行之前执行 setup 中的操作,同样还有setup_class,setup_module pass def teardown_class( self): # 在每个类运行之前执行 teardown_class 中的操作,teardown,teardown_module # 将整个全局字典写入json文件 Opt_json("Template.json").write_to_res_json(GLOBAL_VAR) @pytest.mark.parametrize( "caseid, desc, precondition, parameterize, url, method, header, data, shared, check", data) def test_democase(self, caseid, desc, precondition, parameterize, url,
# -*- coding: utf-8 -*- import pytest from requests import Response from rest_framework.status import HTTP_200_OK import allure from directory_tests_shared import URLs from tests.smoke.cms_api_helpers import get_and_assert, status_error pytestmark = [ allure.suite("HttpOnly Cookie flag"), allure.feature("HttpOnly Cookie flag"), allure.description( "The HttpOnly flag should be set by including this attribute within " "the relevant Set-cookie directive. Alternatively, URL rewriting could be used," " as is detailed in the following example" ), ] USER_AGENT = {"user-agent": "automated smoke tests"} @allure.step("Assert that HttpOnly Cookie flag is set") def assert_httponly_cookie_flag_is_set(response: Response): without_httponly = { c.name: c.__dict__ for c in response.cookies if not c.has_nonstandard_attr("HttpOnly") } error = ( f"Following cookies on {response.url} are set without 'HttpOnly' flag: "
HTTP_404_NOT_FOUND, ) from retrying import retry import allure from directory_tests_shared import URLs from directory_tests_shared.clients import ( BASIC_AUTHENTICATOR, CMS_API_CLIENT, SSO_API_CLIENT, ) from directory_tests_shared.settings import DIRECTORY_API_HEALTH_CHECK_TOKEN as TOKEN from directory_tests_shared.utils import retriable_error from tests.smoke.cms_api_helpers import get_and_assert, status_error pytestmark = [allure.suite("Health checks"), allure.feature("Health checks")] @pytest.mark.sso_api @pytest.mark.parametrize( "url", [URLs.SSO_API_HEALTHCECK.absolute, URLs.SSO_API_HEALTHCHECK_PING.absolute]) def test_sso_api_health_check(url, basic_auth): """This endpoint still uses session auth""" params = {"token": TOKEN} get_and_assert(url=url, params=params, status_code=HTTP_200_OK, auth=basic_auth)