appium_failure_helper 0.2.0 → 0.3.1

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: f76409f1b9c5f4bd448918dd57bcf691b317f2e9f8e49fdc077fb051b731c9c2
4
+ data.tar.gz: c38273c8afae6609ca72a3a0fdea5713ca3d358f1d0ee50a562f9d9cff9d62bf
5
5
  SHA512:
6
- metadata.gz: b29a72379bebe025aee27dff7468de7dbaaa68a42f340eb090acecc472ff4a161fd598ea979852ca735b22e6187dd439bc453448b0f7647bc6f927edf7663934
7
- data.tar.gz: 60b1df4b0c0fbd0ba35e6a761069cc7eb36db0ae961a8c718f77beea616a7a69b5f4817090e5e6ef98f56de3067e5cd115d4c353c3df1ca621d3e9a78a022174
6
+ metadata.gz: e7824f6860fb399ff2d735f410e779f1cc93582131e5ab5672eff5f85f8f0d5c8bfb3c434defa92de4aea24ec75714b3f7920cb7c500d7a48d81612b30fda052
7
+ data.tar.gz: 7761f6376e1f9a2b284a6df260873af206ac550fa9374676eb1673e4fa2abf448deab8f4529e22d1c1b168c044d0486b548b1aba64e79f2e56199d7a183374a1
data/LICENSE.txt CHANGED
@@ -1,21 +1,21 @@
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.
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 CHANGED
@@ -1,62 +1,62 @@
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
-
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
62
  O arquivo `.yaml` é um recurso valioso para inspecionar os elementos da tela e atualizar seus localizadores de forma eficiente.
data/Rakefile CHANGED
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- task default: %i[]
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
@@ -9,9 +9,6 @@ module AppiumFailureHelper
9
9
  timestamp = Time.now.strftime('%Y%m%d_%H%M%S')
10
10
  folder_path = "screenshots"
11
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
12
  FileUtils.mkdir_p(folder_path)
16
13
 
17
14
  screenshot_path = "#{folder_path}/screenshot_#{timestamp}.png"
@@ -36,32 +33,14 @@ module AppiumFailureHelper
36
33
  'Switch' => 'switch',
37
34
  }
38
35
 
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
36
  line = doc.xpath('//*').map do |node|
61
37
  next if node.name == 'hierarchy'
62
38
  attrs = node.attributes.transform_values(&:value)
63
- name = suggest_name(node.name, attrs, prefix)
64
- xpath = xpath_generator(node.name, attrs)
39
+
40
+ # Os métodos agora estão no escopo correto.
41
+ name = self.suggest_name(node.name, attrs, prefix)
42
+ xpath = self.xpath_generator(node.name, attrs)
43
+
65
44
  "[\"#{name}\", \"xpath\", \"#{xpath}\"]"
66
45
  end
67
46
 
@@ -73,5 +52,29 @@ module AppiumFailureHelper
73
52
  puts "Error capturing failure details: #{e.message}"
74
53
  end
75
54
  end
55
+
56
+ private
57
+
58
+ # Mova os métodos para cá.
59
+ def self.suggest_name(tag, attrs, prefix)
60
+ type = tag.split('.').last
61
+ pfx = prefix[type] || 'elm'
62
+ name = attrs['content-desc'] || attrs['text'] || attrs['resource-id'] || 'unknown' || type
63
+ name = name.strip.gsub(/[^0-9a-z]/, '').split.map(&:capitalize).join
64
+ "#{pfx}#{name}"
65
+ end
66
+
67
+ def self.xpath_generator(tag, attrs)
68
+ type = tag.split('.').last
69
+ if attrs['resource-id'] && !attrs['resource-id'].empty?
70
+ "//*[@resource-id='#{attrs['resource-id']}']"
71
+ elsif attrs['content-desc'] && !attrs['content-desc'].empty?
72
+ "//*[@content-desc='#{attrs['content-desc']}']"
73
+ elsif attrs['text'] && !attrs['text'].empty?
74
+ "//*[@text='#{attrs['text']}']"
75
+ else
76
+ "//#{type}"
77
+ end
78
+ end
76
79
  end
77
- end
80
+ end
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
-
3
- module AppiumFailureHelper
4
- VERSION = "0.2.0"
5
- end
1
+ # frozen_string_literal: true
2
+
3
+ module AppiumFailureHelper
4
+ VERSION = "0.3.1"
5
+ end
@@ -1,8 +1,8 @@
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
+ # 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 +1,4 @@
1
- module AppiumFailureHelper
2
- VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
- end
1
+ module AppiumFailureHelper
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
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.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Nascimento
@@ -9,7 +9,77 @@ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
11
  date: 2025-09-23 00:00:00.000000000 Z
12
- dependencies: []
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: appium_lib
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '13.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '13.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
13
83
  description: Appium Failure Helper is a Ruby gem that provides utilities to capture
14
84
  failures during Appium test executions. It extracts and saves relevant information
15
85
  from the page source, including screenshots and element details, to aid in debugging