appium_failure_helper 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4801975d902d4f0a6877d409f7989c7c80581a10899615e34c53fff35052518b
4
- data.tar.gz: cd1a18c7941c603ed9c0055fb87c28ca55fbd702a38996ff2613edce6f347780
3
+ metadata.gz: 66dfd4d6024854d753fb469992d9d5ceacdceca467713f0c7ec7414c67c62acc
4
+ data.tar.gz: 378c3e552e1121c1634f12e22303d2194c85f6604663af6f3eeea1b0fe1092ea
5
5
  SHA512:
6
- metadata.gz: b29a72379bebe025aee27dff7468de7dbaaa68a42f340eb090acecc472ff4a161fd598ea979852ca735b22e6187dd439bc453448b0f7647bc6f927edf7663934
7
- data.tar.gz: 60b1df4b0c0fbd0ba35e6a761069cc7eb36db0ae961a8c718f77beea616a7a69b5f4817090e5e6ef98f56de3067e5cd115d4c353c3df1ca621d3e9a78a022174
6
+ metadata.gz: 3725621316aec82bd374867a5ac36243b79593a0a32d9f60427032de427ae7d3764aa7460f3574480cd383a5e26acd8eb54844950ee935fd2beb447328d78b3f
7
+ data.tar.gz: 7c62240e427a0d612f10d6a7c2ec16d397307230a6295af6102d4eba4d41f457f22e9cc9b7347c6c52a569446829ca355a2f7d900af3e7c99fec59f0b08588c9
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appium_failure_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Nascimento
@@ -19,14 +19,7 @@ email:
19
19
  executables: []
20
20
  extensions: []
21
21
  extra_rdoc_files: []
22
- files:
23
- - LICENSE.txt
24
- - README.md
25
- - Rakefile
26
- - lib/appium_failure_helper.rb
27
- - lib/appium_failure_helper/capture.rb
28
- - lib/appium_failure_helper/version.rb
29
- - sig/appium_failure_helper.rbs
22
+ files: []
30
23
  homepage: https://github.com/David-Nascimento/Appium_failure_helper
31
24
  licenses:
32
25
  - MIT
data/LICENSE.txt DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2025 David Nascimento
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
data/README.md DELETED
@@ -1,62 +0,0 @@
1
- # Appium Failure Helper
2
-
3
- Este módulo Ruby foi projetado para auxiliar na **análise de falhas em testes de automação Appium**. Ao ser invocado, ele captura o estado da aplicação no momento da falha e gera um conjunto de artefatos de diagnóstico, facilitando a identificação da causa raiz do problema e a sugestão de novos localizadores de elementos.
4
-
5
- ## Funcionalidades Principais
6
-
7
- * **Captura de Screenshot:** Salva uma imagem PNG da tela do dispositivo no momento da falha.
8
-
9
- * **Captura de Page Source:** Salva o XML do `page_source` completo, representando a hierarquia de elementos da tela.
10
-
11
- * **Geração de Sugestões de Elementos:** Analisa o `page_source` e gera um arquivo `.yaml` com sugestões de nomes e caminhos XPath para os elementos visíveis na tela.
12
-
13
- ## Como Funciona
14
-
15
- A lógica central do módulo `AppiumFailureHelper` é acionada por um evento de falha no seu framework de testes (ex: Cucumber `After` hook). A função `handler_failure` executa as seguintes etapas:
16
-
17
- 1. **Criação de Diretório:** Garante que a pasta `screenshots/` exista para armazenar os artefatos.
18
-
19
- 2. **Captura de Screenshot e Page Source:** Utiliza o driver do Appium para obter o screenshot e o XML do `page_source`, salvando-os com um timestamp para evitar sobrescrever arquivos.
20
-
21
- 3. **Análise com Nokogiri:** O XML do `page_source` é parseado utilizando a gem `Nokogiri`.
22
-
23
- 4. **Processamento de Elementos:** O código itera sobre cada nó do XML (exceto o nó raiz 'hierarchy') e extrai atributos-chave como `resource-id`, `content-desc` e `text`.
24
-
25
- 5. **Geração de Nomes e XPath:**
26
-
27
- * `suggest_name`: Constrói um nome descritivo para cada elemento, utilizando prefixos comuns (`btn`, `txt`, `input`, etc.) e o valor dos atributos principais.
28
-
29
- * `xpath_generator`: Prioriza atributos mais confiáveis (`resource-id`, `content-desc`, `text`) para gerar um XPath robusto.
30
-
31
- 6. **Saída Final:** O resultado é um arquivo `.yaml` contendo uma lista formatada de sugestões de locators no formato `["nome_sugerido", "xpath", "caminho_xpath"]`.
32
-
33
- ## Uso
34
-
35
- Para usar este helper, integre-o ao seu framework de testes. Um exemplo comum é utilizá-lo em um hook `After` do Cucumber:
36
-
37
- **`features/support/hooks.rb`**
38
-
39
- ```
40
- require 'caminho/para/o/seu/modulo' # Ajuste o caminho
41
-
42
- After do |scenario|
43
- if scenario.failed?
44
- AppiumFailureHelper::Capture.handler_failure(appium_driver)
45
- end
46
- end
47
-
48
- ```
49
-
50
- **Observação:** O nome da sua variável de driver pode variar. No exemplo, `appium_driver` deve ser o objeto de driver do seu teste.
51
-
52
- ## Artefatos Gerados
53
-
54
- Após uma falha, os seguintes arquivos serão gerados na pasta `screenshots/`:
55
-
56
- * `screenshot_20231027_153045.png`
57
-
58
- * `page_source_20231027_153045.xml`
59
-
60
- * `element_suggestions_20231027_153045.yaml`
61
-
62
- O arquivo `.yaml` é um recurso valioso para inspecionar os elementos da tela e atualizar seus localizadores de forma eficiente.
data/Rakefile DELETED
@@ -1,4 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- task default: %i[]
@@ -1,77 +0,0 @@
1
- require 'nokogiri'
2
- require 'fileutils'
3
- require 'base64'
4
-
5
- module AppiumFailureHelper
6
- class Capture
7
- def self.handler_failure(driver)
8
- begin
9
- timestamp = Time.now.strftime('%Y%m%d_%H%M%S')
10
- folder_path = "screenshots"
11
-
12
- # Lógica melhorada para criar a pasta.
13
- # O método mkdir_p cria a pasta apenas se ela não existir,
14
- # tornando a verificação Dir.exist? desnecessária.
15
- FileUtils.mkdir_p(folder_path)
16
-
17
- screenshot_path = "#{folder_path}/screenshot_#{timestamp}.png"
18
- File.open(screenshot_path, 'wb') do |f|
19
- f.write(Base64.decode64(driver.screenshot_as(:base64)))
20
- end
21
- puts "Screenshot saved to #{screenshot_path}"
22
-
23
- page_source = driver.page_source
24
- xml_path = "#{folder_path}/page_source_#{timestamp}.xml"
25
- File.write(xml_path, page_source)
26
-
27
- doc = Nokogiri::XML(page_source)
28
-
29
- prefix = {
30
- 'Button' => 'btn',
31
- 'TextView' => 'txt',
32
- 'ImageView' => 'img',
33
- 'EditText' => 'input',
34
- 'CheckBox' => 'chk',
35
- 'RadioButton' => 'radio',
36
- 'Switch' => 'switch',
37
- }
38
-
39
- def suggest_name(tag, attrs, prefix)
40
- type = tag.split('.').last
41
- pfx = prefix[type] || 'elm'
42
- name = attrs['content-desc'] || attrs['text'] || attrs['resource-id'] || 'unknown' || type
43
- name = name.strip.gsub(/[^0-9a-z]/, '').split.map(&:capitalize).join
44
- "#{pfx}#{name}"
45
- end
46
-
47
- def xpath_generator(tag, attrs)
48
- type = tag.split('.').last
49
- if attrs['resource-id'] && !attrs['resource-id'].empty?
50
- "//*[@resource-id='#{attrs['resource-id']}']"
51
- elsif attrs['content-desc'] && !attrs['content-desc'].empty?
52
- "//*[@content-desc='#{attrs['content-desc']}']"
53
- elsif attrs['text'] && !attrs['text'].empty?
54
- "//*[@text='#{attrs['text']}']"
55
- else
56
- "//#{type}"
57
- end
58
- end
59
-
60
- line = doc.xpath('//*').map do |node|
61
- next if node.name == 'hierarchy'
62
- attrs = node.attributes.transform_values(&:value)
63
- name = suggest_name(node.name, attrs, prefix)
64
- xpath = xpath_generator(node.name, attrs)
65
- "[\"#{name}\", \"xpath\", \"#{xpath}\"]"
66
- end
67
-
68
- yaml_path = "#{folder_path}/element_suggestions_#{timestamp}.yaml"
69
- File.open(yaml_path, 'w') {|f| f.puts(line.compact.join("\n"))}
70
-
71
- puts "Element suggestions saved to #{yaml_path}"
72
- rescue => e
73
- puts "Error capturing failure details: #{e.message}"
74
- end
75
- end
76
- end
77
- end
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module AppiumFailureHelper
4
- VERSION = "0.2.0"
5
- end
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "appium_failure_helper/version"
4
- require_relative "appium_failure_helper/capture"
5
- module AppiumFailureHelper
6
- class Error < StandardError; end
7
- # Your code goes here...
8
- end
@@ -1,4 +0,0 @@
1
- module AppiumFailureHelper
2
- VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
- end