Skip to content

Instantly share code, notes, and snippets.

@backmeupplz
Created May 7, 2020 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save backmeupplz/3fd161a4cd202bc80ca293010cb9e1fc to your computer and use it in GitHub Desktop.
Save backmeupplz/3fd161a4cd202bc80ca293010cb9e1fc to your computer and use it in GitHub Desktop.
Todorant screengrab test
package com.todorant;
import androidx.test.filters.LargeTest;
import androidx.test.rule.ActivityTestRule;
import org.junit.Rule;
import org.junit.ClassRule;
import org.junit.Test;
import tools.fastlane.screengrab.Screengrab;
import tools.fastlane.screengrab.UiAutomatorScreenshotStrategy;
import tools.fastlane.screengrab.locale.LocaleTestRule;
import tools.fastlane.screengrab.locale.LocaleUtil;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withContentDescription;
import static androidx.test.espresso.matcher.ViewMatchers.withTagValue;
import static org.hamcrest.CoreMatchers.allOf;
import static org.hamcrest.Matchers.is;
@LargeTest
public class AppTest {
@ClassRule
public static final LocaleTestRule localeTestRule = new LocaleTestRule();
@Rule
public ActivityTestRule<MainActivity> mActivityTestRule = new ActivityTestRule<>(MainActivity.class);
@Test
public void appTest() {
Screengrab.setDefaultScreenshotStrategy(new UiAutomatorScreenshotStrategy());
try { Thread.sleep(25000); } catch (InterruptedException e) {}
if (LocaleUtil.getTestLocale().getLanguage().equals("ru")) {
onView(allOf(withContentDescription("Настройки, tab, 3 of 3"), isDisplayed())).perform(click());
try { Thread.sleep(2000); } catch (InterruptedException e) {}
onView(withTagValue(is("delete"))).perform(click());
try { Thread.sleep(2000); } catch (InterruptedException e) {}
onView(withTagValue(is("add_ru"))).perform(click());
try { Thread.sleep(8000); } catch (InterruptedException e) {}
onView(allOf(withContentDescription("Текущее, tab, 1 of 3"), isDisplayed())).perform(click());
Screengrab.screenshot("1Current");
try { Thread.sleep(2000); } catch (InterruptedException e) {}
onView(allOf(withContentDescription("Планирование, tab, 2 of 3"), isDisplayed())).perform(click());
try { Thread.sleep(2000); } catch (InterruptedException e) {}
Screengrab.screenshot("2Planning");
onView(allOf(withContentDescription("Настройки, tab, 3 of 3"), isDisplayed())).perform(click());
try { Thread.sleep(2000); } catch (InterruptedException e) {}
onView(withTagValue(is("delete"))).perform(click());
try { Thread.sleep(2000); } catch (InterruptedException e) {}
onView(allOf(withContentDescription("Текущее, tab, 1 of 3"), isDisplayed())).perform(click());
try { Thread.sleep(2000); } catch (InterruptedException e) {}
Screengrab.screenshot("0Empty");
} else if (LocaleUtil.getTestLocale().getLanguage().equals("uk")) {
<...>
} else if (LocaleUtil.getTestLocale().getLanguage().equals("it")) {
<...>
} else {
onView(allOf(withContentDescription("Settings, tab, 3 of 3"), isDisplayed())).perform(click());
try { Thread.sleep(2000); } catch (InterruptedException e) {}
onView(withTagValue(is("delete"))).perform(click());
try { Thread.sleep(2000); } catch (InterruptedException e) {}
onView(withTagValue(is("add_en"))).perform(click());
try { Thread.sleep(8000); } catch (InterruptedException e) {}
onView(allOf(withContentDescription("Current, tab, 1 of 3"), isDisplayed())).perform(click());
Screengrab.screenshot("1Current");
try { Thread.sleep(2000); } catch (InterruptedException e) {}
onView(allOf(withContentDescription("Planning, tab, 2 of 3"), isDisplayed())).perform(click());
try { Thread.sleep(3000); } catch (InterruptedException e) {}
Screengrab.screenshot("2Planning");
onView(allOf(withContentDescription("Settings, tab, 3 of 3"), isDisplayed())).perform(click());
try { Thread.sleep(2000); } catch (InterruptedException e) {}
onView(withTagValue(is("delete"))).perform(click());
try { Thread.sleep(2000); } catch (InterruptedException e) {}
onView(allOf(withContentDescription("Current, tab, 1 of 3"), isDisplayed())).perform(click());
try { Thread.sleep(2000); } catch (InterruptedException e) {}
Screengrab.screenshot("0Empty");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment