Selenium python GBiB script: Difference between revisions

From Genecats
Jump to navigationJump to search
Line 161: Line 161:
## If you try to run this file, you must have your GBiB up and running as the URLs point to http://127.0.0.1:1234/cgi-bin/hgGateway
## If you try to run this file, you must have your GBiB up and running as the URLs point to http://127.0.0.1:1234/cgi-bin/hgGateway
## In the next step you will swap these URLs to point to hgw0-6
## In the next step you will swap these URLs to point to hgw0-6
## Before you do that remove the lines that point to the hgMirror GBiB-only CGI, maybe make this one hgwbeta.
## Before you do that remove the lines that point to the hgMirror GBiB-only CGI
###        driver.get("http://127.0.0.1:1234/cgi-bin/hgMirror")
###        driver.get("http://127.0.0.1:1234/cgi-bin/hgMirror")
###  driver.find_element_by_link_text("Predefined tracks sets").click()
###  driver.find_element_by_link_text("Predefined tracks sets").click()
# Copy your test/hgwbeta file and name it hgw0.selenium.py (for i in {0..6}; do cp hgwbeta.py hgw$i.selenium.py; done)
### Copy your test file and name it hgw0.selenium.py or run this loop (for i in {0..6}; do cp test.py hgw$i.selenium.py; done)
# Now run this perl statement to swap the GBIB address for the hgw0 address
# Now run this perl statement to swap the GBIB address for the hgw0 address
##<code>perl -p -i -e 's#127.0.0.1:1234#hgw0.cse.ucsc.edu#'  hgw0.selenium.py</code>
##<code>perl -p -i -e 's#127.0.0.1:1234#hgw0.cse.ucsc.edu#'  hgw0.selenium.py</code>

Revision as of 23:32, 14 September 2015

Overview

This is an example script that runs on python2.7 with installed selenium (pip install selenium) .

Below is also a section about adapting this script to point it to the RR.

Running

python gbib.selenium.py

Results desired:

$python gbib.selenium.py
.
----------------------------------------------------------------------
Ran 1 test in 106.073s

OK
  • Be sure to watch the script run, it isn't verifying results happen.

Script Code

This code probably has imperfections, it is copy of an earlier script pointed to genome-euro with the http replaced with GBiBs 127.0.0.01:1234 address.

The process to build it was to use FireFoxes Selenium plug-in to record steps. Then to use the plug-in to export it as python. I recall it needed some changes to work with python2.7. I tested that I could cut and paste the below and execute the code in my environment (Python 2.7.6 with the pip install of selenium).

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
import unittest, time, re

class Genome(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Firefox()
        self.driver.implicitly_wait(30)
        self.base_url = "http://127.0.0.1:1234/cgi-bin/hgGateway"
        self.verificationErrors = []
        self.accept_next_alert = True
    
    def test_genome(self):
        driver = self.driver
        driver.get(self.base_url + "Be sure you are not being redirected to genome vs. genome-euro")
        driver.get("http://127.0.0.1:1234/cgi-bin/hgGateway")
        # ERROR: Caught exception [ERROR: Unsupported command [selectWindow | null | ]]
        driver.get("http://127.0.0.1:1234/cgi-bin/hgGateway")
        driver.find_element_by_id("home-link").click()
        driver.find_element_by_link_text("Genome Browser").click()
        driver.find_element_by_link_text("Genomes").click()
        driver.find_element_by_link_text("Click here to reset").click()
        driver.find_element_by_link_text("click here to continue").click()
        driver.get("http://127.0.0.1:1234/cgi-bin/hgGateway?db=hg19")
        Select(driver.find_element_by_name("org")).select_by_visible_text("Mouse")
        driver.find_element_by_name("Submit").click()
        driver.find_element_by_link_text("Genomes").click()
        Select(driver.find_element_by_css_selector("select[name=\"db\"]")).select_by_visible_text("July 2007 (NCBI37/mm9)")
        driver.find_element_by_name("Submit").click()
        driver.find_element_by_link_text("Genomes").click()
        driver.find_element_by_link_text("Click here to reset").click()
        driver.find_element_by_link_text("click here to continue").click()
        driver.get("http://127.0.0.1:1234/cgi-bin/hgGateway?db=hg19")
        driver.find_element_by_name("Submit").click()
        driver.find_element_by_xpath("//td[@id='td_data_knownGene']/div[2]/map/area[4]").click()
        driver.find_element_by_link_text("Genome Browser").click()
        driver.find_element_by_css_selector("map[name=\"map_data_refGene\"] > area.area").click()
        driver.find_element_by_css_selector("map[name=\"map_data_refGene\"] > area.area").click()
        driver.find_element_by_link_text("Genome Browser").click()
        driver.find_element_by_css_selector("input[type=\"button\"]").click()
        driver.find_element_by_name("hgct_customText").clear()
        driver.find_element_by_name("hgct_customText").send_keys("http://hgwdev.cse.ucsc.edu/~brianlee/customTracks/examples.txt")
        driver.find_element_by_name("Submit").click()
        driver.find_element_by_name("submit").click()
        driver.find_element_by_link_text("Genomes").click()
        driver.find_element_by_link_text("Click here to reset").click()
        driver.find_element_by_link_text("click here to continue").click()
        driver.get("http://127.0.0.1:1234/cgi-bin/hgGateway?db=hg19")
        driver.find_element_by_xpath("//input[@value='track hubs']").click()
        driver.find_element_by_link_text("My Hubs").click()
        driver.find_element_by_id("hubUrl").clear()
        driver.find_element_by_id("hubUrl").send_keys("http://hgwdev.cse.ucsc.edu/~brianlee/examples/hubExample/hub.txt")
        driver.find_element_by_name("hubAddButton").click()
        driver.find_element_by_name("Submit").click()
        driver.find_element_by_link_text("Genomes").click()
        driver.find_element_by_link_text("Click here to reset").click()
        driver.find_element_by_link_text("click here to continue").click()
        driver.get("http://127.0.0.1:1234/cgi-bin/hgGateway?db=hg19")
        driver.get("http://127.0.0.1:1234/cgi-bin/hgBlat")
        driver.find_element_by_name("userSeq").clear()
        driver.find_element_by_name("userSeq").send_keys("AACAAAATCAAACTGTTTTTGTTGGACAATTCTCTGTTAAGCAGCTATAA\nGCTGAATGACATTAACCGCAAAATGTAACCATAAAGGCCATAAACCCGAC\nATTGTTAATTAATTAAATGCCTCATTAACTTTTTTAAAAACATGATTTAT\nTCGATTCATAGAAAACTTAACCATCACTACTAAATGCACACACATGCGGT\nTCCACATTGGCATCTTAGCCTAAGAACAGACAGGTTCAACTGTAACTGGC\nCTTTCAGGTGGTCTATTACAGATCTGAAGACAGAGGGTGTTTCTAAACCT\nCAAGAACCAGATTAACAGAAAACAAAGCTTGAGCAGCCTTTTTATTGCAT\nGTGGTATCTTTTTAGCTAAGCAGAAGACAATGATAAAGAGGGGTTTTGGG\nAAACCTCTCCCAAAGCTGTGCATTCATACCGTACCTTATCCTGTTAAGCA\nAACTGTTCTTTTATTTTAAAGGGTTTACACTGCCACATCTGAATGGACTA")
        driver.find_element_by_name("Submit").click()
        driver.find_element_by_link_text("browser").click()
        driver.get("http://127.0.0.1:1234/cgi-bin/hgPcr")
        driver.find_element_by_name("wp_f").clear()
        driver.find_element_by_name("wp_f").send_keys("AACAAAATCAAACTGTTTTTGTTGGACAATTCTCTGTTAAGCAGCTATAA")
        driver.find_element_by_name("wp_r").clear()
        driver.find_element_by_name("wp_r").send_keys("AACTGTTCTTTTATTTTAAAGGGTTTACACTGCCACATCTGAATGGACTA")
        driver.find_element_by_name("wp_flipReverse").click()
        driver.find_element_by_name("Submit").click()
        driver.find_element_by_link_text("chrX:39918932+39919431").click()
        driver.find_element_by_link_text("Genomes").click()
        driver.find_element_by_link_text("Click here to reset").click()
        driver.find_element_by_link_text("click here to continue").click()
        driver.get("http://127.0.0.1:1234/cgi-bin/hgGateway?db=hg19")
        driver.find_element_by_name("Submit").click()
        driver.get("http://127.0.0.1:1234/cgi-bin/hgConvert")
        Select(driver.find_element_by_name("hglft_toOrg")).select_by_visible_text("Human")
        Select(driver.find_element_by_name("hglft_toOrg")).select_by_visible_text("Mouse")
        Select(driver.find_element_by_name("hglft_toDb")).select_by_visible_text("July 2007 (NCBI37/mm9)")
        driver.find_element_by_name("hglft_doConvert").click()
        driver.find_element_by_link_text("chr16:90220619-90227077").click()
        driver.find_element_by_link_text("Genome Browser").click()
        driver.get("http://127.0.0.1:1234/cgi-bin/hgMirror")
        driver.find_element_by_link_text("Predefined tracks sets").click()
        driver.find_element_by_link_text("Genome Browser").click()
        driver.get("http://127.0.0.1:1234/cgi-bin/hgLiftOver")
        Select(driver.find_element_by_name("hglft_fromOrg")).select_by_visible_text("Human")
        driver.find_element_by_name("hglft_userData").clear()
        driver.find_element_by_name("hglft_userData").send_keys("chr21:33,031,597-33,041,570")
        driver.find_element_by_name("hglft_multiple").click()
        driver.find_element_by_name("Submit").click()
        driver.find_element_by_link_text("View Conversions").click()
        driver.find_element_by_link_text("Genome Browser").click()
        self.assertEqual("chr16:90,220,619-90,227,077", driver.find_element_by_id("positionDisplay").text)
    
    def is_element_present(self, how, what):
        try: self.driver.find_element(by=how, value=what)
        except NoSuchElementException as e: return False
        return True
    
    def is_alert_present(self):
        try: self.driver.switch_to_alert()
        except NoAlertPresentException as e: return False
        return True
    
    def close_alert_and_get_its_text(self):
        try:
            alert = self.driver.switch_to_alert()
            alert_text = alert.text
            if self.accept_next_alert:
                alert.accept()
            else:
                alert.dismiss()
            return alert_text
        finally: self.accept_next_alert = True
    
    def tearDown(self):
        self.driver.quit()
        self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
    unittest.main()

Adapting Script to Point to RR

You can take this script and copy it to point to the RR.

  1. Create a directory that you put your RR directed scripts into, I called mine hgw0.6
  2. Create a text file of the above script copied and pasted
    1. If you try to run this file, you must have your GBiB up and running as the URLs point to http://127.0.0.1:1234/cgi-bin/hgGateway
    2. In the next step you will swap these URLs to point to hgw0-6
    3. Before you do that remove the lines that point to the hgMirror GBiB-only CGI
      1. driver.get("http://127.0.0.1:1234/cgi-bin/hgMirror")
      2. driver.find_element_by_link_text("Predefined tracks sets").click()
      3. Copy your test file and name it hgw0.selenium.py or run this loop (for i in {0..6}; do cp test.py hgw$i.selenium.py; done)
  3. Now run this perl statement to swap the GBIB address for the hgw0 address
    1. perl -p -i -e 's#127.0.0.1:1234#hgw0.cse.ucsc.edu#' hgw0.selenium.py
    2. do echo "perl -p -i -e 's#127.0.0.1:1234#hgw$i.cse.ucsc.edu#' hgw$i.selenium.py" >> script; done
    3. chmod 700 script; ./script
  4. Repeat the above steps of copying your test file, and swapping the address so you create scripts for all machines.
    1. For example, create hgw1.selenium.py
    2. Then run perl -p -i -e 's#127.0.0.1:1234#hgw1.cse.ucsc.edu#' hgw1.selenium.py
    3. At the end you will have seven selenium scripts for hgw0.... to hgw6.selenium.py
  5. Lastly you can run them back to back with this command. Check for the "OK" meaning it completed fine.
    1. for i in {0..6}; do echo;echo;echo;echo Running hgw$i test; python hgw$i.selenium.py; done