tag:blogger.com,1999:blog-5906775494486946082024-02-19T22:52:36.561-08:00Mobile Wireless Test AutomationJulianHartyhttp://www.blogger.com/profile/15418816908129476730noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-590677549448694608.post-10417000103891459482009-07-14T07:37:00.000-07:002009-07-14T07:40:32.849-07:00New support site for Mobile Wireless Test AutomationI've created a <a href="http://sites.google.com/site/mobilewirelesstestautomation/">public site</a> containing topics related to mobile wireless test automation. I hope you find it useful, your feedback and comments are welcome.<br /><br />JulianJulianHartyhttp://www.blogger.com/profile/15418816908129476730noreply@blogger.com0tag:blogger.com,1999:blog-590677549448694608.post-40698390797191631612007-12-03T11:27:00.000-08:002007-12-03T11:33:49.313-08:00<span style="font-family: courier new;">""" Markup Example 12</span><br /><br /><span style="font-family: courier new;">Adding a user-agent string to emulate a Nokia 6230</span><br /><br /><span style="font-family: courier new;">author: Julian Harty</span><br /><span style="font-family: courier new;">edited: 03 December 2007</span><br /><span style="font-family: courier new;">"""</span><br /><span style="font-family: courier new;">import urllib</span><br /><span style="font-family: courier new;">import re</span><br /><span style="font-family: courier new;">import amara</span><br /><br /><br /><span style="font-family: courier new;">def getHrefFromXML(doc, search_regex):</span><br /><span style="font-family: courier new;"> """Returns the href link if the in search_regex is</span><br /><span style="font-family: courier new;"> found in any </span><div style="font-family: courier new;"> tags.<br /> <br /> Assumes the links are in the html body's div tags.<br /> <br /> Args:<br /> doc: an amara xml object<br /> search_regex: the regular expression to match in<br /> the href text<br /> <br /> Returns:<br /> the href as a string if the pattern is found, else None.<br /> """<br /> ru1 = re.compile(search_regex)<br /> for item in doc.html.body.div:<br /> try:<br /> # print str(item.a.xml_children[0])<br /> # print type(item.a.xml_children[0])<br /> p = ru1.search(item.a.xml_children[0])<br /> if p:<br /> return item.a.href<br /> except:<br /> pass<br /><br /> return None<br /><br />if __name__ == "__main__": <br /> request = urllib.FancyURLopener()<br /> request.addheader('Accept', <br /> 'application/xhtml+xml')<br /> request.addheader('User-Agent', <br /> 'Nokia6230/2.0+(04.43)'<br /> '+Profile/MIDP-2.0+Configuration'<br /> '/CLDC-1.1+UP.Link/6.3.0.0.0')<br /> response = request.open("http://www.google.co.uk/m")<br /> content = response.read()<br /><br /> # Use the live content<br /> doc = amara.parse(content)<br /> print "should return: '/gmm?source=m&dc=mobile-promotion'"<br /> print getHrefFromXML(doc, "Maps") </div>JulianHartyhttp://www.blogger.com/profile/15418816908129476730noreply@blogger.com0tag:blogger.com,1999:blog-590677549448694608.post-12321049090765958902007-12-03T11:24:00.000-08:002007-12-03T11:36:18.859-08:00Markup exercise 12 using cached file<span style="font-family: courier new;">""" Markup Example 12 local<br /><br />Adding a user-agent string to emulate a Nokia 6230<br />Reads the content from a cached file<br /><br />author: Julian Harty<br />edited: 03 December 2007<br />"""<br />import re<br />import amara<br /><br /><br />def getHrefFromXML(doc, search_regex):<br /> """Returns the href link if the in search_regex is<br /> found in any div tags.<br /> <br /> Assumes the links are in the html body's div tags.<br /> <br /> Args:<br /> doc: an amara xml object<br /> search_regex: the regular expression to match in<br /> the href text<br /> <br /> Returns:<br /> the href as a string if the pattern is found, else None.<br /> """<br /> ru1 = re.compile(search_regex)<br /> for item in doc.html.body.div:<br /> try:<br /> # print str(item.a.xml_children[0])<br /> # print type(item.a.xml_children[0])<br /> p = ru1.search(item.a.xml_children[0])<br /> if p:<br /> return item.a.href<br /> except:<br /> pass<br /><br /> return None<br /><br />if __name__ == "__main__": <br /> # use a local copy of the content<br /> doc = amara.parse(open("mobile-homepage.xhtml"))<br /><br /> print "should return: '/gmm?source=m&dc=mobile-promotion'"<br /> print getHrefFromXML(doc, "Maps") <br /></span>JulianHartyhttp://www.blogger.com/profile/15418816908129476730noreply@blogger.com0tag:blogger.com,1999:blog-590677549448694608.post-8375302459075241302007-12-03T10:59:00.000-08:002007-12-03T11:38:37.804-08:00Markup exercise 11b prettified<span style="font-family:courier new;">""" Markup Example 11<br /><br />Defines the method getlLinkFromXhtml() which is later used to return the href<br />for a given regular expression, if it exists.<br /><br />(Includes the code form markup example 07)<br /><br />author: Julian Harty<br />edited: 03 December 2007<br />"""<br />import re<br />import sys<br />import urllib<br />import BeautifulSoup<br /><br />from xml.dom import minidom<br /><br />def getLinkFromXhtml(content, text_regex):<br /> """getLink returns the href link for a given text_label.<br /> <br /> Args:<br /> content: the source content e.g. an xHTML response.<br /> text_regex: the text to match as a regluar experession.<br /> Returns:<br /> The href if the test is found, else None.<br /> """<br /> <br /> doc = minidom.parseString(content)<br /> links = doc.getElementsByTagName('a')<br /> <br /> rx = re.compile(text_regex)<br /> <br /> for i in links:<br /> if i.hasAttribute('href'):<br /> t = i.firstChild<br /> text = ""<br /> while t:<br /> if t.nodeType == t.TEXT_NODE:<br /> text += t.data<br /> t = t.nextSibling<br /> match = rx.search(text)<br /> if match:<br /> return str(i.toxml())<br /> <br /> return None<br /><br /><br />request = urllib.FancyURLopener()<br />request.addheader('Accept', 'application/xhtml+xml')<br />request.addheader('User-Agent',<br /> 'Nokia6230/2.0+(04.43)+Profile/MIDP-2.0+'<br /> 'Configuration/CLDC-1.1+UP.Link/6.3.0.0.0')<br />response = request.open("http://www.google.co.uk/m")<br />content = response.read()<br /><br />print getLinkFromXhtml(content, 'Maps with My Location')<br /><br />soup = BeautifulSoup.BeautifulSoup(content)<br />#print soup.prettify()<br /><br /># write the content to a file so it can be displayed in a browser<br />f = open("markup_ex11b_prettified.xml", "wb")<br />f.write(content)<br />f.close()<br /><br /><br /></span>JulianHartyhttp://www.blogger.com/profile/15418816908129476730noreply@blogger.com1tag:blogger.com,1999:blog-590677549448694608.post-19367455713813151522007-12-03T10:55:00.000-08:002007-12-03T10:58:38.011-08:00Sample python code Exercise 04 prettified<span style="font-family:courier new;"><br />""" Markup Example 04</span><br /><br /><span style="font-family:courier new;">Adding the accept header for xHTML</span><br /><br /><span style="font-family:courier new;">author: Julian Harty</span><br /><span style="font-family:courier new;">edited: 03 December 2007</span><br /><span style="font-family:courier new;">"""</span><br /><span style="font-family:courier new;">import urllib</span><br /><span style="font-family:courier new;">import BeautifulSoup</span><br /><br /><span style="font-family:courier new;">request = urllib.FancyURLopener()</span><br /><span style="font-family:courier new;">request.addheader('Accept', 'application/xhtml+xml') </span><br /><span style="font-family:courier new;">response = request.open("http://www.google.co.uk/m")</span><br /><span style="font-family:courier new;">content = response.read()</span><br /><br /><span style="font-family:courier new;"># Display the formatted contents</span><br /><span style="font-family:courier new;">soup = BeautifulSoup.BeautifulSoup(content)</span><br /><span style="font-family:courier new;">print soup.prettify()</span><br /><br /><span style="font-family:courier new;"># write the content to a file so it can be displayed in a browser</span><br /><span style="font-family:courier new;">f = open("markup_ex04_prettified.xml", "wb")</span><br /><span style="font-family:courier new;">f.write(content)</span><br /><span style="font-family:courier new;">f.close()</span>JulianHartyhttp://www.blogger.com/profile/15418816908129476730noreply@blogger.com1tag:blogger.com,1999:blog-590677549448694608.post-75203346797684305542007-12-03T10:48:00.000-08:002007-12-03T10:50:50.675-08:00Mobile Wireless Test Automation at EuroSTAR2007I will be presenting on this topic at the EuroSTAR 2007 conference as a 1/2 day tutorial on Tuesday 4th December 2007. I expect to learn as much as I present from the 70+ participants who have booked to join me. Thank you all :)JulianHartyhttp://www.blogger.com/profile/15418816908129476730noreply@blogger.com1