appium_failure_helper 0.1.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 +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +62 -0
- data/Rakefile +4 -0
- data/lib/appium_failure_helper/capture.rb +77 -0
- data/lib/appium_failure_helper/version.rb +5 -0
- data/lib/appium_failure_helper.rb +8 -0
- data/sig/appium_failure_helper.rbs +4 -0
- metadata +54 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7d0e003d2181e4acd5e7a6b8800050ed5d4b58ba8f2b1b6bad77f44f5c952c39
|
4
|
+
data.tar.gz: 14c6708100bb1f3651bcdaae8576459637b87b3bbf9cb6f19e8bf3a8cf29fafc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 67f9453d58528ee83c56ad0da163256ca850c70c68490515b5ce837089aba77849dde082016c382ac7c6bb38fe520f42b4f495c9efa946a4e36d82b42958bc1d
|
7
|
+
data.tar.gz: '0477783e4d83ad5590634bcb3379f332d371426f5c10a52a49b2774a104669c63491ad5920b4d9fe5de6a1e812262d7e01de07cce0175d1f439c9d296308fa5e'
|
data/LICENSE.txt
ADDED
@@ -0,0 +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.
|
data/README.md
ADDED
@@ -0,0 +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
|
+
|
62
|
+
O arquivo `.yaml` é um recurso valioso para inspecionar os elementos da tela e atualizar seus localizadores de forma eficiente.
|
data/Rakefile
ADDED
@@ -0,0 +1,77 @@
|
|
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
|
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: appium_failure_helper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Nascimento
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-09-23 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Appium Failure Helper is a Ruby gem that provides utilities to capture
|
14
|
+
failures during Appium test executions. It extracts and saves relevant information
|
15
|
+
from the page source, including screenshots and element details, to aid in debugging
|
16
|
+
and analysis.
|
17
|
+
email:
|
18
|
+
- halison700@gmail.com
|
19
|
+
executables: []
|
20
|
+
extensions: []
|
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
|
30
|
+
homepage: https://github.com/David-Nascimento/Appium_failure_helper
|
31
|
+
licenses:
|
32
|
+
- MIT
|
33
|
+
metadata: {}
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 3.1.0
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirements: []
|
49
|
+
rubygems_version: 3.3.27
|
50
|
+
signing_key:
|
51
|
+
specification_version: 4
|
52
|
+
summary: Helper to capture Appium failure and extract elements information from page
|
53
|
+
source
|
54
|
+
test_files: []
|