from seltest import url, waitfor, hide, Base
from selenium.webdriver.support.ui import Select, WebDriverWait
import sys

PILEUP_RENDERED_JS = '''
return document.querySelector('.track.pileup canvas') && document.querySelector('.track.pileup canvas').height > 100
'''

def _pileup_is_rendered(driver):
    return driver.execute_script(PILEUP_RENDERED_JS)


def wait_for_pileup(driver):
    driver.implicitly_wait(0)
    WebDriverWait(driver, 120).until(_pileup_is_rendered, 'pileup timed out')
    driver.implicitly_wait(120)


class Pileup(Base):
    base_url = 'localhost:8080'
    window_size = (1280, 768)

    @url('/examples/?pos=chr17:7,512,374-7,512,554')
    @hide('#stats')
    def loose(self, driver):
        wait_for_pileup(driver)

    @url('/examples/?pos=chr17:7,514,241-7,514,331')
    @hide('#stats')
    def small_letters_mismatch(self, driver):
        wait_for_pileup(driver)

    @url('/examples/?pos=chr17:7,514,181-7,514,411')
    @hide('#stats')
    def blocks_mismatch(self, driver):
        wait_for_pileup(driver)

    @url('/examples/?pos=chr17:7,511,774-7,514,654')
    @hide('#stats')
    def gene_utf(self, driver):
        wait_for_pileup(driver)

    @url('/examples/?pos=chr17:7,513,279-7,513,459')
    @hide('#stats')
    def deletions(self, driver):
        wait_for_pileup(driver)

    @url('/examples/?pos=chr17:7,514,550-7,514,640')
    @hide('#stats')
    def inserts(self, driver):
        wait_for_pileup(driver)

    @url('/examples/?pos=chr17:7,514,000-7,515,000')
    @hide('#stats')
    def wide(self, driver):
        wait_for_pileup(driver)


@@ -25,16 +25,18 @@
  waitfor
+js
 , hide, 
@@ -44,82 +44,8 @@
 ase%0A
-from selenium.webdriver.support.ui import Select, WebDriverWait%0Aimport sys
 %0A%0API
@@ -193,286 +193,56 @@
 ''%0A%0A
-def _pileup_is_rendered(driver):%0A    return driver.execute_script(PILEUP_RENDERED_JS)%0A%0A%0Adef wait_for_pileup(driver):%0A    driver.implicitly_wait(0)%0A    WebDriverWait(driver, 120).until(_pileup_is_rendered, 'pileup timed out')%0A    driver.implicitly_wait(120)%0A%0A%0Aclass Pileup(Base):
+%0Aclass Pileup(Base):%0A    host = 'localhost:8080'
 %0A   
@@ -250,38 +250,33 @@
 base_url = '
-localhost:8080
+examples/
 '%0A    window
@@ -302,34 +302,24 @@
 %0A%0A    @url('
-/examples/
 ?pos=chr17:7
@@ -351,32 +351,67 @@
 @hide('#stats')%0A
+    @waitforjs(PILEUP_RENDERED_JS)%0A
     def loose(se
@@ -431,39 +431,20 @@
         
-wait_for_pileup(driver)
+pass
 %0A%0A    @u
@@ -443,34 +443,24 @@
 %0A%0A    @url('
-/examples/
 ?pos=chr17:7
@@ -492,32 +492,67 @@
 @hide('#stats')%0A
+    @waitforjs(PILEUP_RENDERED_JS)%0A
     def small_le
@@ -589,39 +589,20 @@
         
-wait_for_pileup(driver)
+pass
 %0A%0A    @u
@@ -601,34 +601,24 @@
 %0A%0A    @url('
-/examples/
 ?pos=chr17:7
@@ -650,32 +650,67 @@
 @hide('#stats')%0A
+    @waitforjs(PILEUP_RENDERED_JS)%0A
     def blocks_m
@@ -740,39 +740,20 @@
         
-wait_for_pileup(driver)
+pass
 %0A%0A    @u
@@ -752,34 +752,24 @@
 %0A%0A    @url('
-/examples/
 ?pos=chr17:7
@@ -801,32 +801,67 @@
 @hide('#stats')%0A
+    @waitforjs(PILEUP_RENDERED_JS)%0A
     def gene_utf
@@ -884,39 +884,20 @@
         
-wait_for_pileup(driver)
+pass
 %0A%0A    @u
@@ -896,34 +896,24 @@
 %0A%0A    @url('
-/examples/
 ?pos=chr17:7
@@ -945,32 +945,67 @@
 @hide('#stats')%0A
+    @waitforjs(PILEUP_RENDERED_JS)%0A
     def deletion
@@ -1029,39 +1029,20 @@
         
-wait_for_pileup(driver)
+pass
 %0A%0A    @u
@@ -1041,34 +1041,24 @@
 %0A%0A    @url('
-/examples/
 ?pos=chr17:7
@@ -1090,32 +1090,67 @@
 @hide('#stats')%0A
+    @waitforjs(PILEUP_RENDERED_JS)%0A
     def inserts(
@@ -1172,39 +1172,20 @@
         
-wait_for_pileup(driver)
+pass
 %0A%0A    @u
@@ -1192,18 +1192,8 @@
 rl('
-/examples/
 ?pos
@@ -1237,24 +1237,59 @@
 e('#stats')%0A
+    @waitforjs(PILEUP_RENDERED_JS)%0A
     def wide
@@ -1316,29 +1316,10 @@
     
-wait_for_pileup(driver)
+pass
 %0A%0A

Update to seltest 1.0.0