@@ -872,6 +872,36 @@ def pick_select_option_by_value(self, dropdown_selector, option,
872
872
dropdown_by = dropdown_by , option_by = "value" ,
873
873
timeout = timeout )
874
874
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
+
875
905
############
876
906
877
907
def wait_for_element_present (self , selector , by = By .CSS_SELECTOR ,
0 commit comments