2

Here is my TestCase:

class AdminTest(LiveServerTestCase):

  def setUp(self):
      self.browser = webdriver.Firefox()
      self.browser.set_window_size(1920, 1080)

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

  def test_admin_site(self):    
      # user opens web browser, navigates to admin page
      self.browser.get(self.live_server_url + '/admin/')
      body = self.browser.find_element_by_tag_name('body')
      self.assertIn('Django administration', body.text)

I find that the body of the content in HTML is very small. I tried maximizing the firefox by setting window_size, but that only increased the overall size. Here is the screenshot from selenium enter image description here

Here is the screenshot from running: python manage.py test my_app/ enter image description here

brain storm
  • 30,124
  • 69
  • 225
  • 393
  • what is the screen resolution of your desktop? Set your selenium window size to that. Try lowering the resolution to 1440x900 for instance instead of 1920x1080 like you have now – Sohan Jain May 12 '14 at 19:04
  • @SohanJain: That did not help. My screen resolution is 2560X1600 (Macbook Pro retina ) – brain storm May 12 '14 at 19:18
  • Ah, gotcha. Any luck with a much lower res? I've used 1280x800 with selenium/firefox with success before – Sohan Jain May 12 '14 at 19:27
  • @SohanJain: no luck. I dont think it has to do anything with screen resolution though.. – brain storm May 12 '14 at 20:17
  • @brainstorm: I think the page is designed this way. Have a look at the screenshot ( [direct link](http://www.djangobook.com/en/2.0/_images/login.png) ) of the login page (figure 6-1) on [the django book](http://www.djangobook.com/en/2.0/chapter06.html). If you open the page directly in the browser, you should see the same. – Faiz May 13 '14 at 03:42
  • @Faiz:I think you have not understood my question. please see the both the images I pasted above and notice the difference. one is small which is from `manage.py test` and one is normal which is from `manage.py runserver` – brain storm May 13 '14 at 17:47
  • @brainstorm: I see it now :) Also noticed that the favorites bar is not displayed, the icons, title tab bar as well as the address bar are much smaller in the first screenshot. Addons such as adblock plus are loaded in second but not the first. The first is therefore loading a blank profile, and the second with all bells and whistles. Try starting the first one with the default (or specific) profile. – Faiz May 13 '14 at 22:07
  • @Faiz: what do you mean by try starting the first one with the default profile? – brain storm May 14 '14 at 01:35
  • @brainstorm: When creating the selenium webdriver firefox instance, use the firefox user profile that is loaded when you launch firefox normally (rather than letting it create its anonymous profile). See the usage section on `FirefoxProfile` Python doc [here](http://pydoc.net/Python/selenium/2.0dev3/selenium.webdriver.firefox.firefox_profile); additionally, [this](http://stackoverflow.com/a/23330140/2491792) and [this](https://code.google.com/p/selenium/wiki/TipsAndTricks) might help. – Faiz May 14 '14 at 02:00
  • @Faiz: Thanks for pointing these links. I tried them all. I could see the favorites bar displayed, but I have size issue. The body is really small. I am interested more in the size of body to be like native firefox I have when I see 127.0.0.1:8000 – brain storm May 14 '14 at 03:28
  • @brainstorm: It is then a zoom level issue in the loaded profile. As a last resort, try set the firefox zoom level preference to 1.2 (120%) or another number as `profile.set_preference('layout.css.devPixelsPerPx', 1.2)`. See [here](https://support.mozilla.org/en-US/questions/963759) for more information. – Faiz May 14 '14 at 03:39
  • A more informative link: https://support.mozilla.org/en-US/questions/962990 – Faiz May 14 '14 at 06:15

1 Answers1

4

What version of selenium are you using? I am currently using selenium==2.39.0 and do not have the issue. A colleague of mine reported the same issue as you when running selenium==2.41.0 and downgrading to the same version as me fixed the issue.

marchelbling
  • 1,909
  • 15
  • 23