Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 97770

Selenium keeps a cache?

$
0
0

I have a more complicate question but I'm trying to isolate the problem to avoid confusion.

I'm testing a page using selenium. In this page there are two javascript external scripts. If you go there manually the page is working correctly but using selenium one of the javascript isn't loaded:

The script from “http://localhost:55234/static/js/common.js” was loaded even though its MIME type (“text/html”) is not a valid JavaScript MIME type.
2 add-name
Loading failed for the <script> with source “http://localhost:55234/static/js/common.js”.

Checking the source (right click => view page source) gives me correctly the template with this two lines (and the others, off course):

[...] 
<!-- load global javascript -->
    <script type='text/javascript' src="/static/js/common.js"></script>
<!-- load app javascript -->
  <script type='text/javascript' src="/static/lists/js/lists.js"></script>
[...]

the src are clickable. Cliking the first one reload the source page without the line three and four, so without this lines:

<!-- load app javascript -->
  <script type='text/javascript' src="/static/lists/js/lists.js"></script>

Clicking the second one (lists.js) gives the javascript code. But! But this code looks an (very) old version of my code. Many days old (isn't too long to be cached?). At that time all the code was in one javascript file (lists.js) and the other one (common.js) didn't existed so this can explain why isn't loaded.

Why is that? How can I update this code? If I go manually in the page I can find the real updated code.

Also can be useful to know that in my browser I recently selected 'Disable cache' in the Network tab (press F12 with firefox) and 'Disable HTTP cache (...)' in the setting just to avoid these problems. In the page opened by selenium these options are both unchecked. I tried to check both (using a breakpoint()) and reload the page but nothing changed.

I repeat, maybe the cause of this is somewhere else and there many other thing to say but I think is better to keeps things as simple as possible and open other questions when I need. Now, any of this make any sense? why my script isn't updated in days (I prefer to do not empty the cache, if possible)?

I found this code to delete the cache, should I try? It look right?

def setUp(self):
    profile = webdriver.FirefoxProfile()
    profile.set_preference("browser.cache.disk.enable", False)
    profile.set_preference("browser.cache.memory.enable", False)
    profile.set_preference("browser.cache.offline.enable", False)
    profile.set_preference("network.http.use-cache", False)
    self.browser = webdriver.Firefox(profile)

Here some code:

My template base.html:

[...]
<head>
  [...]
  <!-- load global javascript -->
  <script type='text/javascript' src="{% static '/js/common.js' %}"></script>
  <!-- load app javascript -->
  {% block script %}{% endblock %}
[...]

my template list.html

{% block script %}
  <script type='text/javascript' src="{% static 'lists/js/lists.js' %}"></script>
{% endblock %}

where common.js is in myproject/static/js/common.js, while lists.js is in myproject/lists/static/lists/js/lists.js. I call both with {% static but it should be correct.

My test.py:

class NameFormSeleniumTest(LiveServerTestCase):
    def setUp(self):
        self.browser = webdriver.Firefox()
        self.browser.implicitly_wait(2)

    def tearDown(self):
        self.browser.quit()

    def test_form_can_save_a_name(self):
    # some code
    # english = ...
    self.browser.get(self.live_server_url + '/lists/add-name/')
    Select(self.browser.find_element_by_id('id_namelanguage')).\
        select_by_value(str(english.id))
    # ...
    breakpoint()
    form = NameForm({'nametype': nome.id, 'gender': maschio.id,
                     'name': 'Remo', 'namelanguage': english.id,
                     'usato': 0})
    print(form.errors)
    form.save()

The error the test gives is (in the line form = ...):

ValueError: The Name could not be created because the data didn't validate.

and form.error is:

<ul class="errorlist"><li>nametype<ul class="errorlist"><li>This field is required.</li></ul></li></ul>

but with breakpoint() I see the javascript function to add options to the field isn't found, the field stay empty so Select() don't select nothing, and the form gives the error.

Thank you for your help


Viewing all articles
Browse latest Browse all 97770

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>