Skip to content

Commit

Permalink
Add Sauce Visual example
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerem Beygo committed Oct 24, 2024
1 parent aa4232f commit 61602ef
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ android {

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments clearPackageData: 'true'

buildConfigField "String", "SAUCE_USERNAME", getProperty("SAUCE_USERNAME", "\"\"")
buildConfigField "String", "SAUCE_ACCESS_KEY", getProperty("SAUCE_ACCESS_KEY", "\"\"")
}

testOptions {
Expand Down Expand Up @@ -61,6 +64,15 @@ android {
}
}

String getProperty(String name, String defaultValue) {
if (!rootProject.file("./local.properties").exists()) {
return defaultValue
}
def properties = new Properties()
properties.load(rootProject.file("./local.properties").newDataInputStream())
return properties.containsKey(name) ? properties[name] : defaultValue
}

task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'createDebugCoverageReport']) {

reports {
Expand Down Expand Up @@ -90,6 +102,7 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

//Libraries For Testing
androidTestImplementation 'com.saucelabs.visual:visual-espresso:0.0.1'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.4.0'
androidTestImplementation("com.android.support.test.espresso:espresso-contrib:3.0.2")
androidTestImplementation 'androidx.test:runner:1.4.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package com.saucelabs.mydemoapp.android.view.activities;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.action.ViewActions.closeSoftKeyboard;
import static androidx.test.espresso.action.ViewActions.typeText;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;

import android.text.TextUtils;

import androidx.test.espresso.ViewAction;
import androidx.test.espresso.contrib.RecyclerViewActions;
import androidx.test.ext.junit.rules.ActivityScenarioRule;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.LargeTest;
import androidx.test.platform.app.InstrumentationRegistry;

import com.saucelabs.mydemoapp.android.BaseTest;
import com.saucelabs.mydemoapp.android.BuildConfig;
import com.saucelabs.mydemoapp.android.R;
import com.saucelabs.mydemoapp.android.actions.NestingAwareScrollAction;
import com.saucelabs.mydemoapp.android.actions.SideNavClickAction;
import com.saucelabs.visual.VisualClient;
import com.saucelabs.visual.junit.TestMetaInfoRule;

import org.junit.AfterClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

@LargeTest
@RunWith(AndroidJUnit4.class)
public class VisualTest extends BaseTest {

private final ViewAction scroll = new NestingAwareScrollAction();

@Rule
public ActivityScenarioRule<SplashActivity> activityRule = new ActivityScenarioRule<>(SplashActivity.class);

@Rule
public TestMetaInfoRule testMetaInfoRule = new TestMetaInfoRule();

static VisualClient client = VisualClient.builder(BuildConfig.SAUCE_USERNAME, BuildConfig.SAUCE_ACCESS_KEY)
.buildName("My Demo App")
.build();

@Test
public void checkAppCatalog() {

waitView(withId(R.id.menuIV));

client.sauceVisualCheck("Startup");

onView(withId(R.id.menuIV))
.perform(click());

waitView(withId(R.id.menuRV));

onView(withId(R.id.menuRV))
.perform(RecyclerViewActions.scrollToPosition(10))
.perform(RecyclerViewActions.actionOnItemAtPosition(10, new SideNavClickAction()));

String visualCheck = InstrumentationRegistry.getArguments().getString("visualCheck", "");
String name = TextUtils.isEmpty(visualCheck) ? "[email protected]" : "[email protected]";
String pass = "10203040";

// enter a name
onView(withId(R.id.nameET)).perform(typeText(name), closeSoftKeyboard());
onView(withId(R.id.passwordET)).perform(typeText(pass), closeSoftKeyboard());

onView(withId(R.id.nameET)).check(matches(withText(name)));
onView(withId(R.id.passwordET)).check(matches(withText(pass)));

onView(withId(R.id.loginBtn))
.perform(scroll)
.perform(click());

waitView(withId(R.id.menuIV));

client.sauceVisualCheck("App Catalog");

onView(withId(R.id.menuIV)).check(matches(isDisplayed()));
}

@AfterClass
public static void tearDown() {
client.finish();
}
}

0 comments on commit 61602ef

Please sign in to comment.