-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_github_search.py
More file actions
90 lines (73 loc) · 3.42 KB
/
test_github_search.py
File metadata and controls
90 lines (73 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import pytest
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
def get_webdriver(browser, browser_version, platform, os_version, resolution):
USERNAME = "anthonyrozon1"
PASSWORD = "pyx1xfRY4qqkwpsEqSFM"
if browser.lower() == 'chrome':
desired_capabilities = DesiredCapabilities.CHROME
desired_capabilities['os'] = platform
desired_capabilities['os_version'] = os_version
desired_capabilities['browser_version'] = browser_version
desired_capabilities['resolution'] = resolution
return webdriver.Remote(command_executor='http://%s:%s@hub.browserstack.com:80/wd/hub' % (USERNAME, PASSWORD),
desired_capabilities=desired_capabilities)
def test_github_user_search(browser, browserstack_flag, browser_version, platform, os_version, resolution):
driver = get_webdriver(browser, browser_version, platform, os_version, resolution)
pass_counter = 0
checks = 0
github_user_name = "rozon"
driver.get('https://github.com/')
driver.maximize_window()
# Check for page title
with pytest.allure.step('Check for page title'):
if "GitHub" in driver.title:
pass_counter += 1
checks += 1
# Check if github performed a search for given username
with pytest.allure.step('Check if github performed a search for given username'):
input_github_search = driver.find_element_by_xpath(".//input[contains(@placeholder, 'Search GitHub')]")
input_github_search.send_keys(github_user_name)
input_github_search.submit()
if github_user_name in driver.title:
pass_counter += 1
checks += 1
# Check if github returns any user
with pytest.allure.step('Check if github returns any user'):
label_users_search_result = driver.find_element_by_xpath(".//a[contains(@class, 'UnderlineNav-item') and text()='Users']/span")
github_user_results_count = int(label_users_search_result.text)
if github_user_results_count > 0:
pass_counter += 1
checks += 1
# Check if github load users results
with pytest.allure.step('Check if github load users results'):
try:
label_users_search_result.click()
pass_counter += 1
except Exception as e:
print(e)
checks += 1
# Check if github results returns same amount of users
with pytest.allure.step('Check if github results returns same amount of users'):
driver.implicitly_wait(10)
label_users_search_count = driver.find_element_by_xpath(".//h3[contains(text(), 'user')]").text[0:2]
label_int = int(label_users_search_count)
if github_user_results_count == label_int:
pass_counter += 1
checks += 1
# Check if github user url appears on results table
with pytest.allure.step('Check if github user url appears on results table'):
label_user_profile = driver.find_element_by_xpath(".//em[text()='" + github_user_name + "']")
try:
label_user_profile.click()
pass_counter += 1
except Exception as e:
print(e)
checks += 1
# Check if github profile is shown on browser
with pytest.allure.step('Check if github profile is shown on browser'):
if github_user_name in driver.title:
pass_counter += 1
checks += 1
driver.quit()
assert pass_counter == checks