Hi,
The below code extracts the branch number and the test environment to deploy that particular branches build on from a txt file (branch_dest.txt). Then it parses HTML pages to reach a webpage which contains some checkboxes. I want to check the "Select/Deselect All" checkbox and then click the "Deploy" button on that webpage.
How do i code this? I am basically from QA(Tester). So please help.
URL = "http://11.12.13.27:8080/cruisecontrol"
from urllib2 import urlopen
from HTMLParser import HTMLParser
import re
# Fetching links using HTMLParser
def get_links(url):
parser = MyHTMLParser()
parser.feed(urlopen(url).read())
parser.close()
return parser.links
# Build url for Deploy page
def get_deploy_url():
url = URL + "/buildresults/xxx_%s_nightly_build" % branch
print url
for link in get_links(url):
if link["href"].startswith("Deploy"):
return "%s/%s" % (URL, link["href"])
print link["href"]
# Build url for Destination page
def get_destination_url():
url = get_deploy_url()
print url
destination_re = re.compile(r"%s" % destination)
for link in get_links(url):
if destination_re.search(link["href"]):
return "http://11.12.13.27:8080/cruisecontrol/" + link["href"]
# Parsing HTML pages
class MyHTMLParser(HTMLParser):
def __init__(self, *args, **kwd):
HTMLParser.__init__(self, *args, **kwd)
self.links = []
def handle_starttag(self, tag, attrs):
if tag == "a":
attrs = dict(attrs)
if "href" in attrs:
self.links.append(dict(attrs))
def handle_endtag(self, tag):
pass
if __name__ == "__main__":
# Read the branch name and the test destination to deploy on
lines = [x.split(':') for x in open("branch_dest.txt")]
print lines
branch = "%s" % lines[0][1].strip()
print branch
destination = "%s" % lines[1][1].strip()
print destination
final_url = get_destination_url()
if final_url is None:
print "Could not find a destination to deploy"
else:
print final_url