@@ -27,6 +27,7 @@ def test_anything(self):
27
27
import os
28
28
import pytest
29
29
import re
30
+ import requests
30
31
import sys
31
32
import time
32
33
import traceback
@@ -746,6 +747,35 @@ def add_css_style(self, css_style):
746
747
'''h.appendChild(s);''' )
747
748
self .execute_script (add_css_style_script % re .escape (css_style ))
748
749
750
+ def add_js_code_from_link (self , js_link ):
751
+ if js_link .startswith ("//" ):
752
+ js_link = "http:" + js_link
753
+ js_code = requests .get (js_link ).text
754
+ add_js_code_script = (
755
+ '''var h = document.getElementsByTagName('head').item(0);'''
756
+ '''var s = document.createElement("script");'''
757
+ '''s.type = "text/javascript";'''
758
+ '''s.onload = function() {$("html")};'''
759
+ '''s.appendChild(document.createTextNode("%s"));'''
760
+ '''h.appendChild(s);''' )
761
+ self .execute_script (add_js_code_script % re .escape (js_code ))
762
+
763
+ def add_meta_tag (self , http_equiv = None , content = None ):
764
+ if http_equiv is None :
765
+ http_equiv = "Content-Security-Policy"
766
+ if content is None :
767
+ content = ("default-src *; style-src 'self' 'unsafe-inline'; "
768
+ "script-src: 'self' 'unsafe-inline' 'unsafe-eval'" )
769
+ script_to_add_meta = (
770
+ """function injectMeta() {
771
+ var meta = document.createElement('meta');
772
+ meta.httpEquiv = "%s";
773
+ meta.content = "%s";
774
+ document.getElementsByTagName('head')[0].appendChild(meta);
775
+ }
776
+ injectMeta();""" % (http_equiv , content ))
777
+ self .execute_script (script_to_add_meta )
778
+
749
779
def activate_jquery (self ):
750
780
""" If "jQuery is not defined", use this method to activate it for use.
751
781
This happens because jQuery is not always defined on web sites. """
0 commit comments