Skip to content

Instantly share code, notes, and snippets.

@nakov
Created March 26, 2021 17:42
Show Gist options
  • Save nakov/992f0ec0d85478e6fe8181b9cfcf3160 to your computer and use it in GitHub Desktop.
Save nakov/992f0ec0d85478e6fe8181b9cfcf3160 to your computer and use it in GitHub Desktop.
Appium Test for the ContactBook app
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Android;
using OpenQA.Selenium.Remote;
using System;
namespace AppiumTests_ContactBook
{
public class TestsContactBookAndroidApp
{
const string AppPathAndName = @"D:\INSTALL\contactbook-androidclient.apk";
const string AppiumUrl = "http://[::1]:4723/wd/hub";
const string ContactBookApiUrl = "https://contactbook.nakov.repl.co/api";
RemoteWebDriver driver;
[SetUp]
public void Setup()
{
var options = new AppiumOptions() { PlatformName = "Android" };
options.AddAdditionalCapability("app", AppPathAndName);
driver = new AndroidDriver<AndroidElement>(new Uri(AppiumUrl), options);
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
}
[Test]
public void TestContactBookSearch()
{
var contactBookUrl = driver.FindElement(By.Id(
"contactbook.androidclient:id/editTextApiUrl"));
contactBookUrl.Clear();
contactBookUrl.SendKeys(ContactBookApiUrl);
var connectButton = driver.FindElement(By.Id(
"contactbook.androidclient:id/buttonConnect"));
connectButton.Click();
var keywordTextBox = driver.FindElement(By.Id(
"contactbook.androidclient:id/editTextKeyword"));
keywordTextBox.Clear();
keywordTextBox.SendKeys("albert");
var connectSearch = driver.FindElement(By.Id(
"contactbook.androidclient:id/buttonSearch"));
connectSearch.Click();
var firstNameTextBox = driver.FindElement(By.Id(
"contactbook.androidclient:id/textViewFirstName"));
var lastNameTextBox = driver.FindElement(By.Id(
"contactbook.androidclient:id/textViewLastName"));
Assert.AreEqual("Albert", firstNameTextBox.Text);
Assert.AreEqual("Einstein", lastNameTextBox.Text);
}
[TearDown]
public void TearDown()
{
driver.Quit();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment