Juha Mustonen avatar Juha Mustonen committed 325b9f3

Conditional login test

Comments (0)

Files changed (3)


 import logging
+import os
 import unittest
+import urllib
+import urlparse
 from splinter.browser import Browser
+from splinter.driver.webdriver.firefox import WebDriver as FirefoxWebDriver
+from splinter.driver.webdriver.chrome import WebDriver as ChromeWebDriver
 from splinter.driver import ElementAPI
+class ChromeBrowser(ChromeWebDriver):
+  def visit_path(self, path):
+    # In this service, app is deployed at root. thus replace the path
+    res = urlparse.urlsplit(self.url)
+    newres = urlparse.SplitResult(res.scheme, res.netloc, path , res.query, res.fragment)
+    newurl = urlparse.urlunsplit(newres)
+    self.visit(newurl)
 class WebBrowser(object):
   Singleton browser
   def __new__(cls, *arg):
     if not WebBrowser.instance:
-      WebBrowser.instance = Browser('chrome')
+      WebBrowser.instance = ChromeBrowser()
+      #WebBrowser.instance = Browser('chrome')
     return WebBrowser.instance
 class PageElement(object):
 class PageObject(unittest.TestCase):
   def __setitem__(self, key, value):
-    #if hasattr(self.__class__, key):
     if hasattr(self, key):
-      #setattr(self.__class__, key, value)
       setattr(self, key, value)
   def __getitem__(self, key):
-    #if hasattr(self.__class__, key):
     if hasattr(self, key):
-      #return getattr(self.__class__, key)
       return getattr(self, key)
     raise Exception('Element %s cannot be found page object %s' % (key, self.__class__))


 from webtests.objects import WebBrowser, PageObject, PageElement, TextInput, Checkbox
+class WelcomePage(PageObject):
-class LoginMockupPage(PageObject):
+  def __init__(self, browser):
+    self.login = PageElement('a.login')
+class TestLoginPage(PageObject):
   def __init__(self, browser):
     self.email = TextInput('input#email')


 from webtests.objects import WebBrowser
 from webtests import pages
-from webtests.server import Server
+#from webtests.server import Server
 class BasicUsage(unittest.TestCase):
   def setUp(self):
     self.browser = WebBrowser()
-  def test_login(self):
-    login = pages.LoginMockupPage(self.browser)
+  def test_smoke(self):
+    """
+    Smoke test set
+    """
+    # Sometimes user home page is shown.. weird.
+    if self.browser.is_element_present_by_css('a.login'):
+      welcome = pages.WelcomePage(self.browser)
+      welcome.login.click()
+    login = pages.TestLoginPage(self.browser)
     login.email.value = 'juha@localhost'
+    self.browser.visit_path('uninstall')
     install = pages.InstallPage(self.browser)
   def tearDown(self):
     print 'tear down'
-    self.browser.quit()
+    #self.browser.quit()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.