Bu belge, yapı, yetenekler, kullanım, kayıt ve eylemler dahil olmak üzere Robo betikleri hakkında referans bilgileri sağlar. Robo betikleri, mobil uygulamalar için manuel kalite güvencesi (QA) görevlerini otomatikleştiren ve sürekli entegrasyon (CI) ve lansman öncesi test stratejileri sağlayan testlerdir. Bir Robo betiği, bir kullanıcı arabirimi (UI) dizisini ve diğer eylemleri açıklayan bir JSON dosyasıdır.
Aşağıdaki şekillerde bir Robo betiği oluşturabilirsiniz:
- Robo komut dosyası kayıt özelliğini kullanın.
- Robo betiğini manuel olarak oluşturun.
- Robo komut dosyasını kaydedin ve ardından manuel olarak düzenleyin.
Robo betiklerini kullanma hakkında daha fazla bilgi edinmek için Robo betiği çalıştırma bölümüne bakın.
Robo komut dosyası, test edilen uygulama Android Uygulama Paketi (APK) gibi diğer girdilerin yanı sıra Robo testine sağlanır.
Aşağıda, bir kullanıcıyı bir uygulamaya imzalayan ve test edilen uygulama başlatıldığında tetiklenen bir Robo komut dosyası örneği verilmiştir:
[
{
"crawlStage": "crawl",
"contextDescriptor": {
"condition": "app_under_test_shown"
},
"actions": [
{
"eventType": "VIEW_TEXT_CHANGED",
"replacementText": "user123",
"elementDescriptors": [
{
"resourceId": "my.app.package:id/username"
}
]
},
{
"eventType": "VIEW_TEXT_CHANGED",
"replacementText": "12345",
"elementDescriptors": [
{
"resourceId": "my.app.package:id/password"
}
]
},
{
"eventType": "VIEW_CLICKED",
"elementDescriptors": [
{
"resourceId": "my.app.package:id/login"
}
]
}
]
}
]
Bir dosyada tek bir Robo komut dosyası varsa ve yukarıdaki örnekte olduğu gibi varsayılan app_under_test_shown
tetikleme koşuluna sahipse, Robo komut dosyasını daha basit bir biçim kullanarak bir dosyada belirtebilirsiniz - tıpkı eylemlerinin bir sırası gibi:
[
{
"eventType": "VIEW_TEXT_CHANGED",
"replacementText": "user123",
"elementDescriptors": [
{
"resourceId": "my.app.package:id/username"
}
]
},
{
"eventType": "VIEW_TEXT_CHANGED",
"replacementText": "12345",
"elementDescriptors": [
{
"resourceId": "my.app.package:id/password"
}
]
},
{
"eventType": "VIEW_CLICKED",
"elementDescriptors": [
{
"resourceId": "my.app.package:id/login"
}
]
}
]
Yapı
Bir Robo komut dosyasının, Robo'nun onu nasıl yürüttüğünü açıklayan çeşitli öznitelikleri vardır. Bu özniteliklerin çoğu, önceden tanımlanmış varsayılan değerlerle isteğe bağlıdır:
Bağlanmak | Tanım |
id | Tarama çıktılarında bu Robo komut dosyasının izlenmesine yardımcı olan bir tamsayı. |
description | id benzer, ancak daha açıklayıcıdır. |
crawlStage | Tarama Robo aşaması, bu Robo komut dosyasını şu adreste uygular: Varsayılan olarak, ana tarama aşamasıdır. |
priority | Bu Robo betiğinin diğer Robo betiklerine kıyasla önceliği. Varsayılan olarak, tüm Robo betiklerinin önceliği 1 . |
maxNumberOfRuns | Bir tarama sırasında Robo'nun bu Robo komut dosyasını kaç kez çalıştırabileceğini belirtir. Varsayılan olarak, Robo bir Robo komut dosyasını bir kez çalıştırabilir. |
contextDescriptor | Bu Robo komut dosyasını tetikleyen bağlamı/koşulu açıklar. Atlanırsa, bu Robo betiğinin tetikleme koşulunun her zaman karşılandığı kabul edilir; başka bir deyişle, Robo betiği koşulsuzdur. |
actions | Bu Robo betiğinin tüm eylemleri. |
Tek bir dosya, bir veya daha fazla Robo komut dosyası koleksiyonu içerir.
Aşağıda, her biri taramanın başlangıcında bir kez yürütülen tek bir eyleme sahip iki koşulsuz Robo komut dosyasına sahip bir dosya örneği verilmiştir:
[
{
"id": 1000,
"description": "My first Robo script",
"actions": [
{
"eventType": "DISABLE_KEYBOARD"
}
]
},
{
"id": 1001,
"description": "My second Robo script",
"actions": [
{
"eventType": "PRESSED_BACK"
}
]
}
]
Bağlam tanımlayıcı
Bir bağlam tanımlayıcısı, bir Robo komut dosyasını tetikleyen bağlamı/koşulu, bir veya birkaç özelliğin bir kombinasyonunu kullanarak tanımlar:
Bağlanmak | Tanım |
---|---|
"condition": "element_present" | Ekranda elementDescriptors veya visionText tarafından belirtilen metinle eşleşen bir kullanıcı arabirimi parçacığı olup olmadığını kontrol eder. |
"condition": "element_disabled" | elementDescriptors ile eşleşen bir UI parçacığının ekranda mevcut olup olmadığını ve onunla etkileşime geçilemeyeceğini kontrol eder. |
"condition": "element_checked" | Ekranda elementDescriptors ile eşleşen bir kullanıcı arabirimi parçacığı olup olmadığını kontrol eder ve kontrol edilir. |
"condition": "app_under_test_shown" | Test edilen uygulamanın ön planda çalışıp çalışmadığını kontrol eder. |
"condition": "default_launcher_shown" | Bir cihazın ana ekranının gösterilip gösterilmediğini kontrol eder, bu da ön planda hiçbir uygulamanın çalışmadığı anlamına gelir. |
"condition": "non_roboscript_action_performed" | Robo testi tarafından gerçekleştirilen son eylemin bir Robo komut dosyası eylemi olmadığını kontrol eder. |
negateCondition | true olarak ayarlanırsa, condition reddeder. Örneğin, ekranda bir UI parçacığı OLMADIĞINI veya test edilen uygulamanın ön planda ÇALIŞMADIĞINI kontrol etmek için bu özniteliği kullanabilirsiniz. |
elementDescriptors | Ekranda bir UI widget'ını tanımlayan bir veya daha fazla öğe tanımlayıcısı. element_present , element_disabled ve element_checked koşullarıyla birlikte kullanılır. visionText ile birbirini dışlar. Daha fazla bilgi için bkz . Öğe tanımlayıcıları . |
visionText | Ekrandaki metin, Optik Karakter Tanıma (OCR) API'si kullanılarak algılanır. visionText element_present koşuluyla birlikte kullanılır. elementDescriptors ile birbirini dışlar. |
Aşağıda, ekranda "my.app.package:id/page_header"
kaynak kimliğine sahip bir UI widget'ı tarafından tetiklenen bir Robo komut dosyası örneği verilmiştir:
{
"id": 1000,
"contextDescriptor": {
"condition": "element_present",
"elementDescriptors": [
{
"resourceId": "my.app.package:id/page_header"
}
]
},
"actions": [
{
"eventType": "VIEW_CLICKED",
"elementDescriptors": [
{
"text": "Settings"
}
]
}
]
}
Aşağıda, Optik Karakter Tanıma (OCR) tarafından algılanan "Privacy Policy"
tarafından tetiklenen bir Robo komut dosyası örneği verilmiştir:
{
"id": 1000,
"description": "Vision text Robo script",
"contextDescriptor": {
"condition": "element_present",
"visionText": "Privacy Policy"
},
"actions": [
{
"eventType": "VIEW_CLICKED",
"visionText": "Privacy Policy"
}
]
}
Aşağıda, komut dosyası olmayan her Robo eyleminden sonra 5 saniye bekleyen bir Robo komut dosyası örneği verilmiştir:
{
"contextDescriptor": {
"condition": "non_roboscript_action_performed"
},
"maxNumberOfRuns" : 1000,
"actions" : [
{
"eventType" : "DELAYED_MESSAGE_POSTED",
"delayTime" : 5000
}]
}
Hareketler
Bir Robo komut dosyasındaki her eylem, aşağıdaki tabloda açıklanan bir veya daha fazla özellik-değer çiftinin bir demeti olarak temsil edilir:
Bağlanmak | Tanım |
eventType | Eylemin türünü belirtir, örneğin tıklama, metin düzenleme vb. Her eylem için gereklidir. |
elementDescriptors | Bir UI widget'ını tanımlayan tanımlayıcılar. Belirli bir düğmeyi tıklamak gibi, hedef kullanıcı arabirimi widget'ına sahip tüm eylemler için gereklidir. |
optional | true olarak ayarlanırsa, gerçekleştirilemediğinde bu eylem atlanır. Örneğin, bir ekranda hedef UI widget'ını bulamadığında bu eylem atlanır - içeren Robo komut dosyası başarısız olmaz. Varsayılan olarak, değer false şeklindedir. |
replacementText | Hedef kullanıcı arayüzü parçacığına girilecek metin. Metin düzenleme işlemleri için gereklidir. |
swipeDirection | Kaydırmanın yönünü belirtir. Kaydırma işlemleri için gereklidir. |
delayTime | Milisaniye cinsinden ne kadar bekleneceğini belirtir. Bekleme eylemleri için gereklidir. |
pointTapXCoordinate ve pointTapYCoordinate | Dokunulan noktanın piksel X ve Y koordinatları. pointTapXPercent ve pointTapYPercent ile birbirini dışlayan. Noktaya dokunma eylemleri için gereklidir. |
pointTapXPercent ve pointTapYPercent | Dokunulan noktanın yüzde X ve Y koordinatları. pointTapXCoordinate ve pointTapYCoordinate ile birbirini dışlayan. Noktaya dokunma eylemleri için gereklidir. |
Aşağıda, hedef UI widget'ları olmayan iki eylem içeren bir Robo komut dosyası örneği verilmiştir; bu, bu eylemlerin belirli bir UI widget'ında çalışmadığı anlamına gelir:
[
{
"eventType": "DELAYED_MESSAGE_POSTED",
"delayTime": 3000
},
{
"eventType": "PRESSED_BACK"
}
]
Öğe tanımlayıcıları
Bir öğe tanımlayıcısı, aşağıdaki tanımlayıcı özniteliklerden birini veya daha fazlasını kullanarak bir UI widget'ını tanımlar:
Bağlanmak | Tanım |
className | – |
ancestorClassName | Öğenin kullanıcı arayüzü hiyerarşi atasının sınıf adı. Ata, öğenin kendisi de dahil olmak üzere, öğenin kullanıcı arabirimi hiyerarşisindeki üst düğümlerden herhangi biridir. |
resourceId | – |
resourceIdRegex | resourceId ile eşleşecek Java normal ifadesi. |
contentDescription | – |
contentDescriptionRegex | contentDescription ile eşleşecek Java normal ifadesi. |
text (ekranda görünen) | – |
textRegex | text eşleştirmek için Java normal ifadesi. |
groupViewChildPosition , recyclerViewChildPosition veya adapterViewChildPosition | Üst parçacığın türüne bağlı olarak bir UI parçacığının alt konumunu temsil eder. |
Sıklıkla, bu nitelikler tanımsızdır; örneğin, bir düğmenin metin ve içerik açıklaması olmayabilir. Bazı öznitelik değerleri mevcut olsa bile, belirli bir uygulama ekranında ( resourceId
dahil) benzersiz olmayabilirler.
Örneğin, bir listenin öğeleri arasında ayrım yapmak, genellikle yalnızca ana parçacığı içindeki farklı alt konumlarını kullanarak mümkündür. Bu, bir UI widget'ını tanımlamak için yalnızca bir öğe tanımlayıcısı kullanmanın genellikle yetersiz olduğu anlamına gelir. Bu nedenle, bir eylemin elementDescriptors
özniteliği, birincisi hedef UI parçacığına, ikincisi hedef UI parçacığının ana pencere öğesine karşılık gelecek şekilde sıralanan bir dizi öğe tanımlayıcı içerir. Bir eylemin hedef kullanıcı arayüzü parçacığı, tüm öğe tanımlayıcıları karşılık gelen kullanıcı arabirimi parçacığı alt hiyerarşisiyle eşleştiğinde eşleştirilir.
Aşağıda, her ikisi de sağlanan öğe tanımlayıcılarını kullanarak hedef kullanıcı arabirimi pencere bileşenini tanımlamanızı gerektiren, metin değiştirme ve tıklama eylemleri içeren bir Robo komut dosyası örneği verilmiştir:
[
{
"eventType": "VIEW_TEXT_CHANGED",
"replacementText": "John",
"elementDescriptors": [
{
"className": "android.support.v7.widget.AppCompatEditText",
"groupViewChildPosition": 0,
"resourceId": "com.google.samples.apps.topeka:id/first_name"
},
{
"className": "android.widget.FrameLayout",
"groupViewChildPosition": 0
},
{
"className": "android.support.design.widget.TextInputLayout",
"groupViewChildPosition": 1
}
]
},
{
"eventType": "VIEW_CLICKED",
"elementDescriptors": [
{
"className": "android.support.design.widget.FloatingActionButton",
"groupViewChildPosition": 1,
"resourceId": "com.google.samples.apps.topeka:id/done"
},
{
"className": "android.widget.FrameLayout",
"groupViewChildPosition": 1,
"resourceId": "com.google.samples.apps.topeka:id/content"
},
{
"className": "android.widget.FrameLayout",
"groupViewChildPosition": 0,
"resourceId": "com.google.samples.apps.topeka:id/sign_in_content"
}
]
}
]
Yürütme seçenekleri
İsteğe bağlı olarak, bir Robo betiğindeki eylem listesinin önüne, o Robo betiği için yürütme seçeneklerini belirten bir JSON nesnesi ekleyebilirsiniz. Bu yapılandırma başlığı, roboscript
anahtar sözcüğü ile başlar ve ardından istenen yürütme seçeneklerinin bir JSON temsili gelir.
Robo betikleri aşağıdaki yürütme seçeneklerini destekler:
-
executionMode
- bir Robo betiği çalışırken uygulanan yürütme seçenekleri:-
strict
-true
olarak ayarlanırsa, Robo betiği kısmi eşleştirme, geçerli eylemi atlama ve askıya alma kullanmaz. Diğer bir deyişle, Robo betiği normal bir enstrümantasyon testi olarak yürütülür ve eylemlerinden herhangi biri gerçekleştirilemediğinde başarısız olur.
-
-
postscript
- bir Robo betiği tamamlandıktan sonra uygulanan yürütme seçenekleri:-
terminate
-true
olarak ayarlanırsa Robo testi, Robo betiği tamamlandıktan sonra taramayı durdurur.
-
Aşağıda, strict
modda yürütülen ve üç saniye uyuyan, ardından taramanın durduğu bir Robo komut dosyası örneği verilmiştir:
"roboscript": {
"executionMode": {
"strict": true
},
"postscript": {
"terminate": true
}
}
[
{
"eventType": "DELAYED_MESSAGE_POSTED",
"delayTime": 3000
}
]
Şablon parametreleri
Bir şablon parametresi, bir Robo komut dosyasında, Robo testi yürütme için bu Robo komut dosyasını yüklediğinde gerçek değerle değiştirilen bir yer tutucudur. Şablon parametrelerinin önüne bir çift alt çizgi ve ardından bir yüzde işareti eklenir ve bir yüzde işaretinin ardından bir çift alt çizgi eklenir.
Robo betikleri aşağıdaki şablon parametresini destekler:
-
__%APP_PACKAGE_NAME%__
- test edilen uygulamanın paket adı.
Aşağıda, test edilen uygulama sürecini durduran bir Robo komut dosyası örneği verilmiştir:
[
{
"eventType": "ADB_SHELL_COMMAND",
"command": "am force-stop __%APP_PACKAGE_NAME%__"
}
]
Yorumlar
Bir Robo komut dosyası, #
veya //
ile başlayan satırlar olan yorum satırları içerebilir.
Aşağıda, birkaç yorum içeren bir Robo komut dosyası örneği verilmiştir:
# Confirm a user account.
[
{
// Click the DONE button.
"eventType": "VIEW_CLICKED",
"elementDescriptors": [
{
"resourceId": "com.google.samples.apps.topeka:id/done"
}
]
}
]
Yetenekler
Varsayılan olarak, bir Robo betiğinin tüm eylemleri tamamlanana (veya en azından denenene) kadar, Robo betiği etkin kalır. Robo testi, gerçekleştirilecek bir eylemi seçerken bir Robo komut dosyası eylemini eşleştirmeye çalışır. Robo komut dosyası, sağlamlığı artırmak için aşağıdaki teknikleri kullanır:
teknik | Tanım |
Kısmi eşleştirme | Mevcut Robo komut dosyası eylemi tam olarak eşleştirilemezse, eşleştirme kriterleri gevşetilir ve eşleştirme yeniden denenir. Kısmi eşleştirme, bir Robo komut dosyası eyleminin hedef kullanıcı arabirimi parçacığıyla eşleşirken en dıştaki öğe tanımlayıcısını dikkate almaz. Kısmi eşleştirme başarılı olursa, karşılık gelen Robo komut dosyası eylemi her zamanki gibi gerçekleştirilir. Bu teknik, örneğin uygulama sürümleri arasında ekran öğeleri yeniden düzenlendiğinde uygulama yapısının değiştiği senaryoları destekler. |
Geçerli eylemi atla | Geçerli Robo komut dosyası eylemi tamamen veya kısmen eşleştirilemezse Robo, sonraki Robo komut dosyası eylemini eşleştirmeye çalışır. Sonraki eylem tamamen veya kısmen eşleşirse, Robo testi mevcut Robo komut dosyası eylemini atlar (ve asla geri dönmez) ve sonrakini gerçekleştirir. Bu teknik, uygulama davranışının sürümler arasında değiştiği veya kesintili olduğu senaryoları destekler; örneğin, bir Robo betiğinin kaydı veya yeniden oynatılması sırasında farklı ekranlarda aralıklı bir iletişim kutusu görünebilir. |
Askıya almak | Ne mevcut ne de sonraki Robo komut dosyası eylemleri tamamen veya kısmen eşleştirilemezse, Robo komut dosyası geçici olarak askıya alınır ve Robo testi, diğer stratejilerini kullanarak gerçekleştirmek için bir eylem seçer. Bu eylem tamamlandıktan sonra Robo testi, Robo komut dosyasını yürütmeye devam eder. Mevcut veya sonraki Robo betiği eylemleri eşleştirilemediği sürece, Robo betiği herhangi bir sayıda eylem için askıda kalır. Bu nedenle, Robo betiklerinin mutlaka bir Robo testi için bir önsöz olması gerekmez ve Robo betiği eylemlerini standart Robo testi eylemleriyle karıştırabilirsiniz. Bu teknik, uygulama davranışının düzensiz olduğu veya uygulama sürümleri arasındaki değişikliklerin, Robo testinin standart eylemleriyle "boşlukları doldurması" için ihtiyaç duyduğu kadar büyük olduğu senaryoları destekler. |
Öncelikler
Bir Robo betiği maxNumberOfRuns
değerine ulaşırsa, artık belirli bir taramada tetiklenemez. Geçerli bağlam tarafından birden fazla Robo komut dosyası tetiklenebiliyorsa, aşağıdaki sırayla Robo komut dosyası seçilerek öncelik verilir:
- Bir
contextDescriptor
özniteliğine sahiptir. - En yüksek
priority
sahiptir (varsayılan olarak, tüm Robo betikleri1
ile aynı yürütmepriority
sahiptir). - Robo betiklerinin öncelikleri aynıysa, Robo betikleri listesinde en erken görünür.
Aşağıda, aynı eylemi gerçekleştiren ve aynı koşul tarafından tetiklenen üç Robo komut dosyası içeren bir dosya örneği verilmiştir - test edilen uygulama ön plandadır:
[
{
"id": 1000,
"description": "Robo script 1",
"contextDescriptor": {
"condition": "app_under_test_shown"
},
"actions": [
{
"eventType": "DELAYED_MESSAGE_POSTED",
"delayTime": 3000
}
]
},
{
"id": 1001,
"description": "Robo script 2",
"priority": "2",
"contextDescriptor": {
"condition": "app_under_test_shown"
},
"actions": [
{
"eventType": "DELAYED_MESSAGE_POSTED",
"delayTime": 3000
}
]
},
{
"id": 1002,
"description": "Robo script 3",
"contextDescriptor": {
"condition": "app_under_test_shown"
},
"actions": [
{
"eventType": "DELAYED_MESSAGE_POSTED",
"delayTime": 3000
}
]
}
]
Test edilen uygulama ön planda olduğunda, Robo sırasıyla aşağıdakileri tetikler:
-
"Robo script 2"
çünkü en yüksek önceliğe sahiptir. -
"Robo script 1"
, çünkü aynı önceliğe sahip kalan uygulanabilir Robo komut dosyaları arasında daha önce görünür. - Son uygulanabilir Robo komut dosyası olarak
"Robo script 3"
.
Tekrarlanan koşular
Varsayılan olarak Robo, tarama sırasında bir Robo komut dosyasını en fazla bir kez tetikler. Bu, maxNumberOfRuns
özniteliği aracılığıyla ayarlanabilir.
Aşağıda, test edilen uygulamayı 10 defaya kadar arka plana getiren bir Robo komut dosyası örneği verilmiştir:
{
"id": 1000,
"maxNumberOfRuns": 10,
"contextDescriptor": {
"condition": "app_under_test_shown"
},
"actions": [
{
"eventType": "GO_HOME"
}
]
}
Tarama aşaması
Robo betikleri, belirli bir Robo taramasının farklı aşamalarında uygulanabilir:
Tarama aşaması | Tanım |
pre_crawl | Robo başlatılmadan ve test edilen uygulamayı taramaya başlamadan önce. |
post_crawl | Robo, test edilen uygulamayı taramayı bitirdikten sonra. |
crawl | Robo'nun test edilen uygulamayı taradığı ana tarama aşaması. |
close_screen | Robo verilen bir ekrandan geri dönmeye (geri izleme) çalıştığında, bu ekrandaki olası tüm eylemler araştırıldığında. Varsayılan olarak Robo, bazı senaryolarda istenmeyen bir durum olan geri basar. |
Bir Robo betiğinin crawlStage
özniteliği belirtilmemişse, bunun crawl
olduğu ima edilir.
Aşağıda, Robo onu taramaya başlamadan önce test edilen uygulama kullanıcı verilerini temizleyen bir Robo komut dosyası örneği verilmiştir:
{
"id": 1000,
"crawlStage": "pre_crawl",
"actions": [
{
"eventType": "ADB_SHELL_COMMAND",
"command": "pm clear __%APP_PACKAGE_NAME%__"
}
]
}
Aşağıda, Robo'ya bir onay iletişim kutusundan geri dönmeye (geri izleme) çalıştığında "Cancel"
i tıklamasını söyleyen bir Robo komut dosyası örneği verilmiştir:
{
"id": 1000,
"crawlStage": "close_screen",
"maxNumberOfRuns": 999,
"contextDescriptor": {
"condition": "element_present",
"elementDescriptors": [
{
"resourceId": "my.app.package:id/confirmation_dialog"
}
]
},
"actions": [
{
"eventType": "VIEW_CLICKED",
"elementDescriptors": [
{
"text": "Cancel"
}
]
}
]
}
Koşullu işlemler
Bir Robo betiği koşullu eylemler içerebilir. Koşullu eylemler, Robo'nun bunları nasıl gerçekleştirdiğini açıklayan üç ek özelliğe sahiptir:
Bağlanmak | Tanım |
priority | Robo komut dosyasını içeren diğer koşullu işlemlere kıyasla bu koşullu eylemin önceliği. Varsayılan olarak, tüm koşullu eylemlerin önceliği 1 . |
maxNumberOfRuns | Bu koşullu eylemin, içerdiği Robo betiğinin bir yürütmesi sırasında kaç kez gerçekleştirilebileceği. Varsayılan olarak, tüm koşullu eylemler, içerdikleri Robo betiğinin tek bir yürütmesinde en fazla bir kez gerçekleştirilebilir. |
contextDescriptor | Bu koşullu eylemi tetikleyen bağlam/koşul. [Robo betiğinin contextDescriptor](#context-descriptor) ile aynı yapıya sahiptir ve benzer yetenekler sunar. |
Bir Robo betiği tetiklendiğinde, koşulsuz eylemlerini görünüm sırasına göre birer birer gerçekleştirir. Bir Robo betiği koşullu eylemler içeriyorsa, gerçekleştirilecek koşulsuz bir eylem seçilmeden önce bunlar her seferinde dikkate alınır. Herhangi bir koşullu eylem, önceliğine ve kalan çalıştırma sayısına göre tetiklenir ve seçilirse, Robo betiği bu koşullu eylemi gerçekleştirir. Aksi takdirde, Robo betiği aşağıdaki koşulsuz eylemi gerçekleştirir. Geçerli olması için bir Robo betiğinin en az bir koşulsuz eylem içermesi gerekir.
Aşağıda, Robo komut dosyasının yürütülmesi sırasında herhangi bir noktada ortaya çıkmaları durumunda açılır iletişim kutularını kapatan koşullu bir eyleme sahip koşulsuz bir Robo komut dosyası örneği verilmiştir:
{
"id": 1000,
"actions": [
{
"description": "Dismiss popup",
"maxNumberOfRuns": 100,
"contextDescriptor": {
"condition": "default_launcher_shown",
"negateCondition": true
},
"eventType": "GO_HOME"
},
{
"description": "Screen off",
"eventType": "ADB_SHELL_COMMAND",
"command": "input keyevent 26"
},
{
"description": "Wait for 10 seconds",
"eventType": "DELAYED_MESSAGE_POSTED",
"delayTime": 10000
},
{
"description": "Screen on",
"eventType": "ADB_SHELL_COMMAND",
"command": "input keyevent 82"
},
{
"description": "Wait for 10 seconds",
"eventType": "DELAYED_MESSAGE_POSTED",
"delayTime": 10000
}
}
Eylemleri yok sayma
Bir Robo betiği, Robo'nun belirli bir ekrandaki belirli UI widget'larını veya tüm UI widget'larını yok sayması için talimatlar içerebilir. Bu talimatlar, sırasıyla eventType
ELEMENT_IGNORED
ve ALL_ELEMENTS_IGNORED
ile "eylemler" yoksayılıyor olarak temsil edilir.
Yok sayma eylemleri içeren bir Robo betiğinin contextDescriptor
özniteliği belirli bir ekranla eşleştiğinde, Robo, yok sayma eylemleri tarafından hedeflenen herhangi bir UI pencere öğesiyle etkileşime girmez (başka bir Robo komut dosyası eylemi, Robo'nun yok sayılan UI pencere öğelerinden birinde bir eylem gerçekleştirmesini sağlamadığı sürece).
Bir Robo komut dosyası, yoksayma, koşullu ve koşulsuz eylemlerin bir karışımını içerebilir. Diğer Robo komut dosyası eylemlerinden farklı olarak, yok sayma eylemleri, priority
ve maxNumberOfRuns
özniteliklerinin değerlerinden bağımsız olarak, Robo komut dosyasının contextDescriptor
bir Robo taraması sırasında bir ekranla eşleştiği sürece uygulanır.
Aşağıda, iki Robo komut dosyası içeren bir dosya örneği verilmiştir. İlk Robo betiği, Robo'nun "my.app.package:id/ignored_screen"
kaynak kimliğine sahip bir UI widget'ı içeren bir ekranda tüm UI widget'larını yok saymasını sağlar. İkinci Robo betiği, Robo'nun kaynak kimlikleri "my.app.package:id/main_screen"
".*:id/done"
" ile eşleşen UI widget'larını yoksaymasını sağlar:
[
{
"id": 1000,
"contextDescriptor": {
"condition": "element_present",
"elementDescriptors": [
{
"resourceId": "my.app.package:id/ignored_screen"
}
]
},
"actions": [
{
"eventType": "ALL_ELEMENTS_IGNORED"
}
]
},
{
"id": 1001,
"contextDescriptor": {
"condition": "element_present",
"elementDescriptors": [
{
"resourceId": "my.app.package:id/main_screen"
}
]
},
"actions": [
{
"eventType": "ELEMENT_IGNORED",
"elementDescriptors": [
{
"resourceIdRegex": ".*:id/done"
}
]
}
]
}
]
RecyclerView ve AdapterView desteği
RecyclerView ve AdapterView pencere öğelerinin alt öğeleri dinamik olarak yüklenir ve geçerli ekrandan çok sayıda kaydırılarak görüntülenebilir. Bir ekranın boyutu ve bu çocuğa ulaşmak için gereken kaydırma sayısı, farklı cihaz form faktörlerinde farklı olduğundan, çocuğun kesin olan veri konumuna güvenmek çok daha sağlamdır. Bu çocuğu ekrana getirmek ve ardından ekran konumunu kullanmak için gereken kaydırma sayısına güvenmek daha az sağlam bir yaklaşımdır.
Bu nedenle, Robo betiği, Robo betiği eylemlerinin hedefi olan RecyclerView alt öğelerinin mutlak veri konumlarını recyclerViewChildPosition
olarak yakalar. Robo betiği ayrıca, adapterViewChildPosition
olarak Robo betiği eylemlerinin hedefi olan AdapterView alt öğelerinin mutlak veri konumlarını da yakalar.
RecyclerView ve AdapterView alt öğelerindeki eylemler aşağıdaki adımlarda gerçekleştirilir:
Robo testi, ilgili çocuğun, içerdiği RecyclerView veya AdapterView üzerinde bir konumlandırma eylemi aracılığıyla ekranda görüntülenmesini sağlar.
Robo test, ekranda zaten görüntülendiği için kaydedilen eylemi doğrudan alt öğe üzerinde gerçekleştirir.
Aşağıda, bir AdapterView ( android.widget.GridView
) alt öğesinde bir tıklama eylemi örneği verilmiştir:
{
"eventType": "VIEW_CLICKED",
"elementDescriptors": [
{
"className": "com.google.samples.apps.topeka.widget.AvatarView",
"adapterViewChildPosition": 5,
"resourceId": "com.google.samples.apps.topeka:id/avatar",
"contentDescription": "Avatar 6"
},
{
"className": "android.widget.GridView",
"groupViewChildPosition": 1,
"resourceId": "com.google.samples.apps.topeka:id/avatars"
},
{
"className": "android.widget.LinearLayout",
"groupViewChildPosition": 1
},
{
"className": "android.widget.LinearLayout",
"groupViewChildPosition": 0
}
]
}
Aşağıda, bir RecyclerView ( android.support.v7.widget.RecyclerView
) alt öğesinde bir tıklama eylemi örneği verilmiştir:
{
"eventType": "VIEW_CLICKED",
"elementDescriptors": [
{
"className": "android.support.v7.widget.AppCompatTextView",
"groupViewChildPosition": 1,
"resourceId": "com.google.samples.apps.topeka:id/category_title"
},
{
"className": "android.widget.FrameLayout",
"recyclerViewChildPosition": 8,
"resourceId": "com.google.samples.apps.topeka:id/category_item"
},
{
"className": "android.support.v7.widget.RecyclerView",
"groupViewChildPosition": 1,
"resourceId": "com.google.samples.apps.topeka:id/categories"
},
{
"className": "android.widget.FrameLayout",
"groupViewChildPosition": 1,
"resourceId": "com.google.samples.apps.topeka:id/category_container"
},
{
"className": "android.widget.LinearLayout",
"groupViewChildPosition": 0
}
]
}
Android Studio'da bir Robo betiği kaydedin ve Test Lab'de çalıştırın
Komut dosyasını bir JSON dosyası olarak kaydeden Android Studio'da bir Robo komut dosyası oluşturabilirsiniz. Daha sonra JSON dosyasını uygulama ile Firebase Test Lab'e yükleyebilir ve testi buna göre çalıştırabilirsiniz.
Ekli bir komut dosyasıyla bir Robo testi çalıştırdığınızda, Robo testi önce önceden komut dosyası oluşturulmuş eylemlerinizi gerçekleştirir ve ardından uygulamayı her zamanki gibi keşfeder.
Android Studio'da bir Robo betiği JSON dosyası oluşturmak için Android Studio'da Test Lab kullanarak Robo betiği kaydetme bölümündeki adımları izleyin.
Robo komut dosyası eylemleri
Aşağıdaki ortak isteğe bağlı özellik, tüm eylemler için geçerlidir:
-
description
- Robo test çıktılarında bu Robo komut dosyası eyleminin yürütülmesinin izlenmesine yardımcı olur.
İddia
İddia edilen koşul doğruysa Robo betiği, başka bir iddia olabilecek bir sonraki eyleme devam eder. Aksi takdirde, başarısız bir doğrulama nedeniyle Robo betiği yürütme durdurulur.
Aşağıdaki tabloda gerekli özellikler listelenmektedir:
Bağlanmak | Tanım |
"eventType": "ASSERTION" | -- |
contextDescriptor | İddia edilen bağlamı veya koşulu açıklar. Robo betiğinin contextDescriptor ile aynı yapıya sahiptir ve benzer yetenekler sunar. |
Aşağıda, test edilen uygulamanın ön planda olup olmadığını kontrol eden bir Robo komut dosyası doğrulama örneği verilmiştir:
{
"eventType": "ASSERTION",
"contextDescriptor": {
"condition": "app_under_test_shown"
}
}
Aşağıda, ekranda "com.google.samples.apps.topeka:id/done"
kaynak kimliğine sahip bir UI widget'ının bulunup bulunmadığını kontrol eden bir Robo komut dosyası doğrulama örneği verilmiştir:
{
"eventType": "ASSERTION",
"contextDescriptor": {
"condition": "element_present",
"elementDescriptors": [
{
"resourceId": "com.google.samples.apps.topeka:id/done"
}
]
}
}
Aşağıda, OCR kullanan bir ekranda "Settings"
algılanıp algılanmadığını kontrol eden bir Robo komut dosyası doğrulama örneği verilmiştir:
{
"eventType": "ASSERTION",
"contextDescriptor": {
"condition": "element_present",
"negateCondition": true,
"visionText": "Settings"
}
}
Tıklamak
Aşağıdaki tabloda gerekli özellikler listelenmektedir:
Bağlanmak | Tanım |
---|---|
eventType | Robo komut dosyası eyleminin türünü belirtir. |
"eventType": "VIEW_CLICKED" | Test edilen uygulamanın hedef öğesini tıklar. |
"eventType": "SOFT_KEYBOARD_CLICK" | Yazılım klavyesinin hedef öğesini tıklar. |
"eventType": "SOFT_KEYBOARD_RANDOM_CLICK" | Yazılım klavyesinin maxNumberOfRuns katına kadar rasgele öğelerini tıklar. |
"eventType": "LIST_ITEM_CLICKED" | Liste öğelerini tıklamak için Android Studio'daki Robo komut dosyası kaydedici tarafından kullanılır. |
elementDescriptors | Android UI hiyerarşisini kullanarak tıklanan UI widget'ını tanımlar. visionText ile birbirini dışlar. |
visionText | OCR kullanarak tıklanan öğeyi tanımlar. elementDescriptors ile birbirini dışlar. |
maxNumberOfRuns | eventType SOFT_KEYBOARD_RANDOM_CLICK olduğunda, yazılım klavyesinin rastgele bir öğesinin kaç kez tıklanacağını belirtir. Varsayılan değer 1 . |
Aşağıda "com.google.samples.apps.topeka:id/done"
kaynak kimliğine sahip bir düğmeyi tıklayan bir Robo komut dosyası eylemi örneği verilmiştir:
{
"eventType": "VIEW_CLICKED",
"elementDescriptors": [
{
"resourceId": "com.google.samples.apps.topeka:id/done"
}
]
}
Aşağıda, OCR kullanan bir ekranda algılanan "Privacy Policy"
na tıklayan Robo komut dosyası eyleminin bir örneği verilmiştir:
{
"eventType": "VIEW_CLICKED",
"visionText": "Privacy Policy"
}
Aşağıda, "Emoji button"
içerik açıklamasına sahip bir yazılım klavyesi öğesini tıklayan bir Robo komut dosyası eyleminin bir örneği yer almaktadır:
{
"eventType": "SOFT_KEYBOARD_CLICK",
"elementDescriptors": [
{
"contentDescription": "Emoji button"
}
]
}
Aşağıda, rasgele yazılım klavyesi öğelerini beş defaya kadar tıklatan bir Robo komut dosyası eylemi örneği verilmiştir:
{
"eventType": "SOFT_KEYBOARD_RANDOM_CLICK",
"maxNumberOfRuns": 5
}
Yumuşak klavyeyi devre dışı bırak
Aşağıdaki tabloda gerekli özellikler listelenmektedir:
Bağlanmak | Tanım |
"eventType": "DISABLE_KEYBOARD" | -- |
Aşağıda, yazılım klavyesini devre dışı bırakan bir Robo komut dosyası eylemi örneği verilmiştir:
{
"eventType": "DISABLE_KEYBOARD"
}
Adb Shell komutunu yürütün
Aşağıdaki tabloda gerekli özellikler listelenmektedir:
Bağlanmak | Tanım |
"eventType": "ADB_SHELL_COMMAND" | -- |
command | Yürütülecek Android Debug Bridge (adb) kabuk komutu. |
Aşağıda, test edilen uygulama kullanıcı verilerini temizleyen bir Robo komut dosyası eylemi örneği verilmiştir:
{
"eventType": "ADB_SHELL_COMMAND",
"command": "pm clear __%APP_PACKAGE_NAME%__"
}
İzin verme
Bu eylem, Espresso Test Recorder ile geriye dönük uyumluluk için Android Studio'daki Robo script kaydedici tarafından kaydedilir. Robo testi, her taramanın başında test edilen uygulamaya tüm izinleri verir ve bu nedenle, bu eylem işlemsizdir. Bu eylemi Robo betiklerinizde KULLANMAYIN.
Aşağıdaki tabloda gerekli özellikler listelenmektedir:
Bağlanmak | Tanım |
"eventType": "PERMISSIONS_REQUEST" | -- |
Ekrandaki tüm öğeleri yoksay
Bu eylem, Robo'nun, içerdiği Robo komut dosyasını tetikleyen herhangi bir ekrandaki tüm öğeleri yok saymasına neden olur.
Aşağıdaki tabloda gerekli özellikler listelenmektedir:
Bağlanmak | Tanım |
"eventType": "ALL_ELEMENTS_IGNORED" | -- |
Aşağıda, Robo'nun ekrandaki tüm öğeleri yok saymasını sağlayan bir Robo komut dosyası eylemi örneği verilmiştir:
{
"eventType": "ALL_ELEMENTS_IGNORED"
}
Bir öğeyi yoksay
Bu eylem, Robo'nun belirtilen elementDescriptors
ile eşleşen bir öğeyi (veya öğeleri) yoksaymasını sağlar.
Aşağıdaki tabloda gerekli özellikler listelenmektedir:
Bağlanmak | Tanım |
"eventType": "ELEMENT_IGNORED" | -- |
elementDescriptors | Android UI hiyerarşisini kullanarak yok sayılan UI widget'larını tanımlar. |
Aşağıda, Robo'nun içerik açıklamaları "Avatar"
ile başlayan tüm öğeleri yok saymasına neden olan bir Robo komut dosyası eylemi örneği verilmiştir:
{
"eventType": "ELEMENT_IGNORED",
"elementDescriptors": [
{
"contentDescriptionRegex": "Avatar.*"
}
]
}
Giriş metni
Aşağıdaki tabloda gerekli özellikler listelenmektedir:
Bağlanmak | Tanım |
---|---|
eventType | Robo komut dosyası eyleminin türünü belirtir. |
"eventType": "VIEW_TEXT_CHANGED" | Verilen metni hedef UI parçacığına girer. |
"eventType": "ENTER_TEXT" | verilen metni hedef UI parçacığına girer ve ardından bu UI parçacığına bir KEYCODE_ENTER olayı gönderir. |
elementDescriptors | Android UI hiyerarşisini kullanarak hedef UI widget'ını tanımlar. |
replacementText | Hedef kullanıcı arayüzü parçacığına girilecek metin. |
Aşağıda, " "com.google.samples.apps.topeka:id/first_name"
kaynak kimliğine sahip bir UI widget'ına "John"
yazan bir Robo komut dosyası eylemi örneği verilmiştir:
{
"eventType": "VIEW_TEXT_CHANGED",
"replacementText": "John",
"elementDescriptors": [
{
"resourceId": "com.google.samples.apps.topeka:id/first_name"
}
]
}
Uzun tıklama
Aşağıdaki tabloda gerekli özellikler listelenmektedir:
Bağlanmak | Tanım |
"eventType": "VIEW_LONG_CLICKED" | -- |
elementDescriptors | Android UI hiyerarşisini kullanarak hedef UI widget'ını tanımlar. |
Aşağıdaki öznitelik isteğe bağlıdır:
-
delayTime
- uzun bir tıklamanın basılmasının milisaniye cinsinden ne kadar süreceğini belirtir.
Aşağıda "Avatar 8"
içerik açıklamasına sahip bir kullanıcı arabirimi parçacığı üzerinde beş saniye süren bir tıklama gerçekleştiren bir Robo komut dosyası eylemi örneği verilmiştir:
{
"eventType": "VIEW_LONG_CLICKED",
"elementDescriptors": [
{
"contentDescription": "Avatar 8"
}
],
"delayTime": 5000
}
Tek noktalı bir hareket gerçekleştirin
Aşağıdaki tabloda gerekli özellikler listelenmektedir:
Bağlanmak | Tanım |
---|---|
"eventType": "ONE_POINT_GESTURE" | -- |
coordinates | Yüzde veya piksel olarak "(x1,y1)->(x2,y2)" olarak biçimlendirilmiş, tek noktalı bir hareket için iki koordinat. |
Aşağıdaki öznitelik isteğe bağlıdır:
-
dragAndDrop
-true
olarak ayarlanırsa, tek noktalı hareket bir sürükle ve bırak eylemi gerçekleştirir. Varsayılan olarak,false
.
Aşağıda, aşağı kaydırma gerçekleştiren bir Robo komut dosyası tek noktalı hareket eylemi örneği verilmiştir:
{
"eventType": "ONE_POINT_GESTURE",
"coordinates": "(50%,25%)->(50%,75%)"
}
İki noktalı bir hareket gerçekleştirin
Aşağıdaki tabloda gerekli özellikler listelenmektedir:
Bağlanmak | Tanım |
---|---|
"eventType": "TWO_POINT_GESTURE" | -- |
coordinates | Yüzde veya piksel olarak "(x1,y1)->(x2,y2),(x3,y3)->(x4,y4)" şeklinde biçimlendirilmiş iki noktalı bir hareket için dört koordinat. |
Aşağıda, çimdikleme hareketini gerçekleştiren bir Robo komut dosyası eylemi örneği verilmiştir:
{
"eventType": "TWO_POINT_GESTURE",
"coordinates": "(50%,50%)->(25%,50%),(50%,50%)->(75%,50%)"
}
Bir IME eylemi gerçekleştirme
Bu eylem, belirtilen hedef UI parçacığı için Giriş Yöntemi Düzenleyicisi'nde (IME) mevcut eylem düğmesine (örneğin sonraki, bitti ve ara) basar.
Aşağıdaki tabloda gerekli özellikler listelenmektedir:
Bağlanmak | Tanım |
---|---|
"eventType": "PRESSED_EDITOR_ACTION" | -- |
elementDescriptors | Android UI hiyerarşisini kullanarak hedef UI widget'ını tanımlar. |
Aşağıda "com.google.samples.apps.topeka:id/first_name"
kaynak kimliğine sahip bir kullanıcı arabirimi widget'ında bir IME eylemi gerçekleştiren bir Robo komut dosyası eylemi örneği verilmiştir:
{
"eventType": "PRESSED_EDITOR_ACTION",
"elementDescriptors": [
{
"resourceId": "com.google.samples.apps.topeka:id/first_name"
}
]
}
geri basın
Aşağıdaki tabloda gerekli özellikler listelenmektedir:
Bağlanmak | Tanım |
eventType | Robo komut dosyası eyleminin türünü belirtir. |
"eventType": "PRESSED_BACK" | Cihaza bir KEYCODE_BACK olayı gönderir. |
"eventType": "PRESSED_BACK_EMULATOR_28" | API 28 öykünücülerine geri basmak için Android Studio'daki Robo komut dosyası kaydedici tarafından kullanılır. |
Aşağıda, geri basan bir Robo komut dosyası eyleminin bir örneği verilmiştir:
{
"eventType": "PRESSED_BACK"
}
Ana sayfaya basın
Bu eylem, cihaza bir KEYCODE_HOME
olayı gönderir.
Aşağıdaki tabloda gerekli özellikler listelenmektedir:
Bağlanmak | Tanım |
"eventType": "GO_HOME" | -- |
Aşağıda, ana sayfaya basan bir Robo komut dosyası eyleminin bir örneği verilmiştir:
{
"eventType": "GO_HOME"
}
Bir öğeyi görünüme kaydırın
Bu eylem, Robo testinin belirtilen elementDescriptors
ile eşleşen UI widget'ını ekranda belirtilen childElementDescriptors
ile eşleşen UI widget'ı görünene veya kaydırılan widget artık kaydırılamayana veya maksimum 50 kaydırma sayısına ulaşılana kadar ileri kaydırmasını sağlar.
Aşağıdaki tabloda gerekli özellikler listelenmektedir:
Bağlanmak | Tanım |
"eventType": "ELEMENT_SCROLL_INTO_VIEW" | -- |
elementDescriptors | Android UI hiyerarşisini kullanarak kaydırılan UI widget'ını tanımlar. |
childElementDescriptors | Android UI hiyerarşisini kullanarak kaydırılacak UI widget'ını tanımlar. |
Aşağıda "my.app.package:id/scrollable_card_container"
kaynak kimliğine sahip UI widget'ını ekranda "Orange"
metnine sahip UI widget'ı görünene (veya daha fazla kaydırma yapılamayana) kadar kaydıran bir Robo komut dosyası eylemi örneği verilmiştir. veya maksimum 50 kaydırma sayısına ulaşılır):
{
"eventType": "ELEMENT_SCROLL_INTO_VIEW",
"elementDescriptors": [
{
"resourceId": "my.app.package:id/scrollable_card_container"
}
],
"childElementDescriptors": [
{
"text": "Orange"
}
]
}
Tokatlamak
Aşağıdaki tabloda gerekli özellikler listelenmektedir:
Bağlanmak | Tanım |
---|---|
"eventType": "VIEW_SWIPED" | -- |
swipeDirection | Kaydırmanın yönünü belirtir:
|
elementDescriptors | Android UI hiyerarşisini kullanarak hedef UI widget'ını tanımlar. |
Aşağıda "my.app.package:id/custom_content"
kaynak kimliğine sahip bir UI widget'ını kaydıran bir Robo komut dosyası eylemi örneği verilmiştir:
{
"eventType": "VIEW_SWIPED",
"swipeDirection": "Up",
"elementDescriptors": [
{
"resourceId": "my.app.package:id/custom_content"
}
]
}
Ekran görüntüsü al
Aşağıdaki tabloda gerekli özellikler listelenmektedir:
Bağlanmak | Tanım |
"eventType": "TAKE_SCREENSHOT" | -- |
screenshotName | Ekran görüntüsü dosya adını belirtir. |
Aşağıda, ekran görüntüsü alan bir Robo komut dosyası eylemi örneği verilmiştir:
{
"eventType": "TAKE_SCREENSHOT",
"screenshotName": "my_screenshot"
}
Ekranda bir noktaya dokunun
Aşağıdaki tabloda gerekli özellikler listelenmektedir:
Bağlanmak | Tanım |
---|---|
"eventType": "POINT_TAP" | -- |
pointTapXCoordinate | Dokunulan noktanın piksel X koordinatı. pointTapXPercent ve pointTapYPercent ile birbirini dışlayan. |
pointTapYCoordinate | Dokunulan noktanın piksel Y koordinatı. pointTapXPercent ve pointTapYPercent ile birbirini dışlayan. |
pointTapXPercent | Dokunulan noktanın yüzde X koordinatı. pointTapXCoordinate ve pointTapYCoordinate ile birbirini dışlayan. |
pointTapYPercent | Dokunulan noktanın yüzde Y koordinatı. pointTapXCoordinate ve pointTapYCoordinate ile birbirini dışlayan. |
Aşağıda, ekranın ortasına hafifçe vuran bir Robo komut dosyası eylemi örneği verilmiştir:
{
"eventType": "POINT_TAP",
"pointTapXPercent": 50,
"pointTapYPercent": 50
}
Bir öğe içindeki bir noktaya dokunun
Aşağıdaki tabloda gerekli özellikler listelenmektedir:
Bağlanmak | Tanım |
"eventType": "POINT_TAP_ELEMENT" | -- |
pointTapXPercent | Hedef öğe içindeki yüzde X koordinatı. |
pointTapYPercent | Hedef öğe içindeki yüzde Y koordinatı. |
elementDescriptors | Android UI hiyerarşisini kullanarak hedef UI widget'ını tanımlar. |
Aşağıda, bir arama çubuğunun kaydırıcısını sağa hareket ettiren bir Robo komut dosyası eylemi örneği verilmiştir:
{
"eventType": "POINT_TAP_ELEMENT",
"pointTapXPercent": 80,
"pointTapYPercent": 50,
"elementDescriptors": [
{
"resourceId": "my.app.package:id/my_seekbar"
}
]
}
Taramayı sonlandır
Bu eylem Robo testini durdurur.
Aşağıdaki tabloda gerekli özellikler listelenmektedir:
Bağlanmak | Tanım |
---|---|
"eventType": "TERMINATE_CRAWL" | -- |
Aşağıda, bir Robo testini durduran bir Robo komut dosyası eylemi örneği verilmiştir:
{
"eventType": "TERMINATE_CRAWL"
}
Beklemek
Aşağıdaki tabloda gerekli özellikler listelenmektedir:
Bağlanmak | Tanım |
"eventType": "DELAYED_MESSAGE_POSTED" | -- |
delayTime | Milisaniye cinsinden ne kadar bekleneceğini belirtir. |
Aşağıda, üç saniye bekleyen bir Robo komut dosyası eylemi örneği verilmiştir:
{
"eventType": "DELAYED_MESSAGE_POSTED",
"delayTime": 3000
}
Bir öğe için bekleyin
Bu eylem, Robo testinin belirtilen zaman aşımına kadar bir öğenin ekranda görünmesini beklemesini sağlar.
Aşağıdaki tabloda gerekli özellikler listelenmektedir:
Bağlanmak | Tanım |
"eventType": "WAIT_FOR_ELEMENT" | -- |
delayTime | Bekleme zaman aşımını milisaniye cinsinden belirtir. |
elementDescriptors | Android UI hiyerarşisini kullanarak, beklenen UI widget'ını tanımlar. |
Aşağıda, "my.app.package:id/confirmation_button"
kaynak kimliğine sahip bir UI widget'ının ekranda görünmesi için 30 saniyeye kadar bekleyen bir Robo komut dosyası eylemi örneği verilmiştir:
{
"eventType": "WAIT_FOR_ELEMENT",
"delayTime": 30000,
"elementDescriptors": [
{
"resourceId": "my.app.package:id/confirmation_button"
}
]
}
Sonraki adımlar
,Bu belge, yapı, yetenekler, kullanım, kayıt ve eylemler dahil olmak üzere Robo betikleri hakkında referans bilgileri sağlar. Robo betikleri, mobil uygulamalar için manuel kalite güvencesi (QA) görevlerini otomatikleştiren ve sürekli entegrasyon (CI) ve lansman öncesi test stratejileri sağlayan testlerdir. Bir Robo betiği, bir kullanıcı arabirimi (UI) dizisini ve diğer eylemleri açıklayan bir JSON dosyasıdır.
Aşağıdaki şekillerde bir Robo betiği oluşturabilirsiniz:
- Robo komut dosyası kayıt özelliğini kullanın.
- Robo betiğini manuel olarak oluşturun.
- Robo komut dosyasını kaydedin ve ardından manuel olarak düzenleyin.
Robo betiklerini kullanma hakkında daha fazla bilgi edinmek için Robo betiği çalıştırma bölümüne bakın.
Robo komut dosyası, test edilen uygulama Android Uygulama Paketi (APK) gibi diğer girdilerin yanı sıra Robo testine sağlanır.
Aşağıda, bir kullanıcıyı bir uygulamaya imzalayan ve test edilen uygulama başlatıldığında tetiklenen bir Robo komut dosyası örneği verilmiştir:
[
{
"crawlStage": "crawl",
"contextDescriptor": {
"condition": "app_under_test_shown"
},
"actions": [
{
"eventType": "VIEW_TEXT_CHANGED",
"replacementText": "user123",
"elementDescriptors": [
{
"resourceId": "my.app.package:id/username"
}
]
},
{
"eventType": "VIEW_TEXT_CHANGED",
"replacementText": "12345",
"elementDescriptors": [
{
"resourceId": "my.app.package:id/password"
}
]
},
{
"eventType": "VIEW_CLICKED",
"elementDescriptors": [
{
"resourceId": "my.app.package:id/login"
}
]
}
]
}
]
Bir dosyada tek bir Robo komut dosyası varsa ve yukarıdaki örnekte olduğu gibi varsayılan app_under_test_shown
tetikleme koşuluna sahipse, Robo komut dosyasını daha basit bir biçim kullanarak bir dosyada belirtebilirsiniz - tıpkı eylemlerinin bir sırası gibi:
[
{
"eventType": "VIEW_TEXT_CHANGED",
"replacementText": "user123",
"elementDescriptors": [
{
"resourceId": "my.app.package:id/username"
}
]
},
{
"eventType": "VIEW_TEXT_CHANGED",
"replacementText": "12345",
"elementDescriptors": [
{
"resourceId": "my.app.package:id/password"
}
]
},
{
"eventType": "VIEW_CLICKED",
"elementDescriptors": [
{
"resourceId": "my.app.package:id/login"
}
]
}
]
Yapı
Bir Robo komut dosyasının, Robo'nun onu nasıl yürüttüğünü açıklayan çeşitli öznitelikleri vardır. Bu özniteliklerin çoğu, önceden tanımlanmış varsayılan değerlerle isteğe bağlıdır:
Bağlanmak | Tanım |
id | Tarama çıktılarında bu Robo komut dosyasının izlenmesine yardımcı olan bir tamsayı. |
description | id benzer, ancak daha açıklayıcıdır. |
crawlStage | Tarama Robo aşaması, bu Robo komut dosyasını şu adreste uygular: Varsayılan olarak, ana tarama aşamasıdır. |
priority | Bu Robo betiğinin diğer Robo betiklerine kıyasla önceliği. Varsayılan olarak, tüm Robo betiklerinin önceliği 1 . |
maxNumberOfRuns | Bir tarama sırasında Robo'nun bu Robo komut dosyasını kaç kez çalıştırabileceğini belirtir. Varsayılan olarak, Robo bir Robo komut dosyasını bir kez çalıştırabilir. |
contextDescriptor | Bu Robo komut dosyasını tetikleyen bağlamı/koşulu açıklar. Atlanırsa, bu Robo betiğinin tetikleme koşulunun her zaman karşılandığı kabul edilir; başka bir deyişle, Robo betiği koşulsuzdur. |
actions | Bu Robo betiğinin tüm eylemleri. |
Tek bir dosya, bir veya daha fazla Robo komut dosyası koleksiyonu içerir.
Aşağıda, her biri taramanın başlangıcında bir kez yürütülen tek bir eyleme sahip iki koşulsuz Robo komut dosyasına sahip bir dosya örneği verilmiştir:
[
{
"id": 1000,
"description": "My first Robo script",
"actions": [
{
"eventType": "DISABLE_KEYBOARD"
}
]
},
{
"id": 1001,
"description": "My second Robo script",
"actions": [
{
"eventType": "PRESSED_BACK"
}
]
}
]
Bağlam tanımlayıcı
Bir bağlam tanımlayıcısı, bir Robo komut dosyasını tetikleyen bağlamı/koşulu, bir veya birkaç özelliğin bir kombinasyonunu kullanarak tanımlar:
Bağlanmak | Tanım |
---|---|
"condition": "element_present" | Ekranda elementDescriptors veya visionText tarafından belirtilen metinle eşleşen bir kullanıcı arabirimi parçacığı olup olmadığını kontrol eder. |
"condition": "element_disabled" | elementDescriptors ile eşleşen bir UI parçacığının ekranda mevcut olup olmadığını ve onunla etkileşime geçilemeyeceğini kontrol eder. |
"condition": "element_checked" | Ekranda elementDescriptors ile eşleşen bir kullanıcı arabirimi parçacığı olup olmadığını kontrol eder ve kontrol edilir. |
"condition": "app_under_test_shown" | Test edilen uygulamanın ön planda çalışıp çalışmadığını kontrol eder. |
"condition": "default_launcher_shown" | Bir cihazın ana ekranının gösterilip gösterilmediğini kontrol eder, bu da ön planda hiçbir uygulamanın çalışmadığı anlamına gelir. |
"condition": "non_roboscript_action_performed" | Robo testi tarafından gerçekleştirilen son eylemin bir Robo komut dosyası eylemi olmadığını kontrol eder. |
negateCondition | true olarak ayarlanırsa, condition reddeder. Örneğin, ekranda bir UI parçacığı OLMADIĞINI veya test edilen uygulamanın ön planda ÇALIŞMADIĞINI kontrol etmek için bu özniteliği kullanabilirsiniz. |
elementDescriptors | Ekranda bir UI widget'ını tanımlayan bir veya daha fazla öğe tanımlayıcısı. element_present , element_disabled ve element_checked koşullarıyla birlikte kullanılır. visionText ile birbirini dışlar. Daha fazla bilgi için bkz . Öğe tanımlayıcıları . |
visionText | Ekrandaki metin, Optik Karakter Tanıma (OCR) API'si kullanılarak algılanır. visionText element_present koşuluyla birlikte kullanılır. elementDescriptors ile birbirini dışlar. |
Aşağıda, ekranda "my.app.package:id/page_header"
kaynak kimliğine sahip bir UI widget'ı tarafından tetiklenen bir Robo komut dosyası örneği verilmiştir:
{
"id": 1000,
"contextDescriptor": {
"condition": "element_present",
"elementDescriptors": [
{
"resourceId": "my.app.package:id/page_header"
}
]
},
"actions": [
{
"eventType": "VIEW_CLICKED",
"elementDescriptors": [
{
"text": "Settings"
}
]
}
]
}
Aşağıda, Optik Karakter Tanıma (OCR) tarafından algılanan "Privacy Policy"
tarafından tetiklenen bir Robo komut dosyası örneği verilmiştir:
{
"id": 1000,
"description": "Vision text Robo script",
"contextDescriptor": {
"condition": "element_present",
"visionText": "Privacy Policy"
},
"actions": [
{
"eventType": "VIEW_CLICKED",
"visionText": "Privacy Policy"
}
]
}
The following is an example of a Robo script that waits for 5 seconds after every non-script Robo action:
{
"contextDescriptor": {
"condition": "non_roboscript_action_performed"
},
"maxNumberOfRuns" : 1000,
"actions" : [
{
"eventType" : "DELAYED_MESSAGE_POSTED",
"delayTime" : 5000
}]
}
Actions
Each action in a Robo script is represented as a bundle of one or more attribute-value pairs, which are described in the following table:
Attribute | Description |
eventType | Specifies the type of the action, for example, click, text edit, etc. Required for every action. |
elementDescriptors | Descriptors that identify a UI widget. Required for all actions that have a target UI widget, like clicking a particular button. |
optional | If set to true , this action is skipped when it cannot be performed. For example, this action is skipped when it can't find its target UI widget on a screen– without failing the containing Robo script. By default, the value is false . |
replacementText | The text to input into the target UI widget. Required for text editing actions. |
swipeDirection | Specifies the direction of the swipe. Required for swipe actions. |
delayTime | Specifies how long to wait, in milliseconds. Required for wait actions. |
pointTapXCoordinate and pointTapYCoordinate | The pixel X and Y coordinates of the tapped point. Mutually exclusive with pointTapXPercent and pointTapYPercent . Required for point tap actions. |
pointTapXPercent and pointTapYPercent | The percentage X and Y coordinates of the tapped point. Mutually exclusive with pointTapXCoordinate and pointTapYCoordinate . Required for point tap actions. |
The following is an example of a Robo script with two actions without target UI widgets, which means that these actions don't operate on a specific UI widget:
[
{
"eventType": "DELAYED_MESSAGE_POSTED",
"delayTime": 3000
},
{
"eventType": "PRESSED_BACK"
}
]
Element descriptors
An element descriptor identifies a UI widget using one or more of the following identifying attributes:
Attribute | Description |
className | – |
ancestorClassName | Class name of the element's UI hierarchy ancestor. An ancestor is any of the parent nodes in the element's UI hierarchy, including the element itself. |
resourceId | – |
resourceIdRegex | Java regular expression to match resourceId . |
contentDescription | – |
contentDescriptionRegex | Java regular expression to match contentDescription . |
text (that appears on the screen) | – |
textRegex | Java regular expression to match text . |
groupViewChildPosition , recyclerViewChildPosition , or adapterViewChildPosition | Represents a UI widget's child position depending on the kind of its parent widget. |
Frequently, these attributes are undefined, for example, a button might not have text and content description. Even if some attribute values are present, they might not be unique on a given app screen (including resourceId
).
For example, differentiating between items of a list is commonly possible only by using their different child positions within their parent widget. This means that using just one element descriptor to identify a UI widget is usually insufficient. Therefore, an action's elementDescriptors
attribute contains a sequence of element descriptors that are ordered such that the first one corresponds to the target UI widget, the second one corresponds to the target UI widget's parent widget, and so on. An action's target UI widget is matched when all of its element descriptors match the corresponding UI widget sub-hierarchy.
The following is an example of a Robo script with a text change and click actions, both of which require you to identify the target UI widget using the provided element descriptors:
[
{
"eventType": "VIEW_TEXT_CHANGED",
"replacementText": "John",
"elementDescriptors": [
{
"className": "android.support.v7.widget.AppCompatEditText",
"groupViewChildPosition": 0,
"resourceId": "com.google.samples.apps.topeka:id/first_name"
},
{
"className": "android.widget.FrameLayout",
"groupViewChildPosition": 0
},
{
"className": "android.support.design.widget.TextInputLayout",
"groupViewChildPosition": 1
}
]
},
{
"eventType": "VIEW_CLICKED",
"elementDescriptors": [
{
"className": "android.support.design.widget.FloatingActionButton",
"groupViewChildPosition": 1,
"resourceId": "com.google.samples.apps.topeka:id/done"
},
{
"className": "android.widget.FrameLayout",
"groupViewChildPosition": 1,
"resourceId": "com.google.samples.apps.topeka:id/content"
},
{
"className": "android.widget.FrameLayout",
"groupViewChildPosition": 0,
"resourceId": "com.google.samples.apps.topeka:id/sign_in_content"
}
]
}
]
Execution options
You can optionally prefix the list of actions in a Robo script with a JSON object that specifies the execution options for that Robo script. This configuration header starts with the roboscript
keyword followed by a JSON representation of the desired execution options.
Robo scripts support the following execution options:
-
executionMode
- execution options applied when a Robo script is running:-
strict
- if set totrue
, Robo script does not employ partial matching, skipping current action, and suspension . That is, the Robo script is executed as a regular instrumentation test and fails as soon as any of its actions cannot be performed.
-
-
postscript
- execution options applied after a Robo script is completed:-
terminate
- if set totrue
, Robo test stops crawling after the Robo script is completed.
-
The following is an example of a Robo script executed in strict
mode that sleeps for three seconds, after which the crawl stops:
"roboscript": {
"executionMode": {
"strict": true
},
"postscript": {
"terminate": true
}
}
[
{
"eventType": "DELAYED_MESSAGE_POSTED",
"delayTime": 3000
}
]
Template parameters
A template parameter is a placeholder in a Robo script that is replaced with the actual value when Robo test loads that Robo script for execution. Template parameters are prefixed with a double underscore followed by a percent sign, and are postfixed with a percent sign followed by a double underscore.
Robo scripts support the following template parameter:
-
__%APP_PACKAGE_NAME%__
- the package name of the app-under-test.
The following is an example of a Robo script that stops the app-under-test process:
[
{
"eventType": "ADB_SHELL_COMMAND",
"command": "am force-stop __%APP_PACKAGE_NAME%__"
}
]
Comments
A Robo script can contain comment lines, which are lines that start with #
or //
.
The following is an example of a Robo script with a couple of comments:
# Confirm a user account.
[
{
// Click the DONE button.
"eventType": "VIEW_CLICKED",
"elementDescriptors": [
{
"resourceId": "com.google.samples.apps.topeka:id/done"
}
]
}
]
Capabilities
By default, until all actions of a Robo script are completed (or at least attempted), the Robo script remains active. Robo test keeps trying to match a Robo script action whenever it is picking an action to perform. Robo script employs the following techniques to increase robustness:
Technique | Description |
Partial matching | If the current Robo script action cannot be fully matched, the matching criteria are relaxed and the matching is retried. The partial matching doesn't consider the outermost element descriptor while matching the target UI widget of a Robo script action. If the partial matching succeeds, the corresponding Robo script action is performed as usual. This technique supports scenarios in which the app structure changes, for example, between app versions, when screen elements are rearranged. |
Skip current action | If the current Robo script action cannot be fully or partially matched, Robo tries to match the subsequent Robo script action. If the subsequent action fully or partially matches, Robo test skips (and never returns to) the current Robo script action and performs the subsequent one. This technique supports scenarios when app behavior changes between versions or is flaky, for example, when an intermittent dialog might appear at different screens during recording versus replaying of a Robo script. |
Suspend | If neither current nor subsequent Robo script actions can be fully or partially matched, Robo script is temporarily suspended and Robo test picks an action to perform using its other strategies. After this action is completed, Robo test resumes executing the Robo script. As long as current or subsequent Robo script actions cannot be matched, Robo script remains suspended for any number of actions. Thus, Robo scripts do not necessarily need to be a prologue for a Robo test, and you can intersperse Robo script actions with standard Robo test actions. This technique supports scenarios when app behavior is flaky, or when changes between app versions are large enough that Robo test needs to "fill in the gaps" with its standard actions. |
Priorities
If a Robo script reaches its maxNumberOfRuns
, it can no longer be triggered in a given crawl. If more than one Robo script can be triggered by the current context, priority is given by choosing, in the following order, the Robo script that:
- Has a
contextDescriptor
attribute. - Has the highest
priority
(by default, all Robo scripts have the same executionpriority
of1
). - Appears earliest in the list of the Robo scripts, if Robo scripts' priorities are the same.
The following is an example of a file with three Robo scripts that perform the same action and are triggered by the same condition - the app-under-test being in the foreground:
[
{
"id": 1000,
"description": "Robo script 1",
"contextDescriptor": {
"condition": "app_under_test_shown"
},
"actions": [
{
"eventType": "DELAYED_MESSAGE_POSTED",
"delayTime": 3000
}
]
},
{
"id": 1001,
"description": "Robo script 2",
"priority": "2",
"contextDescriptor": {
"condition": "app_under_test_shown"
},
"actions": [
{
"eventType": "DELAYED_MESSAGE_POSTED",
"delayTime": 3000
}
]
},
{
"id": 1002,
"description": "Robo script 3",
"contextDescriptor": {
"condition": "app_under_test_shown"
},
"actions": [
{
"eventType": "DELAYED_MESSAGE_POSTED",
"delayTime": 3000
}
]
}
]
When the app-under-test is in the foreground, Robo triggers the following, in order:
-
"Robo script 2"
because it has the highest priority. -
"Robo script 1"
because it appears earlier among the remaining applicable Robo scripts with the same priority. -
"Robo script 3"
as the last applicable Robo script.
Repeated runs
By default, Robo triggers a Robo script at most once during a crawl. This can be adjusted via the maxNumberOfRuns
attribute.
The following is an example of a Robo script that brings the app-under-test into the background for up to 10 times:
{
"id": 1000,
"maxNumberOfRuns": 10,
"contextDescriptor": {
"condition": "app_under_test_shown"
},
"actions": [
{
"eventType": "GO_HOME"
}
]
}
Crawl stage
Robo scripts are applicable at different stages of a given Robo crawl:
Crawl stage | Description |
pre_crawl | Before Robo launches and starts crawling the app-under-test. |
post_crawl | After Robo finishes crawling the app-under-test. |
crawl | The main crawl stage, when Robo crawls the app-under-test. |
close_screen | When Robo tries to return back (backtrack) from a given screen, when all possible actions on this screen are explored. By default, Robo presses back, which is undesirable in some scenarios. |
If the crawlStage
attribute of a Robo script is unspecified, it is implied to be crawl
.
The following is an example of a Robo script that clears the app-under-test user data before Robo starts crawling it:
{
"id": 1000,
"crawlStage": "pre_crawl",
"actions": [
{
"eventType": "ADB_SHELL_COMMAND",
"command": "pm clear __%APP_PACKAGE_NAME%__"
}
]
}
The following is an example of a Robo script that instructs Robo to click "Cancel"
whenever it tries to return back (backtrack) from a confirmation dialog:
{
"id": 1000,
"crawlStage": "close_screen",
"maxNumberOfRuns": 999,
"contextDescriptor": {
"condition": "element_present",
"elementDescriptors": [
{
"resourceId": "my.app.package:id/confirmation_dialog"
}
]
},
"actions": [
{
"eventType": "VIEW_CLICKED",
"elementDescriptors": [
{
"text": "Cancel"
}
]
}
]
}
Conditional actions
A Robo script can contain conditional actions. Conditional actions have three additional attributes that describe how Robo performs them:
Attribute | Description |
priority | The priority of this conditional action in comparison to other conditional actions within its containing Robo script. By default, all conditional actions have a priority of 1 . |
maxNumberOfRuns | How many times this conditional action can be performed during one execution of its containing Robo script. By default, all conditional actions can be performed at most once in a single execution of their containing Robo script. |
contextDescriptor | The context/condition that triggers this conditional action. It has the same structure and offers similar capabilities as [the Robo script's contextDescriptor](#context-descriptor). |
When triggered, a Robo script performs its non-conditional actions one by one in order of appearance. If a Robo script contains conditional actions, then they are considered every time before picking a non-conditional action to perform. If any conditional action is triggered and picked based on its priority and the remaining number of runs, then the Robo script performs this conditional action. Otherwise, the Robo script performs the following non-conditional action. To be valid, a Robo script must contain at least one non-conditional action.
The following is an example of an unconditional Robo script with a conditional action that dismisses popup dialogs if they show up at any point during the Robo script execution:
{
"id": 1000,
"actions": [
{
"description": "Dismiss popup",
"maxNumberOfRuns": 100,
"contextDescriptor": {
"condition": "default_launcher_shown",
"negateCondition": true
},
"eventType": "GO_HOME"
},
{
"description": "Screen off",
"eventType": "ADB_SHELL_COMMAND",
"command": "input keyevent 26"
},
{
"description": "Wait for 10 seconds",
"eventType": "DELAYED_MESSAGE_POSTED",
"delayTime": 10000
},
{
"description": "Screen on",
"eventType": "ADB_SHELL_COMMAND",
"command": "input keyevent 82"
},
{
"description": "Wait for 10 seconds",
"eventType": "DELAYED_MESSAGE_POSTED",
"delayTime": 10000
}
}
Ignoring actions
A Robo script can contain instructions for Robo to ignore specific UI widgets or all UI widgets on a particular screen. These instructions are represented as ignoring "actions" with eventType
ELEMENT_IGNORED
and ALL_ELEMENTS_IGNORED
correspondingly.
Whenever the contextDescriptor
attribute of a Robo script containing ignoring actions matches a given screen, Robo does not interact with any UI widgets targeted by its ignoring actions (unless some other Robo script action makes Robo perform an action on one of the ignored UI widgets).
A Robo script can contain a mix of ignoring, conditional, and non-conditional actions. Unlike other Robo script actions, ignoring actions are applied as long as their containing Robo script's contextDescriptor
matches a screen during a Robo crawl, regardless of the values of the priority
and maxNumberOfRuns
attributes.
The following is an example of a file with two Robo scripts. The first Robo script makes Robo ignore all UI widgets on a screen containing a UI widget with a resource ID "my.app.package:id/ignored_screen"
. The second Robo script makes Robo ignore UI widgets whose resource IDs match Java regex ".*:id/done"
on a screen containing a UI widget with a resource ID "my.app.package:id/main_screen"
:
[
{
"id": 1000,
"contextDescriptor": {
"condition": "element_present",
"elementDescriptors": [
{
"resourceId": "my.app.package:id/ignored_screen"
}
]
},
"actions": [
{
"eventType": "ALL_ELEMENTS_IGNORED"
}
]
},
{
"id": 1001,
"contextDescriptor": {
"condition": "element_present",
"elementDescriptors": [
{
"resourceId": "my.app.package:id/main_screen"
}
]
},
"actions": [
{
"eventType": "ELEMENT_IGNORED",
"elementDescriptors": [
{
"resourceIdRegex": ".*:id/done"
}
]
}
]
}
]
RecyclerView and AdapterView support
Children of RecyclerView and AdapterView widgets are loaded dynamically and might be displayed many swipes away from the current screen. Since the size of a screen, and the number of swipes required to get to this child, is different for different device form factors, it is much more robust to rely on the child's data position, which is absolute. It is a less robust approach to rely on the number of swipes that are required to bring this child to the screen and then use its screen position.
Therefore, Robo script captures the absolute data positions of RecyclerView children that are targets of Robo script actions as recyclerViewChildPosition
. Robo script also captures the absolute data positions of AdapterView children that are targets of Robo script actions as adapterViewChildPosition
.
Actions on RecyclerView and AdapterView children are performed in the following steps:
Robo test ensures that the corresponding child is displayed on the screen through a positioning action on its containing RecyclerView or AdapterView.
Robo test performs the recorded action directly on the child element, since it is already displayed on the screen.
The following is an example of a click action on an AdapterView ( android.widget.GridView
) child:
{
"eventType": "VIEW_CLICKED",
"elementDescriptors": [
{
"className": "com.google.samples.apps.topeka.widget.AvatarView",
"adapterViewChildPosition": 5,
"resourceId": "com.google.samples.apps.topeka:id/avatar",
"contentDescription": "Avatar 6"
},
{
"className": "android.widget.GridView",
"groupViewChildPosition": 1,
"resourceId": "com.google.samples.apps.topeka:id/avatars"
},
{
"className": "android.widget.LinearLayout",
"groupViewChildPosition": 1
},
{
"className": "android.widget.LinearLayout",
"groupViewChildPosition": 0
}
]
}
The following is an example of a click action on a RecyclerView ( android.support.v7.widget.RecyclerView
) child:
{
"eventType": "VIEW_CLICKED",
"elementDescriptors": [
{
"className": "android.support.v7.widget.AppCompatTextView",
"groupViewChildPosition": 1,
"resourceId": "com.google.samples.apps.topeka:id/category_title"
},
{
"className": "android.widget.FrameLayout",
"recyclerViewChildPosition": 8,
"resourceId": "com.google.samples.apps.topeka:id/category_item"
},
{
"className": "android.support.v7.widget.RecyclerView",
"groupViewChildPosition": 1,
"resourceId": "com.google.samples.apps.topeka:id/categories"
},
{
"className": "android.widget.FrameLayout",
"groupViewChildPosition": 1,
"resourceId": "com.google.samples.apps.topeka:id/category_container"
},
{
"className": "android.widget.LinearLayout",
"groupViewChildPosition": 0
}
]
}
Record a Robo script in Android Studio and run it in Test Lab
You can create a Robo script in Android Studio, which saves the script as a JSON file. You can then upload the JSON file to Firebase Test Lab with the application and run the test accordingly.
When you run a Robo test with a script attached, Robo test first steps through your pre-scripted actions and then explores the app as usual.
To create a Robo script JSON file in Android Studio, follow the steps in Record a Robo script using Test Lab in Android Studio .
Robo script actions
The following common optional attribute applies to all actions:
-
description
- helps track execution of this Robo script action in Robo test outputs.
Assertion
If the asserted condition is true, the Robo script continues to the next action, which could be another assertion. Otherwise, the Robo script execution is halted due to a failed assertion.
The following table lists required attributes:
Attribute | Description |
"eventType": "ASSERTION" | -- |
contextDescriptor | Describes the asserted context or condition. It has the same structure and offers similar capabilities as the Robo script's contextDescriptor . |
The following is an example of a Robo script assertion that checks that the app-under-test is in the foreground:
{
"eventType": "ASSERTION",
"contextDescriptor": {
"condition": "app_under_test_shown"
}
}
The following is an example of a Robo script assertion that checks that a UI widget with the resource ID "com.google.samples.apps.topeka:id/done"
is present on a screen:
{
"eventType": "ASSERTION",
"contextDescriptor": {
"condition": "element_present",
"elementDescriptors": [
{
"resourceId": "com.google.samples.apps.topeka:id/done"
}
]
}
}
The following is an example of a Robo script assertion that checks that "Settings"
is NOT detected on a screen using OCR:
{
"eventType": "ASSERTION",
"contextDescriptor": {
"condition": "element_present",
"negateCondition": true,
"visionText": "Settings"
}
}
Click
The following table lists required attributes:
Attribute | Description |
---|---|
eventType | Specifies the type of the Robo script action. |
"eventType": "VIEW_CLICKED" | Clicks the target element of the app-under-test. |
"eventType": "SOFT_KEYBOARD_CLICK" | Clicks the target element of the soft keyboard. |
"eventType": "SOFT_KEYBOARD_RANDOM_CLICK" | Clicks random elements of the soft keyboard up to maxNumberOfRuns times. |
"eventType": "LIST_ITEM_CLICKED" | Used by the Robo script recorder in Android Studio for clicking list items. |
elementDescriptors | Identifies the clicked UI widget using the Android UI hierarchy. Mutually exclusive with visionText . |
visionText | Identifies the clicked element using OCR. Mutually exclusive with elementDescriptors . |
maxNumberOfRuns | Specifies how many times to click a random element of the soft keyboard, when eventType is SOFT_KEYBOARD_RANDOM_CLICK . The default value is 1 . |
The following is an example of a Robo script action that clicks a button with the resource ID "com.google.samples.apps.topeka:id/done"
:
{
"eventType": "VIEW_CLICKED",
"elementDescriptors": [
{
"resourceId": "com.google.samples.apps.topeka:id/done"
}
]
}
The following is an example of a Robo script action that clicks on "Privacy Policy"
detected on a screen using OCR:
{
"eventType": "VIEW_CLICKED",
"visionText": "Privacy Policy"
}
The following is an example of a Robo script action that clicks a soft keyboard element with a content description "Emoji button"
:
{
"eventType": "SOFT_KEYBOARD_CLICK",
"elementDescriptors": [
{
"contentDescription": "Emoji button"
}
]
}
The following is an example of a Robo script action that clicks random soft keyboard elements up to five times:
{
"eventType": "SOFT_KEYBOARD_RANDOM_CLICK",
"maxNumberOfRuns": 5
}
Disable soft keyboard
The following table lists required attributes:
Attribute | Tanım |
"eventType": "DISABLE_KEYBOARD" | -- |
The following is an example of a Robo script action that disables the soft keyboard:
{
"eventType": "DISABLE_KEYBOARD"
}
Execute adb shell command
The following table lists required attributes:
Attribute | Tanım |
"eventType": "ADB_SHELL_COMMAND" | -- |
command | The Android Debug Bridge (adb) shell command to execute. |
The following is an example of a Robo script action that clears the app-under-test user data:
{
"eventType": "ADB_SHELL_COMMAND",
"command": "pm clear __%APP_PACKAGE_NAME%__"
}
Grant permissions
This action is recorded by the Robo script recorder in Android Studio for backward compatibility with Espresso Test Recorder . Robo test grants all permissions to the app-under-test at the beginning of every crawl, and thus, this action is a no-op. Do NOT use this action in your Robo scripts.
The following table lists required attributes:
Attribute | Tanım |
"eventType": "PERMISSIONS_REQUEST" | -- |
Ignore all elements on a screen
This action makes Robo ignore all elements on any screen that triggers the containing Robo script.
The following table lists required attributes:
Attribute | Tanım |
"eventType": "ALL_ELEMENTS_IGNORED" | -- |
The following is an example of a Robo script action that makes Robo ignore all elements on a screen:
{
"eventType": "ALL_ELEMENTS_IGNORED"
}
Ignore an element
This action makes Robo ignore an element (or elements) that match the specified elementDescriptors
.
The following table lists required attributes:
Attribute | Tanım |
"eventType": "ELEMENT_IGNORED" | -- |
elementDescriptors | Identifies the ignored UI widget(s) using the Android UI hierarchy. |
The following is an example of a Robo script action that makes Robo ignore all elements, whose content descriptions start with "Avatar"
:
{
"eventType": "ELEMENT_IGNORED",
"elementDescriptors": [
{
"contentDescriptionRegex": "Avatar.*"
}
]
}
Input text
The following table lists required attributes:
Attribute | Tanım |
---|---|
eventType | Specifies the type of the Robo script action. |
"eventType": "VIEW_TEXT_CHANGED" | Inputs the given text into the target UI widget. |
"eventType": "ENTER_TEXT" | inputs the given text into the target UI widget and then sends a KEYCODE_ENTER event to this UI widget. |
elementDescriptors | Identifies the target UI widget using the Android UI hierarchy. |
replacementText | The text to input into the target UI widget. |
The following is an example of a Robo script action that inputs "John"
into a UI widget with the resource ID "com.google.samples.apps.topeka:id/first_name"
:
{
"eventType": "VIEW_TEXT_CHANGED",
"replacementText": "John",
"elementDescriptors": [
{
"resourceId": "com.google.samples.apps.topeka:id/first_name"
}
]
}
Long click
The following table lists required attributes:
Attribute | Tanım |
"eventType": "VIEW_LONG_CLICKED" | -- |
elementDescriptors | Identifies the target UI widget using the Android UI hierarchy. |
The following attribute is optional:
-
delayTime
- specifies how long the press down of a long click lasts, in milliseconds.
The following is an example of a Robo script action that performs a five seconds-long click on a UI widget with content description "Avatar 8"
:
{
"eventType": "VIEW_LONG_CLICKED",
"elementDescriptors": [
{
"contentDescription": "Avatar 8"
}
],
"delayTime": 5000
}
Perform a one-point gesture
The following table lists required attributes:
Attribute | Tanım |
---|---|
"eventType": "ONE_POINT_GESTURE" | -- |
coordinates | Two coordinates for a one-point gesture, formatted as "(x1,y1)->(x2,y2)" as percentages or pixels. |
The following attribute is optional:
-
dragAndDrop
- if set totrue
, the one-point gesture performs a drag-and-drop action. By default, it isfalse
.
The following is an example of a Robo script one-point gesture action that performs a swipe down:
{
"eventType": "ONE_POINT_GESTURE",
"coordinates": "(50%,25%)->(50%,75%)"
}
Perform a two-point gesture
The following table lists required attributes:
Attribute | Tanım |
---|---|
"eventType": "TWO_POINT_GESTURE" | -- |
coordinates | Four coordinates for a two-point gesture, formatted as "(x1,y1)->(x2,y2),(x3,y3)->(x4,y4)" as percentages or pixels. |
The following is an example of a Robo script action that performs a pinch out gesture:
{
"eventType": "TWO_POINT_GESTURE",
"coordinates": "(50%,50%)->(25%,50%),(50%,50%)->(75%,50%)"
}
Perform an IME action
This action presses the current action button, for example, next, done, and search, on the Input Method Editor (IME) for the specified target UI widget.
The following table lists required attributes:
Attribute | Tanım |
---|---|
"eventType": "PRESSED_EDITOR_ACTION" | -- |
elementDescriptors | Identifies the target UI widget using the Android UI hierarchy. |
The following is an example of a Robo script action that performs an IME action on a UI widget with the resource ID "com.google.samples.apps.topeka:id/first_name"
:
{
"eventType": "PRESSED_EDITOR_ACTION",
"elementDescriptors": [
{
"resourceId": "com.google.samples.apps.topeka:id/first_name"
}
]
}
Press back
The following table lists required attributes:
Attribute | Tanım |
eventType | Specifies the type of the Robo script action. |
"eventType": "PRESSED_BACK" | Sends a KEYCODE_BACK event to the device. |
"eventType": "PRESSED_BACK_EMULATOR_28" | Used by the Robo script recorder in Android Studio for pressing back on emulators API 28. |
The following is an example of a Robo script action that presses back:
{
"eventType": "PRESSED_BACK"
}
Press home
This action sends a KEYCODE_HOME
event to the device.
The following table lists required attributes:
Attribute | Tanım |
"eventType": "GO_HOME" | -- |
The following is an example of a Robo script action that presses home:
{
"eventType": "GO_HOME"
}
Scroll an element into view
This action makes Robo test scroll forward the UI widget that matches the specified elementDescriptors
until the UI widget that matches the specified childElementDescriptors
is present on the screen, or the scrolled widget can no longer be scrolled, or the max number of 50 scrolls is reached.
The following table lists required attributes:
Attribute | Tanım |
"eventType": "ELEMENT_SCROLL_INTO_VIEW" | -- |
elementDescriptors | Identifies the scrolled UI widget using the Android UI hierarchy. |
childElementDescriptors | Identifies the UI widget to scroll to using the Android UI hierarchy. |
The following is an example of a Robo script action that scrolls the UI widget with the resource ID "my.app.package:id/scrollable_card_container"
until the UI widget with text "Orange"
is present on the screen (or no more scrolls can be performed, or the max number of 50 scrolls is reached):
{
"eventType": "ELEMENT_SCROLL_INTO_VIEW",
"elementDescriptors": [
{
"resourceId": "my.app.package:id/scrollable_card_container"
}
],
"childElementDescriptors": [
{
"text": "Orange"
}
]
}
Swipe
The following table lists required attributes:
Attribute | Tanım |
---|---|
"eventType": "VIEW_SWIPED" | -- |
swipeDirection | Specifies the direction of the swipe:
|
elementDescriptors | Identifies the target UI widget using the Android UI hierarchy. |
The following is an example of a Robo script action that swipes up a UI widget with the resource ID "my.app.package:id/custom_content"
:
{
"eventType": "VIEW_SWIPED",
"swipeDirection": "Up",
"elementDescriptors": [
{
"resourceId": "my.app.package:id/custom_content"
}
]
}
Take screenshot
The following table lists required attributes:
Attribute | Tanım |
"eventType": "TAKE_SCREENSHOT" | -- |
screenshotName | Specifies the screenshot file name. |
The following is an example of a Robo script action that takes a screenshot:
{
"eventType": "TAKE_SCREENSHOT",
"screenshotName": "my_screenshot"
}
Tap a point on the screen
The following table lists required attributes:
Attribute | Tanım |
---|---|
"eventType": "POINT_TAP" | -- |
pointTapXCoordinate | The pixel X coordinate of the tapped point. Mutually exclusive with pointTapXPercent and pointTapYPercent . |
pointTapYCoordinate | The pixel Y coordinate of the tapped point. Mutually exclusive with pointTapXPercent and pointTapYPercent . |
pointTapXPercent | The percentage X coordinate of the tapped point. Mutually exclusive with pointTapXCoordinate and pointTapYCoordinate . |
pointTapYPercent | The percentage Y coordinate of the tapped point. Mutually exclusive with pointTapXCoordinate and pointTapYCoordinate . |
The following is an example of a Robo script action that taps in the middle of a screen:
{
"eventType": "POINT_TAP",
"pointTapXPercent": 50,
"pointTapYPercent": 50
}
Tap a point within an element
The following table lists required attributes:
Attribute | Tanım |
"eventType": "POINT_TAP_ELEMENT" | -- |
pointTapXPercent | The percentage X coordinate within the target element. |
pointTapYPercent | The percentage Y coordinate within the target element. |
elementDescriptors | Identifies the target UI widget using Android UI hierarchy. |
The following is an example of a Robo script action that moves a seekbar's slider to the right:
{
"eventType": "POINT_TAP_ELEMENT",
"pointTapXPercent": 80,
"pointTapYPercent": 50,
"elementDescriptors": [
{
"resourceId": "my.app.package:id/my_seekbar"
}
]
}
Terminate crawl
This action stops the Robo test.
The following table lists required attributes:
Attribute | Tanım |
---|---|
"eventType": "TERMINATE_CRAWL" | -- |
The following is an example of a Robo script action that stops a Robo test:
{
"eventType": "TERMINATE_CRAWL"
}
Wait
The following table lists required attributes:
Attribute | Tanım |
"eventType": "DELAYED_MESSAGE_POSTED" | -- |
delayTime | Specifies how long to wait, in milliseconds. |
The following is an example of a Robo script action that waits for three seconds:
{
"eventType": "DELAYED_MESSAGE_POSTED",
"delayTime": 3000
}
Wait for an element
This action makes Robo test wait for an element to appear on the screen up to the specified timeout.
The following table lists required attributes:
Attribute | Tanım |
"eventType": "WAIT_FOR_ELEMENT" | -- |
delayTime | Specifies the waiting timeout, in milliseconds. |
elementDescriptors | Identifies the waited-for UI widget using the Android UI hierarchy. |
The following is an example of a Robo script action that waits for up to 30 seconds for a UI widget with the resource ID "my.app.package:id/confirmation_button"
to appear on the screen:
{
"eventType": "WAIT_FOR_ELEMENT",
"delayTime": 30000,
"elementDescriptors": [
{
"resourceId": "my.app.package:id/confirmation_button"
}
]
}