# -*- coding: UTF-8 -*- import ldtp import os import time import json import sys #3 catala #9 espaƱol #38 valenciano class testubiquity: def __init__(self, language): self.context = {} self.appname = "" self.language = language self.__change_language_context(self.language) def enable_accesiblity(self): os.system("gsettings set org.gnome.desktop.interface toolkit-accessibility true") def waitstate(self, component, state, timeout=7): for x in range(0, timeout): if ldtp.hasstate(self.appname, component, state) == 1: return True time.sleep(1) z = ldtp.getobjectlist(self.appname) f = open("/home/lliurex/log", "w") json.dump(z, f) f.close() return False def update_name_app(self): aux = ldtp.getwindowlist()[-1] if self.context['appname'] in aux: self.appname = aux return True else: self.appname = self.context['appname'] return False def start_app(self, timeout=30): ldtp.launchapp('ubiquity') self.update_name_app() if ldtp.waittillguiexist(self.appname, guiTimeOut=timeout) == 1: return True else: return False def __change_language_context(self, language): try: f = open(os.path.join(os.path.dirname(__file__), 'context', language), 'r') except Exception as e: f = open("/tmp/log", "w") f.write(" ".join(dir(e))) f.write(e.strerror) f.close() raise e self.context = json.load(f) f.close() def chage_language(self, language): language_map = {'valencian': {'index': 38, 'value': ''}, 'spanish': {'index': 9, 'value': ''}, 'catala': {'index': 3, 'value': ''}} if not language_map.has_key(language): return False value = ldtp.getcellvalue(self.appname, self.context['languageselector'], language_map[language]['index']) self.__change_language_context(language) return True def error(self): print "error" sys.exit(1) def test_install(self, language, user_info): self.enable_accesiblity() time.sleep(2) self.start_app() self.chage_language(self.language) ldtp.click(self.appname, self.context['next']) if not self.waitstate(self.context['installsoftwarethird'], state=ldtp.state.SHOWING): self.error() ldtp.click(self.appname, self.context['next']) if not self.waitstate(self.context['manualformat'], state=ldtp.state.SHOWING): self.error() ldtp.click(self.appname, self.context['deletewindowsandreplacewithubuntu']) ldtp.click(self.appname, self.context['next']) if not self.waitstate(self.context['installnow'], state=ldtp.state.SHOWING): self.error() ldtp.click(self.appname, self.context['installnow']) #self.context['location'] = 'txt2' if not self.waitstate(self.context['location'], state=ldtp.state.SHOWING): self.error() ldtp.settextvalue(self.appname, self.context['location'], 'Madrid') ldtp.click(self.appname, self.context['next']) #self.context['checkkeyboard'] == 'txt3' if not self.waitstate(self.context['checkkeyboard'], state=ldtp.state.SHOWING): self.error() ldtp.click(self.appname, self.context['next']) if not self.waitstate(self.context['username'], state=ldtp.state.SHOWING): self.error() ldtp.settextvalue(self.appname, self.context['username'], user_info['username']) ldtp.settextvalue(self.appname, self.context['hostname'], user_info['hostname']) ldtp.settextvalue(self.appname, self.context['login'], user_info['login']) ldtp.settextvalue(self.appname, self.context['password'], user_info['password']) ldtp.settextvalue(self.appname, self.context['confirmpassword'], user_info['password']) if user_info['autologin']: ldtp.click(self.appname, self.context['autologin']) else: ldtp.click(self.appname, self.context['requirepassword']) ldtp.click(self.appname, self.context['next'])