https://github.com/rezapace/parent-axes
Parent-Axes
https://github.com/rezapace/parent-axes
Last synced: 12 months ago
JSON representation
Parent-Axes
- Host: GitHub
- URL: https://github.com/rezapace/parent-axes
- Owner: rezapace
- Created: 2025-07-23T02:57:34.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2025-07-23T03:00:14.000Z (about 1 year ago)
- Last Synced: 2025-07-23T05:12:49.048Z (about 1 year ago)
- Language: Go
- Size: 19.1 MB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ๐ฏ XPath Generator - Preceding/Following Specialist
## ๐ Deskripsi
XPath Generator adalah aplikasi web canggih yang dirancang khusus untuk menghasilkan pattern XPath yang fokus pada navigasi **Preceding** dan **Following** untuk testing iOS dan Android. Aplikasi ini sangat berguna untuk automation testing yang memerlukan navigasi element berdasarkan posisi relatif dalam DOM structure.
## ๐ฌ Demo

*Demo penggunaan XPath Generator untuk menganalisis XML dan menghasilkan pattern navigation*
## โจ Fitur Utama
- ๐ **XML Analysis**: Parsing dan analisis struktur XML secara mendalam
- ๐ฏ **Advanced Pattern Generation**: Menghasilkan berbagai pattern XPath dengan confidence rating
- ๐ฑ **iOS/Android Support**: Konversi otomatis ke Groovy constants untuk testing framework
- ๐ **Statistics & Analytics**: Laporan statistik lengkap tentang struktur XML
- ๐จ **Modern UI**: Interface yang responsive dan user-friendly
- ๐ **Copy to Clipboard**: One-click copy untuk semua pattern yang dihasilkan
## ๐ Cara Menjalankan
```bash
# Clone repository
git clone
cd precidingsiblinggenerator
# Build aplikasi
go build -o xpath_generator main.go
# Jalankan aplikasi
./xpath_generator
```
Aplikasi akan berjalan di `http://localhost:8080`
## ๐ Pattern XPath Navigation
### 1. ๐ **Preceding**
**Preceding** mengacu pada semua element yang muncul **sebelum** element saat ini dalam document order (urutan dokumen).
#### Karakteristik:
- Mencakup semua element yang telah diproses sebelum element target
- Tidak terbatas pada sibling, tetapi seluruh dokumen
- Urutan berdasarkan document order, bukan tree hierarchy
#### Contoh Pattern:
```xpath
// Basic preceding
${element.xpath}/preceding::*[1]
// Preceding by type
${element.xpath}/preceding::XCUIElementTypeButton[1]
// Preceding with condition
${element.xpath}/preceding::*[@name='Login'][1]
```
#### Use Cases:
- โ
Mencari label atau instruksi yang muncul sebelum form field
- โ
Navigasi ke element yang sudah diproses sebelumnya
- โ
Validasi sequence dalam workflow
#### ๐ฏ Kapan Menggunakan Preceding:
- **Form Validation**: Ketika perlu mencari error message yang muncul sebelum input field
- **Navigation Flow**: Untuk kembali ke step sebelumnya dalam multi-step form
- **Context Reference**: Mencari heading atau label yang memberikan context untuk element saat ini
- **Sequential Testing**: Validasi bahwa element muncul dalam urutan yang benar
**Contoh Real Case**:
```groovy
// Mencari error message yang muncul sebelum password field
def errorMsg = driver.findElement(By.xpath("${passwordField.xpath}/preceding::*[contains(text(),'Password required')][1]"))
```
---
### 2. โฌ
๏ธ **Preceding Sibling**
**Preceding Sibling** mengacu pada element yang memiliki **parent yang sama** dan muncul **sebelum** element saat ini.
#### Karakteristik:
- Hanya element dengan parent yang sama (sibling)
- Lebih spesifik dan terbatas dibanding preceding
- Ideal untuk navigasi dalam container yang sama
#### Contoh Pattern:
```xpath
// Immediate preceding sibling
${element.xpath}/preceding-sibling::*[1]
// Preceding sibling by type
${element.xpath}/preceding-sibling::XCUIElementTypeTextField[1]
// All preceding siblings
${element.xpath}/preceding-sibling::*
```
#### Use Cases:
- โ
Navigasi antar field dalam form yang sama
- โ
Mencari element sebelumnya dalam list atau menu
- โ
Validasi urutan element dalam container
#### ๐ฏ Kapan Menggunakan Preceding Sibling:
- **Form Navigation**: Berpindah dari field saat ini ke field sebelumnya dalam form
- **List Item Selection**: Memilih item sebelumnya dalam list atau menu dropdown
- **Tab Navigation**: Navigasi ke tab sebelumnya dalam tab container
- **Button Grouping**: Mencari tombol yang berdekatan dalam button group
**Contoh Real Case**:
```groovy
// Klik tombol "Previous" yang berada sebelum tombol "Next"
def previousBtn = driver.findElement(By.xpath("${nextButton.xpath}/preceding-sibling::*[contains(@name,'Previous')][1]"))
previousBtn.click()
```
#### ๐ง Perbedaan Preceding vs Preceding Sibling:
| Aspect | Preceding | Preceding Sibling |
|--------|-----------|-------------------|
| **Scope** | Seluruh dokumen | Hanya sibling dalam parent yang sama |
| **Performance** | Lebih lambat | Lebih cepat |
| **Precision** | Lebih luas | Lebih spesifik |
| **Use Case** | Cross-container navigation | Same-container navigation |
---
### 3. ๐ **Following**
**Following** mengacu pada semua element yang muncul **setelah** element saat ini dalam document order.
#### Karakteristik:
- Mencakup semua element yang akan diproses setelah element target
- Tidak terbatas pada sibling, tetapi seluruh dokumen
- Berguna untuk navigasi forward dalam workflow
#### Contoh Pattern:
```xpath
// Basic following
${element.xpath}/following::*[1]
// Following by type
${element.xpath}/following::XCUIElementTypeButton[1]
// Following with condition
${element.xpath}/following::*[text()='Submit'][1]
```
#### Use Cases:
- โ
Navigasi ke step selanjutnya dalam wizard
- โ
Mencari element konfirmasi setelah input
- โ
Validasi element yang muncul setelah action
#### ๐ฏ Kapan Menggunakan Following:
- **Wizard Navigation**: Melanjutkan ke step berikutnya setelah mengisi form
- **Confirmation Check**: Mencari pesan konfirmasi yang muncul setelah submit
- **Dynamic Content**: Menunggu element yang muncul setelah loading atau action
- **Validation Messages**: Mencari success/error message yang muncul setelah form submission
**Contoh Real Case**:
```groovy
// Mencari success message yang muncul setelah login form
def successMsg = driver.findElement(By.xpath("${loginForm.xpath}/following::*[contains(text(),'Login successful')][1]"))
assert successMsg.isDisplayed()
```
---
### 4. โก๏ธ **Following Sibling**
**Following Sibling** mengacu pada element yang memiliki **parent yang sama** dan muncul **setelah** element saat ini.
#### Karakteristik:
- Hanya element dengan parent yang sama (sibling)
- Lebih spesifik dan terbatas dibanding following
- Ideal untuk navigasi sequential dalam container
#### Contoh Pattern:
```xpath
// Immediate following sibling
${element.xpath}/following-sibling::*[1]
// Following sibling by type
${element.xpath}/following-sibling::XCUIElementTypeButton[1]
// All following siblings
${element.xpath}/following-sibling::*
```
#### Use Cases:
- โ
Navigasi ke field berikutnya dalam form
- โ
Mencari tombol action setelah input field
- โ
Validasi sequence dalam list item
#### ๐ฏ Kapan Menggunakan Following Sibling:
- **Sequential Form Filling**: Berpindah ke field berikutnya setelah mengisi field saat ini
- **Action Button Location**: Mencari tombol submit/save yang berada setelah input field
- **List Navigation**: Navigasi ke item berikutnya dalam list yang sama
- **Related Controls**: Mencari control yang berhubungan langsung (checkbox setelah label)
**Contoh Real Case**:
```groovy
// Setelah mengisi username, lanjut ke password field
def passwordField = driver.findElement(By.xpath("${usernameField.xpath}/following-sibling::*[@type='password'][1]"))
passwordField.sendKeys("mypassword")
```
#### ๐ง Perbedaan Following vs Following Sibling:
| Aspect | Following | Following Sibling |
|--------|-----------|-------------------|
| **Timing** | Setelah action/loading | Immediate navigation |
| **Context** | Document-wide search | Container-specific |
| **Reliability** | Depends on timing | More predictable |
| **Speed** | Slower (broader search) | Faster (limited scope) |
---
### 5. ๐ฏ **Last**
**Last** mengacu pada element **terakhir** dari jenis tertentu dalam dokumen atau context tertentu.
#### Karakteristik:
- Menggunakan XPath function `last()`
- Berguna untuk menemukan element final dalam list
- Dapat dikombinasikan dengan condition untuk specificity
#### Contoh Pattern:
```xpath
// Last element of type
(//${IOS_TYPE_BUTTON})[last()]
// Last with condition
(//${IOS_TYPE_CELL}[@name='Item'])[last()]
// Last in parent context
(${parent.xpath}/${IOS_TYPE_TEXTFIELD})[last()]
```
#### Use Cases:
- โ
Scroll ke item terakhir dalam list
- โ
Navigasi ke footer element
- โ
Validasi element terakhir yang ditambahkan
#### ๐ฏ Kapan Menggunakan Last:
- **List Operations**: Scroll ke bottom untuk melihat item terbaru atau terakhir
- **Data Validation**: Memverifikasi bahwa item baru ditambahkan di akhir list
- **Navigation to End**: Langsung ke element terakhir tanpa iterasi
- **Form Completion**: Mencari tombol submit yang biasanya di akhir form
**Contoh Real Case**:
```groovy
// Scroll ke item terakhir dalam shopping cart untuk melihat total
def lastItem = driver.findElement(By.xpath("(//XCUIElementTypeCell)[last()]"))
def totalPrice = driver.findElement(By.xpath("(//XCUIElementTypeStaticText[contains(@name,'Total')])[last()]"))
```
#### ๐ฏ Advanced Last Pattern Usage:
- **`[last()]`**: Element terakhir dari type tertentu
- **`[last()-1]`**: Element kedua dari akhir
- **`[position()=last()]`**: Sama dengan `[last()]` tapi lebih eksplisit
- **`[last()][contains(@name,'Submit')]`**: Element terakhir dengan kondisi tertentu
**Performance Tips**:
- โ
`last()` lebih cepat dari iterasi manual
- โ
Kombinasikan dengan type selector untuk precision
- โ
Gunakan parent context untuk scope yang lebih sempit
---
---
## ๐ฏ Decision Matrix: Kapan Menggunakan Pattern Mana?
### ๐ Quick Reference Guide
| Scenario | Pattern | Why | Example |
|----------|---------|-----|---------|
| **Form field โ next field** | Following Sibling | Same container, predictable | Username โ Password |
| **Form field โ previous field** | Preceding Sibling | Same container, rollback | Password โ Username |
| **After submit โ success message** | Following | Cross-container, timing-based | Form โ Confirmation |
| **Error state โ related field** | Preceding | Context lookup | Error โ Input field |
| **Navigate to end of list** | Last | Direct access, no iteration | โ Bottom item |
### ๐ฆ Decision Tree
```
Need to navigate from current element?
โ
โโ YES โ Where to go?
โ โ
โ โโ Same container (parent)?
โ โ โโ Previous element โ Use PRECEDING SIBLING
โ โ โโ Next element โ Use FOLLOWING SIBLING
โ โ
โ โโ Different container?
โ โ โโ Before current โ Use PRECEDING
โ โ โโ After current โ Use FOLLOWING
โ โ
โ โโ Final element of type?
โ โโ Use LAST
โ
โโ NO โ Use standard locator patterns
```
### โก Performance Comparison
| Pattern | Speed | Reliability | Scope | Best For |
|---------|-------|-------------|-------|----------|
| **Preceding Sibling** | โกโกโกโกโก | โญโญโญโญโญ | Narrow | Form navigation |
| **Following Sibling** | โกโกโกโกโก | โญโญโญโญโญ | Narrow | Sequential flow |
| **Preceding** | โกโกโก | โญโญโญ | Wide | Context lookup |
| **Following** | โกโกโก | โญโญโญ | Wide | Result validation |
| **Last** | โกโกโกโก | โญโญโญโญ | Targeted | End navigation |
## ๐ Pattern Advanced
### Relative Patterns
Pattern yang menggunakan context relationship:
- **Parent-Child**: `${parent.xpath}/XCUIElementTypeButton`
- **Depth-based**: `//*[@depth='3']/XCUIElementTypeCell`
- **Index-based**: `(//XCUIElementTypeButton)[2]`
### Conditional Patterns
Pattern dengan kondisi spesifik:
- **Contains**: `//XCUIElementTypeButton[contains(@name, 'Save')]`
- **Starts-with**: `//XCUIElementTypeTextField[starts-with(@name, 'Input')]`
- **Position**: `//XCUIElementTypeCell[position()=2]`
## ๐ฑ iOS Testing Integration
Aplikasi ini secara otomatis mengkonversi element type ke Groovy constants:
```groovy
// iOS Element Types
XCUIElementTypeButton โ ${Constants.IOS_TYPE_BUTTON}
XCUIElementTypeTextField โ ${Constants.IOS_TYPE_TEXTFIELD}
XCUIElementTypeStaticText โ ${Constants.IOS_TYPE_STATIC_TEXT}
// iOS Attributes
@name โ @${Constants.IOS_ATTR_NAME}
@label โ @${Constants.IOS_ATTR_LABEL}
@value โ @${Constants.IOS_ATTR_VALUE}
```
## ๐ก Real-World Testing Examples
### ๐ Login Form Automation
```groovy
// Test flow: Username โ Password โ Login Button โ Success Message
class LoginTest {
def testLoginFlow() {
// Fill username
def usernameField = findElement("//XCUIElementTypeTextField[@name='username']")
usernameField.sendKeys("testuser")
// Navigate to password (following sibling)
def passwordField = findElement("${usernameField.xpath}/following-sibling::XCUIElementTypeSecureTextField[1]")
passwordField.sendKeys("password123")
// Find login button (following sibling)
def loginBtn = findElement("${passwordField.xpath}/following-sibling::XCUIElementTypeButton[1]")
loginBtn.click()
// Verify success message (following - cross container)
def successMsg = findElement("${loginBtn.xpath}/following::*[contains(@name,'Welcome')][1]")
assert successMsg.isDisplayed()
}
}
```
### ๐ Shopping Cart Operations
```groovy
// Navigate through cart items and validate total
class CartTest {
def testCartTotal() {
// Add items to cart first...
// Navigate to last item to see total
def lastCartItem = findElement("(//XCUIElementTypeCell[contains(@name,'cart-item')])[last()]")
// Find total price (following the last item)
def totalPrice = findElement("${lastCartItem.xpath}/following::*[contains(@name,'Total')][1]")
// Validate total is correct
assert totalPrice.text.contains("$99.99")
}
}
```
### ๐ Form Validation Testing
```groovy
// Test form validation messages
class FormValidationTest {
def testFieldValidation() {
def emailField = findElement("//XCUIElementTypeTextField[@name='email']")
emailField.sendKeys("invalid-email")
// Trigger validation
def submitBtn = findElement("//XCUIElementTypeButton[@name='submit']")
submitBtn.click()
// Find error message (typically appears after the field)
def errorMsg = findElement("${emailField.xpath}/following::*[contains(@name,'Invalid email')][1]")
assert errorMsg.isDisplayed()
// Or find error icon (typically preceding the field)
def errorIcon = findElement("${emailField.xpath}/preceding-sibling::*[@name='error-icon'][1]")
assert errorIcon.isDisplayed()
}
}
```
## ๐ค Android Testing Integration
Support untuk Android element types:
```groovy
// Android Element Types
android.widget.Button โ ${Constants.ANDROID_TYPE_BUTTON}
android.widget.TextView โ ${Constants.ANDROID_TYPE_TEXTVIEW}
android.widget.EditText โ ${Constants.ANDROID_TYPE_EDITTEXT}
// Android Attributes
@text โ @${Constants.ANDROID_ATTR_TEXT}
@content-desc โ @${Constants.ANDROID_ATTR_CONTENT_DESC}
@resource-id โ @${Constants.ANDROID_ATTR_RESOURCE_ID}
```
## ๐ Confidence Rating System
Setiap pattern dilengkapi dengan confidence rating (1-5 stars):
- โญ **1 Star**: Pattern umum, mungkin tidak stabil
- โญโญ **2 Stars**: Pattern cukup reliable
- โญโญโญ **3 Stars**: Pattern good, recommended untuk use case tertentu
- โญโญโญโญ **4 Stars**: Pattern very reliable, highly recommended
- โญโญโญโญโญ **5 Stars**: Pattern excellent, sangat stabil dan unique
## ๐จ UI Features
### Home Page
- ๐ **Statistics Dashboard**: Total elements, patterns generated, depth analysis
- ๐ **XML Input**: Paste dan analyze XML content
- ๐ท๏ธ **Element Cards**: Preview semua element dengan attributes
### Analysis Page
- ๐ **Element Details**: Informasi lengkap element yang dipilih
- ๐ **Pattern Categories**: Grouped by pattern type dengan color coding
- ๐ก **Use Cases**: Penjelasan kapan menggunakan setiap pattern
- ๐ท๏ธ **Test Object ID**: Suggested variable names untuk automation
- ๐ **One-Click Copy**: Copy pattern ke clipboard dengan hover effect
### Responsive Design
- ๐ฑ **Mobile Friendly**: Layout responsif untuk semua device
- ๐จ **Modern Styling**: Gradient backgrounds, hover effects, animations
- ๐ **Horizontal Scroll**: Auto scroll untuk pattern yang panjang
- ๐ฏ **Visual Indicators**: Color-coded patterns dan confidence badges
## ๐ ๏ธ Technical Stack
- **Backend**: Go (Golang) dengan standard library
- **Frontend**: HTML5, CSS3, Vanilla JavaScript
- **XML Processing**: Go xml package dengan custom parsing
- **Template Engine**: Go html/template
- **HTTP Server**: Go net/http
## ๐ Struktur Project
```
precidingsiblinggenerator/
โโโ main.go # Main application file
โโโ go.mod # Go module definition
โโโ README.md # Documentation
โโโ rule.md # iOS constants reference
โโโ xmlfiles/ # Sample XML files
โโโ login_2025-07-16_16-08-31_060030.xml
โโโ sample_ios.xml
```
## ๐ง Development
### Prerequisites
- Go 1.23.6 atau lebih baru
- Browser modern (Chrome, Firefox, Safari, Edge)
### Build & Run
```bash
# Development mode
go run main.go
# Production build
go build -o xpath_generator main.go
./xpath_generator
```
## ๏ฟฝ Troubleshooting & Best Practices
### โ Common Issues & Solutions
| Issue | Problem | Solution |
|-------|---------|----------|
| **Element not found** | Pattern too specific | Use broader pattern (preceding vs preceding-sibling) |
| **Multiple matches** | Pattern too generic | Add more specific conditions |
| **Timing issues** | Element not loaded yet | Use explicit waits with following patterns |
| **Performance slow** | Using preceding/following extensively | Prefer sibling patterns when possible |
### โ
Best Practices
#### ๐ฏ Pattern Selection Strategy
1. **Start Narrow**: Use sibling patterns first (faster, more reliable)
2. **Expand Scope**: Use preceding/following if sibling doesn't work
3. **Add Conditions**: Use attributes to make patterns more specific
4. **Test Stability**: Verify patterns work across different data sets
#### ๐ Performance Optimization
```groovy
// โ Slow - searches entire document
def element = findElement("//XCUIElementTypeButton/following::*[contains(@name,'Submit')]")
// โ
Fast - limited scope
def element = findElement("${formContainer.xpath}//XCUIElementTypeButton/following-sibling::*[contains(@name,'Submit')]")
```
#### ๐ Debugging Tips
1. **Use Browser Dev Tools**: Test XPath patterns in browser console
2. **Start Simple**: Begin with basic patterns, add complexity gradually
3. **Check Parent Context**: Ensure you're in the right container
4. **Validate Data**: Test with different data sets and UI states
## ๏ฟฝ๐ Referensi
- [XPath Specification](https://www.w3.org/TR/xpath/)
- [XCUITest Documentation](https://developer.apple.com/documentation/xctest)
- [UI Automator Documentation](https://developer.android.com/training/testing/ui-automator)
## ๐ค Contributing
Contributions welcome! Please read the contributing guidelines and submit pull requests untuk improvements.
## ๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
## ๐น Demo Video
Untuk melihat aplikasi dalam action, check out `demo.gif` yang menampilkan:
- โ
XML input dan parsing
- โ
Element selection dan analysis
- โ
Pattern generation dengan confidence ratings
- โ
Copy-to-clipboard functionality
- โ
Responsive design di berbagai ukuran layar
> **Note**: `demo.gif` file harus dibuat dengan screen recording dari aplikasi yang sedang berjalan untuk memberikan gambaran visual yang lengkap kepada users.
---
**Dibuat dengan โค๏ธ untuk iOS & Android Test Automation**