Best Python code snippet using pytest-mozwebqa_python
settings.py
Source:settings.py
1# Scrapy settings for test_selenium project2#3# For simplicity, this file contains only settings considered important or4# commonly used. You can find more settings consulting the documentation:5#6# https://docs.scrapy.org/en/latest/topics/settings.html7# https://docs.scrapy.org/en/latest/topics/downloader-middleware.html8# https://docs.scrapy.org/en/latest/topics/spider-middleware.html9from pathlib import Path10BASE_DIR = Path(__file__).resolve().parent.parent11BOT_NAME = 'test_selenium'12SPIDER_MODULES = ['test_selenium.spiders']13NEWSPIDER_MODULE = 'test_selenium.spiders'14LOG_ENABLED = True15LOG_LEVEL = 'DEBUG'16# Crawl responsibly by identifying yourself (and your website) on the user-agent17USER_AGENT = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36'18# Obey robots.txt rules19ROBOTSTXT_OBEY = False20# Configure maximum concurrent requests performed by Scrapy (default: 16)21CONCURRENT_REQUESTS = 822# Configure a delay for requests for the same website (default: 0)23# See https://docs.scrapy.org/en/latest/topics/settings.html#download-delay24# See also autothrottle settings and docs25DOWNLOAD_DELAY = 1.526# The download delay setting will honor only one of:27#CONCURRENT_REQUESTS_PER_DOMAIN = 1628#CONCURRENT_REQUESTS_PER_IP = 1629# Disable cookies (enabled by default)30COOKIES_ENABLED = True31# Disable Telnet Console (enabled by default)32#TELNETCONSOLE_ENABLED = False33# Override the default request headers:34#DEFAULT_REQUEST_HEADERS = {35# 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',36# 'Accept-Language': 'en',37#}38# Enable or disable spider middlewares39# See https://docs.scrapy.org/en/latest/topics/spider-middleware.html40#SPIDER_MIDDLEWARES = {41# 'test_selenium.middlewares.TestSeleniumSpiderMiddleware': 543,42#}43# Enable or disable downloader middlewares44# See https://docs.scrapy.org/en/latest/topics/downloader-middleware.html45DOWNLOADER_MIDDLEWARES = {46 # 'test_selenium.middlewares.TestSeleniumDownloaderMiddleware': 543,47 'test_selenium.middlewares.SeleniumMiddleware': 800,48}49SELENIUM_DRIVER_NAME = 'chrome'50SELENIUM_DRIVER_EXECUTABLE_PATH = BASE_DIR / 'chromedriver'51SELENIUM_DRIVER_ARGUMENTS = ['start-maximized']52# Enable or disable extensions53# See https://docs.scrapy.org/en/latest/topics/extensions.html54#EXTENSIONS = {55# 'scrapy.extensions.telnet.TelnetConsole': None,56#}57# Configure item pipelines58# See https://docs.scrapy.org/en/latest/topics/item-pipeline.html59ITEM_PIPELINES = {60 'test_selenium.pipelines.TestSeleniumPipeline': 300,61}62# Enable and configure the AutoThrottle extension (disabled by default)63# See https://docs.scrapy.org/en/latest/topics/autothrottle.html64#AUTOTHROTTLE_ENABLED = True65# The initial download delay66#AUTOTHROTTLE_START_DELAY = 567# The maximum download delay to be set in case of high latencies68#AUTOTHROTTLE_MAX_DELAY = 6069# The average number of requests Scrapy should be sending in parallel to70# each remote server71#AUTOTHROTTLE_TARGET_CONCURRENCY = 1.072# Enable showing throttling stats for every response received:73#AUTOTHROTTLE_DEBUG = False74# Enable and configure HTTP caching (disabled by default)75# See https://docs.scrapy.org/en/latest/topics/downloader-middleware.html#httpcache-middleware-settings76#HTTPCACHE_ENABLED = True77#HTTPCACHE_EXPIRATION_SECS = 078#HTTPCACHE_DIR = 'httpcache'79#HTTPCACHE_IGNORE_HTTP_CODES = []...
selenium_1123.py
Source:selenium_1123.py
1# -*- coding: UTF-8 -*-2#!/usr/bin/env python3# @Time : 2017/11/23 15:144# @Author : SiYe5# @PROJECT_NAME : LemonClass6# @File : selenium_1123.py7# @Software: PyCharm8#-------------------------------------------------------------------------------9from selenium import webdriver10import time11from selenium.webdriver.common.action_chains import ActionChains12class ElementLocation:13 def __init__(self):14 self.browser = webdriver.Chrome()15 self.browser.get('http://www.lemfix.com/')16 self.browser.implicitly_wait(5)17 def loginWebsite(self):18 login_element=self.browser.find_element_by_link_text("ç»å½")19 login_element.click()20 time.sleep(1)21 self.browser.find_element_by_id("name").clear()22 self.browser.find_element_by_id("name").send_keys("zwnpepsi")23 self.browser.find_element_by_id("pass").clear()24 self.browser.find_element_by_id("pass").send_keys("zwn870706")25 self.browser.find_element_by_css_selector("input.span-primary").click()26 time.sleep(1)27 def readingArticle(self):28 self.browser.maximize_window() # æ大åçªå£29 self.browser.find_element_by_xpath("//*[@id='topic_list']/div[1]/div/a").click()30 time.sleep(1)31 self.browser.back()#åé32 time.sleep(1)33 self.browser.forward()#åè¿34 def replyArticle(self):35 time.sleep(1)36 reply_form=self.browser.find_element_by_css_selector("div.CodeMirror-scroll") #å®ä¹åå¤æ ä½ç½®37 ActionChains(self.browser).move_to_element(reply_form).click().perform() #ç¹å»åå¤æ ï¼æ¿æ´»åå¤æ è¾å
¥ç¶æ38 time.sleep(1)39 self.browser.find_element_by_xpath("//form[@id='reply_form']/div/div/div[2]/div/textarea").send_keys("è¿æ¯ä¸ç¯ä¸éçæç« ") #å¨åå¤æ ææ¬æ¡å
è¾å
¥æå40 time.sleep(1)41 self.browser.find_element_by_xpath("//*[@id='reply_form']/div/div/div[3]/input").click()42 def closeBrowser(self):43 time.sleep(1)44 self.browser.close()#å
³éå½åçªå£45 self.browser.quit()#å
³éæµè§å¨46test_selenium=ElementLocation()47test_selenium.loginWebsite()48test_selenium.readingArticle()49test_selenium.replyArticle()...
test_selenium.py
Source:test_selenium.py
...4# å¼åæ¶é´ : 2020-08-19 15:235# æ件å称 : test_selenium PY6# å¼åå·¥å
· : PyCharm7from selenium import webdriver8def test_selenium():9 driver = webdriver.Chrome()10 driver.get("https://www.baidu.com/")11if __name__ == "__main__":...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!