Created
November 20, 2016 17:20
-
-
Save Maxibond/c41a1241f55714d315fae9ec7de89056 to your computer and use it in GitHub Desktop.
Selenium testing work
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf-8 | |
from selenium.webdriver.common.keys import Keys | |
from time import sleep | |
def run(driver, goto): | |
goto(driver) | |
elem = driver.find_element_by_name('user') | |
elem.clear() | |
elem.send_keys('login') | |
elem = driver.find_element_by_name('passwd') | |
elem.clear() | |
elem.send_keys('passwd') | |
elem.submit() | |
sleep(1) | |
assert 'неверный пароль' in driver.page_source |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf-8 | |
from time import sleep | |
def run(driver, goto): | |
goto(driver) | |
# находим ссылку у первого текстового поста | |
elem = driver.find_element_by_xpath("//div[@data-context='listing'" | |
" and div[contains(@class, 'entry')]/div[contains(@class, 'selftext')]]" | |
"/div[contains(@class, 'entry')]/p[1]/a") | |
driver.get(elem.get_attribute('href')) | |
sleep(2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf-8 | |
from selenium.webdriver.common.keys import Keys | |
from time import sleep | |
def run(driver, goto): | |
goto(driver) | |
def search(item): | |
elem = driver.find_element_by_name('q') | |
elem.clear() | |
elem.send_keys(item) | |
elem.submit() | |
sleep(3) | |
results = driver.find_elements_by_class_name('search-result-subreddit') | |
return results | |
assert search('python') | |
assert not search('asdsadsadsadsadsadsadsad') | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from selenium import webdriver | |
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary | |
import manager | |
if __name__ == '__main__': | |
binary = FirefoxBinary(r'C:\Program Files (x86)\Mozilla Firefox\firefox.exe') | |
driver = webdriver.Firefox(firefox_binary=binary) | |
try: | |
manager.start(driver) | |
finally: | |
driver.quit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf-8 | |
import tests | |
def gotosite(driver): | |
driver.get("https://www.reddit.com/") | |
assert "reddit" in driver.title | |
def start(driver): | |
# run tests | |
tests.check_search.run(driver, gotosite) | |
tests.check_login.run(driver, gotosite) | |
tests.check_post.run(driver, gotosite) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment