Skip to content

Commit 8f6eb70

Browse files
authored
Merge pull request #139 from seleniumbase/traffic-generation
Adding methods for testing analytics software
2 parents fa85664 + 4c9a17d commit 8f6eb70

File tree

5 files changed

+52
-2
lines changed

5 files changed

+52
-2
lines changed

help_docs/method_summary.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ self.pick_select_option_by_index(dropdown_selector, option,
125125
self.pick_select_option_by_value(dropdown_selector, option,
126126
dropdown_by=By.CSS_SELECTOR, timeout=settings.SMALL_TIMEOUT)
127127

128+
self.generate_referral(start_page, destination_page)
129+
130+
self.generate_traffic(start_page, destination_page, loops=1)
131+
128132
########
129133

130134
self.wait_for_element_present(selector, by=By.CSS_SELECTOR,

seleniumbase/fixtures/base_case.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,36 @@ def pick_select_option_by_value(self, dropdown_selector, option,
872872
dropdown_by=dropdown_by, option_by="value",
873873
timeout=timeout)
874874

875+
def generate_referral(self, start_page, destination_page):
876+
""" This method opens the start_page, creates a referral link there,
877+
and clicks on that link, which goes to the destination_page.
878+
(This generates real traffic for testing analytics software.) """
879+
if not page_utils.is_valid_url(destination_page):
880+
raise Exception(
881+
"Exception: destination_page [%s] is not a valid URL!"
882+
% destination_page)
883+
if start_page:
884+
if not page_utils.is_valid_url(start_page):
885+
raise Exception(
886+
"Exception: start_page [%s] is not a valid URL! "
887+
"(Use an empty string or None to start from current page.)"
888+
% start_page)
889+
self.open(start_page)
890+
time.sleep(0.03)
891+
referral_link = ('''<a class='analytics referral test' href='%s'>'''
892+
'''Generate Free Referral!</a>''' % destination_page)
893+
self.execute_script(
894+
'''document.body.innerHTML = \"%s\"''' % referral_link)
895+
time.sleep(0.05)
896+
self.click("a.analytics") # Clicks the generated button
897+
time.sleep(0.03)
898+
899+
def generate_traffic(self, start_page, destination_page, loops=1):
900+
""" Similar to generate_referral(), but can do multiple loops. """
901+
for loop in range(loops):
902+
self.generate_referral(start_page, destination_page)
903+
time.sleep(0.05)
904+
875905
############
876906

877907
def wait_for_element_present(self, selector, by=By.CSS_SELECTOR,

seleniumbase/fixtures/page_utils.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
This module contains useful utility methods.
33
"""
4+
import re
45
import requests
56

67

@@ -42,6 +43,21 @@ def is_xpath_selector(selector):
4243
return False
4344

4445

46+
def is_valid_url(url):
47+
regex = re.compile(
48+
r'^(?:http)s?://' # http:// or https://
49+
r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+'
50+
r'(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' # domain...
51+
r'localhost|' # localhost...
52+
r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip
53+
r'(?::\d+)?' # optional port
54+
r'(?:/?|[/?]\S+)$', re.IGNORECASE)
55+
if regex.match(url):
56+
return True
57+
else:
58+
return False
59+
60+
4561
def _download_file_to(file_url, destination_folder, new_file_name=None):
4662
if new_file_name:
4763
file_name = new_file_name

server_setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
setup(
1010
name='seleniumbase',
11-
version='1.5.2',
11+
version='1.5.3',
1212
description='Web Automation & Testing Framework - http://seleniumbase.com',
1313
long_description='Web Automation and Testing Framework - seleniumbase.com',
1414
platforms='Mac * Windows * Linux * Docker',

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
setup(
1010
name='seleniumbase',
11-
version='1.5.2',
11+
version='1.5.3',
1212
description='Web Automation & Testing Framework - http://seleniumbase.com',
1313
long_description='Web Automation and Testing Framework - seleniumbase.com',
1414
platforms='Mac * Windows * Linux * Docker',

0 commit comments

Comments
 (0)