This repository was archived by the owner on Sep 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
Setup UIAutomator2 Tests #594
Open
sharath-os
wants to merge
1
commit into
ghostery:master
Choose a base branch
from
sharath-os:UIA2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,6 +52,7 @@ buildscript { | |
| url repository | ||
| } | ||
| } | ||
| google() | ||
| } | ||
|
|
||
| ext.kotlin_version = '1.2.41' | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 8 additions & 3 deletions
11
mozilla-release/mobile/android/app/src/androidTest/AndroidManifest.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
mozilla-release/mobile/android/tests/cliqz/java/com/cliqz/mobile/test/CliqzRunner.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| package com.cliqz.mobile.test; | ||
|
|
||
| import android.util.Log; | ||
|
|
||
| import org.junit.Ignore; | ||
| import org.junit.internal.AssumptionViolatedException; | ||
| import org.junit.internal.runners.model.EachTestNotifier; | ||
| import org.junit.runner.Description; | ||
| import org.junit.runner.notification.RunNotifier; | ||
| import org.junit.runner.notification.StoppedByUserException; | ||
| import org.junit.runners.BlockJUnit4ClassRunner; | ||
| import org.junit.runners.model.FrameworkMethod; | ||
| import org.junit.runners.model.InitializationError; | ||
| import org.junit.runners.model.Statement; | ||
|
|
||
| /** | ||
| * Copyright © Cliqz 2019 | ||
| */ | ||
| public class CliqzRunner extends BlockJUnit4ClassRunner { | ||
|
|
||
| private static final int RETRY_COUNT = 2; | ||
|
|
||
| public CliqzRunner(Class<?> clazz) throws InitializationError { | ||
| super(clazz); | ||
| } | ||
|
|
||
| @Override | ||
| public void run(final RunNotifier notifier) { | ||
| final EachTestNotifier testNotifier = new EachTestNotifier(notifier, getDescription()); | ||
| Statement statement = classBlock(notifier); | ||
| try { | ||
| statement.evaluate(); | ||
| } catch (AssumptionViolatedException ave) { | ||
| testNotifier.fireTestIgnored(); | ||
| } catch (StoppedByUserException sbue) { | ||
| throw sbue; | ||
| } catch (Throwable t) { | ||
| Log.w("AUTOBOTS", "Retry class: " + getDescription().getDisplayName()); | ||
| retry(testNotifier, statement, t, getDescription()); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| protected void runChild(final FrameworkMethod method, RunNotifier notifier) { | ||
| final Description description = describeChild(method); | ||
| if (method.getAnnotation(Ignore.class) != null) { | ||
| notifier.fireTestIgnored(description); | ||
| } else { | ||
| runTest(methodBlock(method), description, notifier); | ||
| } | ||
| } | ||
|
|
||
| private void runTest(Statement statement, Description description, RunNotifier notifier) { | ||
| final EachTestNotifier eachNotifier = new EachTestNotifier(notifier, description); | ||
| eachNotifier.fireTestStarted(); | ||
| try { | ||
| statement.evaluate(); | ||
| } catch (AssumptionViolatedException e) { | ||
| eachNotifier.addFailedAssumption(e); | ||
| } catch (Throwable e) { | ||
| Log.w("AUTOBOTS", "Retry test: " + description.getDisplayName()); | ||
| retry(eachNotifier, statement, e, description); | ||
| } finally { | ||
| eachNotifier.fireTestFinished(); | ||
| } | ||
| } | ||
|
|
||
| private void retry(EachTestNotifier notifier, Statement statement, Throwable currentThrowable, Description info) { | ||
| int failedAttempts = 0; | ||
| Throwable caughtThrowable = currentThrowable; | ||
| while (RETRY_COUNT > failedAttempts) { | ||
| try { | ||
| notifier.fireTestIgnored(); | ||
| notifier.fireTestStarted(); | ||
| Log.w("AUTOBOTS", "Retry attempt " + (failedAttempts + 1) + " for " + info.getDisplayName()); | ||
| statement.evaluate(); | ||
| notifier.fireTestFinished(); | ||
| return; | ||
| } catch (Throwable t) { | ||
| failedAttempts++; | ||
| caughtThrowable = t; | ||
| } | ||
| } | ||
| Log.e("AUTOBOTS", caughtThrowable.getMessage()); | ||
| notifier.addFailure(caughtThrowable); | ||
| } | ||
| } | ||
41 changes: 41 additions & 0 deletions
41
...lla-release/mobile/android/tests/cliqz/java/com/cliqz/mobile/test/driver/ElementData.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package com.cliqz.mobile.test.driver; | ||
|
|
||
| import android.support.test.uiautomator.UiObject2; | ||
| import android.util.Log; | ||
|
|
||
| /** | ||
| * Copyright © Cliqz 2019 | ||
| */ | ||
| public class ElementData { | ||
|
|
||
| private UiObject2 element; | ||
| private boolean exists; | ||
| private boolean checked; | ||
| private boolean enabled; | ||
| private boolean focused; | ||
| private boolean selected; | ||
| private String text; | ||
| private String description; | ||
|
|
||
|
|
||
| public ElementData(UiObject2 elem) { | ||
| element = elem; | ||
| try { | ||
| exists = element.getResourceName()!=null; | ||
| text = element.getText(); | ||
| description = element.getContentDescription(); | ||
| checked = element.isChecked(); | ||
| enabled = element.isEnabled(); | ||
| focused = element.isFocused(); | ||
| selected = element.isSelected(); | ||
| } catch (Exception e) { | ||
| Log.w("AUTOBOTS", e.toString()); | ||
| } | ||
| } | ||
|
|
||
| public boolean hasChanged() { | ||
| ElementData tempData = new ElementData(element); | ||
| return this != tempData; | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.