How to use obter_texto method in SeleniumBase

Best Python code snippet using SeleniumBase

permission.py

Source:permission.py Github

copy

Full Screen

...8# - Validar duplicidade de permissão em um mesmo grupo9# - Colocar uma opção force para efetuar as operações indepente das Warnings10from xml.dom import minidom11from os.path import isfile12def obter_texto(node_list):13 rc = ""14 for node in node_list:15 if node.nodeType == node.TEXT_NODE:16 rc = rc + node.data17 return rc18def obter_por_nome_tag(node_list, tagName):19 for node in node_list:20 if node.nodeType == node.ELEMENT_NODE and node.tagName == tagName:21 return node22 return None23 24class App:25 def __init__(self, nome=None):26 self.nome = nome27 self.grupos = {}28 29class Grupo:30 def __init__(self, nome=None, app=None):31 self.nome = nome32 self.app = app33 self.permissoes = []34 35class Permissao:36 def __init__(self, model_app, model_name, permission_name):37 self.nome = u"%s.%s.%s" % (model_app, model_name, permission_name)38 39class GroupPermission:40 def __init__(self):41 self.apps = {}42 self.nomes_grupo = {}43 def processar(self, nome_arquivo_permissao, current_app):44 dom = minidom.parse(nome_arquivo_permissao).documentElement45 permissoes = []46 # Start process permission file47 for group in dom.getElementsByTagName("group"):48 group_names = obter_texto(group.getElementsByTagName("name")[0].childNodes).split(';')49 # Se tiver a tag app do grupo50 group_app_tag = obter_por_nome_tag(group.childNodes, 'app')51 if group_app_tag:52 group_names_app = (obter_texto(obter_por_nome_tag(group.childNodes, 'app').childNodes) or current_app).split(';')53 54 # se não tiver a mesma quantidade55 if len(group_names) != len(group_names_app):56 raise Exception('In %s/permission.xml group name %s or apps %s has no app correctly defined' % (current_app, group_names, group_names_app))57 58 for index, group_name in enumerate(group_names):59 group_name = group_name.strip()60 61 # Caso não tenha definito a app, a app defaul será a do permissions.xml 62 group_app = current_app63 if group_app_tag:64 group_app = group_names_app[index].strip()65 66 if group_name in self.nomes_grupo and self.nomes_grupo[group_name].app != group_app:67 raise Exception('In %s/permission.xml group name %s has been defined in module %s' % (current_app, group_names, self.nomes_grupo[group_name].app))68 69 # se já estiver adicionado recupere 70 if group_app in self.apps:71 app = self.apps[group_app]72 else:73 # se não, crie e já adicione74 app = App(group_app)75 self.apps[group_app] = app76 77 # se já estiver adicionado recupere 78 if group_name in app.grupos:79 grupo = app.grupos[group_name]80 else:81 # se não, crie e já adicione82 grupo = Grupo(group_name, group_app)83 app.grupos[group_name] = grupo84 self.nomes_grupo[group_name] = grupo85 86 87 tags_models = group.getElementsByTagName("models")88 tags_model = group.getElementsByTagName("model")89 90 if tags_models.length > 1:91 raise Exception(to_ascii(u'Nao deve haver mais de uma tag models em uma tag group => %s[%s]' % (nome_arquivo_permissao, group_name)))92 elif tags_models.length == 1:93 if tags_model.length == 0:94 raise Exception(to_ascii(u'Deve haver ao menos de uma tag model em uma tag models => %s[%s]' % (nome_arquivo_permissao, group_name)))95 elif tags_models.length == 0:96 if tags_model.length != 0:97 raise Exception(to_ascii(u'A tag model deve estar em uma tag models => %s[%s]' % (nome_arquivo_permissao, group_name)))98 99 # Process permissions100 for model in tags_model:101 model_app = obter_texto(model.getElementsByTagName("app")[0].childNodes)102 model_name = obter_texto(model.getElementsByTagName("name")[0].childNodes)103 for permission in model.getElementsByTagName("permission"):104 permission_name = obter_texto(permission.childNodes)105 permissao = Permissao(model_app, model_name, permission_name)106 grupo.permissoes.append(permissao)107 permissoes.append(permissao.nome)108 return permissoes109 110 def obter_grupos(self):111 retorno = []112 for app in self.apps.values():113 for grupo in app.grupos.values():114 retorno.append(grupo)115 116 return retorno117 118 def obter_dicionario(self):119 retorno = {}120 for grupo in self.obter_grupos():121 nome_grupo = grupo.nome122 retorno[nome_grupo] = []123 for permissao in grupo.permissoes:124 retorno[nome_grupo].append(permissao.nome)125 126 return retorno127 128 @classmethod129 def obter_grupos_por_app(cls, app):130 groups = set()131 permission_file_name = '%s/permissions.xml' % app132 if isfile(permission_file_name):133 dom = minidom.parse(permission_file_name).documentElement134 135 for group in dom.getElementsByTagName("group"):136 group_names = obter_texto(group.getElementsByTagName("name")[0].childNodes).split(';')137 # Se tiver a tag app do grupo138 group_app_tag = obter_por_nome_tag(group.childNodes, 'app')139 if group_app_tag:140 group_names_app = (obter_texto(obter_por_nome_tag(group.childNodes, 'app').childNodes) or app).split(';')141 # se não tiver a mesma quantidade142 if len(group_names) != len(group_names_app):143 raise Exception('In %s/permission.xml group name %s has no app correctly defined' % (app, group_names))144 145 for index, group_name in enumerate(group_names):146 group_name = group_name.strip()147 group_app = app148 if group_app_tag:149 group_app = group_names_app[index].strip()150 151 if group_app == app:152 groups.add(group_name)153 154 return groups...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run SeleniumBase automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful