Re: simple web/html testing
For static html testing, I'd avoid using Selenium. Even though Selenium is
*the* tool for RIA and javascript intensive environments, feels like bringing
up a browser with all the coordination and resources that it takes just to
crawl the website and find 404s is an overkill.
What we implemented for doing that is just a simple crawler based on urllib:
class LinkTest(MechanizeTestCase):
def __init__(self, *args, **kwargs):
super(LinkTest, self).__init__(*args, **kwargs)
self.pages = ['/?']
self.exceptions = ['/forums',
'/blog']
def _page_test(self, url):
try:
self.get(url[1:], local=True)
except Exception, e:
raise Exception("Couldn't test %s - %s (%s)" % (url, e,
self.exceptions))
try:
links = self.mbrowser.links()
except mechanize.BrowserStateError, e:
return
for l in links:
if not l.url.startswith('/'):
continue
if l.url in self.exceptions:
continue
self.pages.append(l.url)
self.pages = list(set(self.pages))
try:
mechanize.urlopen(l.absolute_url)
#Apparently this will raise with the HTTP Error code
except Exception, e:
raise Exception("Error with link '%s' on page '%s'" % (l.url,
url))
def test_all_links(self):
while self.pages:
x = self.pages.pop()
if x not in self.exceptions:
print "Trying %s" % x
self._page_test(x)
self.exceptions.append(x)
self.exceptions = list(set(self.exceptions))
And basically, MechanizeTestCase is a couple of handy assertions as well as
instantiating a mechanize instance:
class MechanizeTestCase(TestCase):
def setUp(self, extra=None):
self.config = load_config() or self.fail('Failed to load config.')
def __init__(self, arg):
super(MechanizeTestCase, self).__init__(arg)
self.mbrowser = mechanize.Browser()
def get(self, url, local=True):
self.last_url = url
if local:
url = self.config['base-url'] + url
self._page = self.mbrowser.open(url)
self._content = self._page.read()
def submitForm(self):
self._page = self.mbrowser.submit()
self._content = self._page.read()
def assertWantedContent(self, content):
self.assertTrue(content in self._content,
"couldn't find %s in /%s" % (content, self.last_url))
def assertUrl(self, url):
self.assertEqual(self.config['base-url'] + url, self._page.geturl(),
"wrong url expected: %s, received: %s, content: %s" % (url,
self._page.geturl(), self._content))
Hope this helps
--
http://mail.python.org/mailman/listinfo/python-list
Re: Selenium Webdriver + Python (How to get started ??)
On Monday, April 22, 2013 8:24:40 AM UTC-4, [email protected] wrote: > Note that:- I have some experience of using Selenium IDE and Webdriver > (Java). but no prior experience of Python. > > > > Now there is a project for which I will need to work with webdriver + Python. > > > > So far I have done following steps.. > > > > Install JDK > > Setup Eclipse > > download & Installed Python v3.3.1 > > Download & Installed Pydev (for Eclipse) also configured > > download & installed (Distribute + PIP) > http://www.lfd.uci.edu/~gohlke/pythonlibs/#pip > > Installed Selenium using command prompt > > > > Running following commands from windows 7 command prompt, successfully opens > firefox browser > > > > python > > >>>from selenium import webdriver > > >>>webdriver.Firefox() > > > > -- > > > > ISSUE is that, I do not know exact steps of creating a python webdriver test > project. > > > > I create new Pydev project with a "src" folder and also used sample python > code from internet but selenium classes cannot be recognized. I have tried > various approaches to import libraries but none seems to work. Any one can > guide me what i need to do step by step to successfully run a simple test via > python webdriver!! (eclipse pydev) > > > > Thank you. I'm guessing your PyDev setup is not configured to use pip and your dependencies? How about this: http://stackoverflow.com/questions/4631377/unresolved-import-issues-with-pydev-and-eclipse -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP 372 -- Adding an ordered directory to collections
Hi all, I'm a first-time writer here, so excuse me if I say something inappropriate or such. Last week, I was reviewing some Python 2.7 modules when I came across the OrderedDict data structure. After seeing its official implementation and also after reading through the corresponding PEP, I figured out another way of implementing it. As I recently saw here, the idea is similar to the one proposed by bearophile, but nevertheless I think it is more efficient since there is no need to perform lookups multiple times. The idea is to embed the doubly-linked list of items in the dictionary itself, and extend the values inserted by providing a node as a 4-tuple . Of course, references to the first and last nodes must be kept too, in addition to the dictionary. After implementing this approach, I experimented a little bit and compared both versions (i.e., the official one that uses an extra dictionary and mine) by measuring the running times of some basic operations. I verified that it indeed outperforms the existing implementation. I made up a recipe with the code and several comments, including more details about the experimentation mentioned above: http://code.activestate.com/recipes/577826-yet-another-ordered-dictionary/ Comments will be surely appreciated! Lucio -- http://mail.python.org/mailman/listinfo/python-list
Re: Ten rules to becoming a Python community member.
On Mon, Aug 15, 2011 at 9:06 AM, Neil Cerutti wrote:
> On 2011-08-14, Chris Angelico wrote:
> > On Sun, Aug 14, 2011 at 2:21 PM, Irmen de Jong
> wrote:
> >> On 14-8-2011 7:57, rantingrick wrote:
> >>> 8. Use "e.g." as many times as you can! (e.g. e.g.) If you use "e.g."
> >>> more than ten times in a single post, you will get an invite to
> >>> Guido's next birthday party; where you'll be forced to do shots whist
> >>> walking the balcony railing wearing wooden shoes!
> >>
> >> I lolled about this one, e.g. I laughed out loud. But where
> >> are the tulips and windmills for extra credit?
> >>
> >> Greetings from a Dutchman!
>
> No credit. E.g., i.e., exampla gratis, means, "for example."
>
The correct spelling is 'exempli gratia'. It's Latin.
i.e., on the other hand, comes from 'id est' ('that is'). Latin too.
Regards,
Lucio
--
http://mail.python.org/mailman/listinfo/python-list
