# -*- coding: utf-8 -*-
'''
(c) Copyright 2014 Telefonica, I+D. Printed in Spain (Europe). All Rights
Reserved.

The copyright to the software program(s) is property of Telefonica I+D.
The program(s) may be used and or copied only with the express written
consent of Telefonica I+D or in accordance with the terms and conditions
stipulated in the agreement/contract under which the program(s) have
been supplied.
'''
from selenium_tid_python.selenium_test_case import SeleniumTestCase
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium_tid_python import selenium_driver


class AndroidEbookStore(SeleniumTestCase):
    def setUp(self):
        # Updating properties
        config = selenium_driver.config
        if not config.getboolean_optional('Server', 'enabled'):
            previous_browser = config.get('Browser', 'browser')
            config.set('Browser', 'browser', 'android')
            self.addCleanup(config.set, 'Browser', 'browser', previous_browser)
        config.set('AppiumCapabilities', 'automationName', 'Appium')
        config.set('AppiumCapabilities', 'platformName', 'Android')
        config.set('AppiumCapabilities', 'deviceName', 'Android Emulator')
        config.set('AppiumCapabilities', 'browserName', '')
        config.set('AppiumCapabilities', 'app', 'http://qacore02/sites/seleniumExamples/EbookStore.apk')
        super(AndroidEbookStore, self).setUp()

    def test_open_book_by_title(self):
        book_title = "El Nombre de la Rosa"
        wait = WebDriverWait(self.driver, 10)
        wait.until(EC.element_to_be_clickable((By.NAME, book_title))).click()

        # Wait until page has changed
        wait.until(EC.invisibility_of_element_located((By.ID, "user_info")))

        opened_book_title = self.driver.find_element_by_xpath("(//android.widget.TextView)[2]").text
        self.logger.debug("Book title: '" + opened_book_title + "'")
        self.assertEqual(book_title, opened_book_title, "The book title is wrong")

@@ -1610,15 +1610,8 @@
     
- wait =
  Web
@@ -1637,29 +1637,16 @@
 ver, 10)
-%0A        wait
 .until(E
@@ -1754,53 +1754,49 @@
     
-wait
+self
 .u
-n
 til
-(EC.invisibility_of_element_located
+s.wait_until_element_not_visible
 ((By
@@ -1813,17 +1813,16 @@
 _info%22))
-)
 %0A%0A      

Use wait method from utils class to run tests quickly