diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..92275db --- /dev/null +++ b/.gitignore @@ -0,0 +1,405 @@ +# globs +Makefile.in +*.userprefs +*.usertasks +config.make +config.status +aclocal.m4 +install-sh +autom4te.cache/ +*.tar.gz +tarballs/ +test-results/ + +# Mac bundle stuff +*.dmg +*.app + +# content below from: https://github.com/github/gitignore/blob/main/Global/macOS.gitignore +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# content below from: https://github.com/github/gitignore/blob/main/Global/Windows.gitignore +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# content below from: https://github.com/github/gitignore/blob/master/VisualStudio.gitignore +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ \ No newline at end of file diff --git a/Android/.config/dotnet-tools.json b/Android/.config/dotnet-tools.json new file mode 100644 index 0000000..f4f780d --- /dev/null +++ b/Android/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "browserstack-sdk": { + "version": "1.13.8", + "commands": [ + "browserstack-sdk" + ] + } + } +} \ No newline at end of file diff --git a/Android/Android.csproj b/Android/Android.csproj new file mode 100644 index 0000000..d346595 --- /dev/null +++ b/Android/Android.csproj @@ -0,0 +1,24 @@ + + + + net6.0 + enable + enable + + false + true + + + + + + + + + + + + + + + diff --git a/Android/BrowserstackMSTest.cs b/Android/BrowserstackMSTest.cs new file mode 100644 index 0000000..6fc4a3e --- /dev/null +++ b/Android/BrowserstackMSTest.cs @@ -0,0 +1,23 @@ +namespace Android; + +public class BrowserstackMSTest +{ + public AndroidDriver? driver; + + public BrowserstackMSTest() { } + + [TestInitialize] + public void TestSetup() + { + AppiumOptions appiumOptions = new AppiumOptions(); + driver = new AndroidDriver(new Uri("http://127.0.0.1:4723/wd/hub"), appiumOptions); + } + + [TestCleanup] + public void TestTeardown() + { + if (driver != null) + driver.Quit(); + } +} + diff --git a/Android/LocalSample.apk b/Android/LocalSample.apk new file mode 100644 index 0000000..f31c574 Binary files /dev/null and b/Android/LocalSample.apk differ diff --git a/Android/LocalTest.cs b/Android/LocalTest.cs new file mode 100644 index 0000000..3049459 --- /dev/null +++ b/Android/LocalTest.cs @@ -0,0 +1,38 @@ +using OpenQA.Selenium; +using OpenQA.Selenium.Support.UI; +using System.Collections.ObjectModel; + +namespace Android; + +[TestClass] +public class LocalTest : BrowserstackMSTest +{ + + public LocalTest() { } + + [TestMethod] + public void LocalNetworkTest() + { + if (driver == null) + throw new Exception("Could not run tests. Driver not initialised"); + + var _ = driver.PageSource; + var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30)); + + var testActionId = By.Id("com.example.android.basicnetworking:id/test_action"); + AndroidElement testActionElement = (AndroidElement)wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(testActionId)); + testActionElement.Click(); + Thread.Sleep(5000); + + _ = driver.PageSource; + + ReadOnlyCollection textviewElements = driver.FindElementsByClassName("android.widget.TextView"); + string text = textviewElements.Last().Text; + + Assert.IsTrue(text.Contains("The active connection is wifi")); + Assert.IsTrue(text.Contains("Up and running")); + + driver.ExecuteScript("browserstack_executor: { \"action\": \"setSessionStatus\", \"arguments\": { \"status\": \"passed\", \"reason\": \"Test Passed!\"} }"); + } +} + diff --git a/Android/SingleTest.cs b/Android/SingleTest.cs new file mode 100644 index 0000000..b69c475 --- /dev/null +++ b/Android/SingleTest.cs @@ -0,0 +1,39 @@ +using System.Collections.ObjectModel; +using OpenQA.Selenium; +using OpenQA.Selenium.Support.UI; + +namespace Android; + +[TestClass] +public class SingleTest : BrowserstackMSTest +{ + public SingleTest() { } + + [TestMethod] + public void SearchTest() + { + if (driver == null) + throw new Exception("Could not run tests. Driver not initialised"); + + var _ = driver.PageSource; + var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30)); + + var searchElementId = MobileBy.AccessibilityId("Search Wikipedia"); + AndroidElement searchElement = (AndroidElement)wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(searchElementId)); + searchElement.Click(); + Thread.Sleep(2000); + + _ = driver.PageSource; + + wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30)); + var insertTextElementId = By.Id("org.wikipedia.alpha:id/search_src_text"); + AndroidElement insertTextElement = (AndroidElement)wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(insertTextElementId)); + insertTextElement.SendKeys("BrowserStack"); + Thread.Sleep(5000); + + ReadOnlyCollection allProductsName = driver.FindElements(By.ClassName("android.widget.TextView")); + Assert.IsTrue(allProductsName.Count > 0); + + driver.ExecuteScript("browserstack_executor: { \"action\": \"setSessionStatus\", \"arguments\": { \"status\": \"passed\", \"reason\": \"Test Passed!\"} }"); + } +} diff --git a/Android/Usings.cs b/Android/Usings.cs new file mode 100644 index 0000000..590e8ef --- /dev/null +++ b/Android/Usings.cs @@ -0,0 +1,3 @@ +global using Microsoft.VisualStudio.TestTools.UnitTesting; +global using OpenQA.Selenium.Appium; +global using OpenQA.Selenium.Appium.Android; \ No newline at end of file diff --git a/Android/WikipediaSample.apk b/Android/WikipediaSample.apk new file mode 100644 index 0000000..03d19e6 Binary files /dev/null and b/Android/WikipediaSample.apk differ diff --git a/Android/browserstack.yml b/Android/browserstack.yml new file mode 100644 index 0000000..1306382 --- /dev/null +++ b/Android/browserstack.yml @@ -0,0 +1,69 @@ +# ============================= +# Set BrowserStack Credentials +# ============================= +# Add your BrowserStack userName and acccessKey here or set BROWSERSTACK_USERNAME and +# BROWSERSTACK_ACCESS_KEY as env variables +userName: BROWSERSTACK_USERNAME +accessKey: BROWSERSTACK_ACCESS_KEY + +# ====================== +# BrowserStack Reporting +# ====================== +# The following capabilities are used to set up reporting on BrowserStack: +# Set 'projectName' to the name of your project. Example, Marketing Website +projectName: BrowserStack Samples +# Set `name` to set the session name +name: BStack android test +# Set `buildName` as the name of the job / testsuite being run +buildName: browserstack build +# `buildIdentifier` is a unique id to differentiate every execution that gets appended to +# buildName. Choose your buildIdentifier format from the available expressions: +# ${BUILD_NUMBER} (Default): Generates an incremental counter with every execution +# ${DATE_TIME}: Generates a Timestamp with every execution. Eg. 05-Nov-19:30 +# Read more about buildIdentifiers here -> https://www.browserstack.com/docs/automate/selenium/organize-tests +buildIdentifier: '#${BUILD_NUMBER}' # Supports strings along with either/both ${expression} + +source: mstest:appium-sample-sdk:v1.0 + +# Set `app` to define the app that is to be used for testing. +# It can either take the id of any uploaded app or the path of the app directly. +app: ./WikipediaSample.apk +# app: ./LocalSample.apk #For running local tests + +# ======================================= +# Platforms (Browsers / Devices to test) +# ======================================= +# Platforms object contains all the browser / device combinations you want to test on. +# Entire list available here -> (https://www.browserstack.com/list-of-browsers-and-platforms/automate) + +platforms: + - deviceName: Samsung Galaxy S22 Ultra + osVersion: 12.0 + platformName: android + - deviceName: OnePlus 11R + osVersion: 13.0 + platformName: android + - deviceName: Google Pixel 6 Pro + osVersion: 12.0 + platformName: android + +# ========================================== +# BrowserStack Local +# (For localhost, staging/private websites) +# ========================================== +# Set browserStackLocal to true if your website under test is not accessible publicly over the internet +# Learn more about how BrowserStack Local works here -> https://www.browserstack.com/docs/automate/selenium/local-testing-introduction +browserstackLocal: true # (Default false) +#browserStackLocalOptions: +#Options to be passed to BrowserStack local in-case of advanced configurations +# localIdentifier: # (Default: null) Needed if you need to run multiple instances of local. +# forceLocal: true # (Default: false) Set to true if you need to resolve all your traffic via BrowserStack Local tunnel. +# Entire list of arguments available here -> https://www.browserstack.com/docs/automate/selenium/manage-incoming-connections + +# =================== +# Debugging features +# =================== +debug: false # # Set to true if you need screenshots for every selenium command ran +networkLogs: false # Set to true to enable HAR logs capturing +consoleLogs: errors # Remote browser's console debug levels to be printed (Default: errors) +# Available options are `disable`, `errors`, `warnings`, `info`, `verbose` (Default: errors) \ No newline at end of file diff --git a/README.md b/README.md index 54c6229..9aa85aa 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,80 @@ -# mstest-appium-app-browserstack -Sample Repo for running Appium Sessions using MSTest Framework +# MSTest-appium-app-browserstack + +This sample elaborates the [MSTest](https://docs.microsoft.com/en-us/dotnet/core/testing/unit-testing-with-mstest) Integration with BrowserStack. + + + +Note: SDK Support for MSTest Framework only works on Windows. + +## Setup + +### Installation Steps + +1. Clone the repository. +2. Open the solution `mstest-appium-app-browserstack.sln` in Visual Studio. +3. Install dependencies using NuGet Package Manager: + ```bash + dotnet restore + ``` +4. Build the solution + +### Setup + +1. Add your BrowserStack Username and Access Key to the `browserstack.yml` files in the Android/iOS project. You can get your browserstack credentials from [here](https://www.browserstack.com/accounts/profile/details) + ```yml + userName: BROWSERSTACK_USERNAME + accessKey: BROWSERSTACK_ACCESS_KEY + ``` + +2. Provide the path to your apk/ipa file in `browserstack.yml`. + ```yml + app: ./WikipediaSample.apk + ``` + +3. To run your test on multiple devices, update the devices list in `browserstack.yml`. + ```yml + platforms: + - deviceName: Samsung Galaxy S22 Ultra + osVersion: 12.0 + platformName: android + ``` + +4. To run your tests using Browserstack Local. Update the `browserstack.yml` with the following key: + ```yml + browserstackLocal: true # (Default false) + ``` + +### Running Tests + +- To run tests, execute the following command: + ```bash + dotnet test + ``` + +- To run tests on Android/iOS, provide `` to the below command. Where os can take either of two values: `Android` or `iOS`. + ```bash + dotnet test + ``` + +- To run the single test, execute the following command: + ```bash + dotnet test --filter SingleTest + ``` + +- To run local tests, execute the following command: + ```bash + dotnet test --filter LocalTest + ``` + +Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/app-automate/parallel-calculator?ref=github) + +## Notes +* You can view your test results on the [BrowserStack automate dashboard](https://www.browserstack.com/app-automate) +* To test on a different set of devices or build a set of appium capabilities, use our [Capability Builder](https://www.browserstack.com/app-automate/capabilities?tag=w3c) + +## Additional Resources +* [Documentation for writing automate playwright test scripts in C#](https://www.browserstack.com/docs/app-automate/appium/getting-started/c-sharp) +* [Capability Builder for App Automate](https://www.browserstack.com/app-automate/capabilities) +* [Real Mobile devices for Appium testing on BrowserStack](https://www.browserstack.com/list-of-browsers-and-platforms/app_automate) +* [Using REST API to access information about your tests via the command-line interface](https://www.browserstack.com/docs/app-automate/api-reference/introduction) + diff --git a/assets/MSTest.png b/assets/MSTest.png new file mode 100644 index 0000000..3d58b06 Binary files /dev/null and b/assets/MSTest.png differ diff --git a/assets/browserstack.png b/assets/browserstack.png new file mode 100644 index 0000000..042235b Binary files /dev/null and b/assets/browserstack.png differ diff --git a/iOS/.config/dotnet-tools.json b/iOS/.config/dotnet-tools.json new file mode 100644 index 0000000..517f9b3 --- /dev/null +++ b/iOS/.config/dotnet-tools.json @@ -0,0 +1,5 @@ +{ + "version": 1, + "isRoot": true, + "tools": {} +} \ No newline at end of file diff --git a/iOS/BStackSampleApp.ipa b/iOS/BStackSampleApp.ipa new file mode 100644 index 0000000..c1891b8 Binary files /dev/null and b/iOS/BStackSampleApp.ipa differ diff --git a/iOS/BrowserstackMSTest.cs b/iOS/BrowserstackMSTest.cs new file mode 100644 index 0000000..55aa9e5 --- /dev/null +++ b/iOS/BrowserstackMSTest.cs @@ -0,0 +1,23 @@ +namespace iOS; + +public class BrowserstackMSTest +{ + protected IOSDriver? driver; + + public BrowserstackMSTest() { } + + [TestInitialize] + public void TestSetup() + { + AppiumOptions appiumOptions = new AppiumOptions(); + driver = new IOSDriver(new Uri("http://127.0.0.1:4723/wd/hub"), appiumOptions); + } + + [TestCleanup] + public void TestTeardown() + { + if (driver != null) + driver.Quit(); + } +} + diff --git a/iOS/LocalSample.ipa b/iOS/LocalSample.ipa new file mode 100644 index 0000000..a937349 Binary files /dev/null and b/iOS/LocalSample.ipa differ diff --git a/iOS/LocalTest.cs b/iOS/LocalTest.cs new file mode 100644 index 0000000..ba06819 --- /dev/null +++ b/iOS/LocalTest.cs @@ -0,0 +1,33 @@ +using OpenQA.Selenium; +using OpenQA.Selenium.Support.UI; + +namespace iOS; + +[TestClass] +public class LocalTest : BrowserstackMSTest +{ + [TestMethod] + public void LocalNetworkTest() + { + if (driver == null) + throw new Exception("Could not run tests. Driver not initialised"); + + var _ = driver.PageSource; + var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30)); + + var testButtonId = By.XPath("/XCUIElementTypeApplication/XCUIElementTypeWindow/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeButton/XCUIElementTypeStaticText"); + IOSElement testButton = (IOSElement)wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(testButtonId)); + testButton.Click(); + Thread.Sleep(5000); + + _ = driver.PageSource; + + IOSElement textElement = driver.FindElementByXPath("/XCUIElementTypeApplication/XCUIElementTypeWindow[1]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeTextField"); + string text = textElement.Text; + + Assert.IsTrue(text.Contains("Up and running")); + + driver.ExecuteScript("browserstack_executor: { \"action\": \"setSessionStatus\", \"arguments\": { \"status\": \"passed\", \"reason\": \"Test Passed!\"} }"); + } +} + diff --git a/iOS/SingleTest.cs b/iOS/SingleTest.cs new file mode 100644 index 0000000..7821618 --- /dev/null +++ b/iOS/SingleTest.cs @@ -0,0 +1,37 @@ +using OpenQA.Selenium.Support.UI; + +namespace iOS; + +[TestClass] +public class SingleTest : BrowserstackMSTest +{ + public SingleTest() { } + + [TestMethod] + public void SearchTest() + { + if (driver == null) + throw new Exception("Could not run tests. Driver not initialised"); + + var _ = driver.PageSource; + var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30)); + + var textButtonId = MobileBy.AccessibilityId("Text Button"); + IOSElement textButton = (IOSElement)wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(textButtonId)); + textButton.Click(); + Thread.Sleep(5000); + + _ = driver.PageSource; + + wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30)); + var textInputId = MobileBy.AccessibilityId("Text Input"); + IOSElement textInput = (IOSElement)wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(textInputId)); + textInput.SendKeys("hello@browserstack.com\n"); + Thread.Sleep(5000); + + var textOutput = driver.FindElementByAccessibilityId("Text Output"); + Assert.IsTrue(textOutput.Text == "hello@browserstack.com"); + + driver.ExecuteScript("browserstack_executor: { \"action\": \"setSessionStatus\", \"arguments\": { \"status\": \"passed\", \"reason\": \"Test Passed!\"} }"); + } +} diff --git a/iOS/Usings.cs b/iOS/Usings.cs new file mode 100644 index 0000000..9bd0e54 --- /dev/null +++ b/iOS/Usings.cs @@ -0,0 +1,3 @@ +global using Microsoft.VisualStudio.TestTools.UnitTesting; +global using OpenQA.Selenium.Appium; +global using OpenQA.Selenium.Appium.iOS; diff --git a/iOS/browserstack.yml b/iOS/browserstack.yml new file mode 100644 index 0000000..b5a0b88 --- /dev/null +++ b/iOS/browserstack.yml @@ -0,0 +1,67 @@ +# ============================= +# Set BrowserStack Credentials +# ============================= +# Add your BrowserStack userName and acccessKey here or set BROWSERSTACK_USERNAME and +# BROWSERSTACK_ACCESS_KEY as env variables +userName: BROWSERSTACK_USERNAME +accessKey: BROWSERSTACK_ACCESS_KEY + +# ====================== +# BrowserStack Reporting +# ====================== +# The following capabilities are used to set up reporting on BrowserStack: +# Set 'projectName' to the name of your project. Example, Marketing Website +projectName: BrowserStack Samples +# Set `buildName` as the name of the job / testsuite being run +buildName: browserstack build +# `buildIdentifier` is a unique id to differentiate every execution that gets appended to +# buildName. Choose your buildIdentifier format from the available expressions: +# ${BUILD_NUMBER} (Default): Generates an incremental counter with every execution +# ${DATE_TIME}: Generates a Timestamp with every execution. Eg. 05-Nov-19:30 +# Read more about buildIdentifiers here -> https://www.browserstack.com/docs/automate/selenium/organize-tests +buildIdentifier: '#${BUILD_NUMBER}' # Supports strings along with either/both ${expression} + +source: 'mstest:appium-sample-sdk:v1.0' + +# Set `app` to define the app that is to be used for testing. +# It can either take the id of any uploaded app or the path of the app directly. +app: ./BStackSampleApp.ipa +# app: ./LocalSample.ipa #For running local tests + +# ======================================= +# Platforms (Browsers / Devices to test) +# ======================================= +# Platforms object contains all the browser / device combinations you want to test on. +# Entire list available here -> (https://www.browserstack.com/list-of-browsers-and-platforms/automate) + +platforms: + - deviceName: iPhone 14 Pro + osVersion: 16 + platformName: ios + - deviceName: iPhone 13 Pro + osVersion: 15 + platformName: ios + - deviceName: iPhone 15 Plus + osVersion: 17 + platformName: ios + +# ========================================== +# BrowserStack Local +# (For localhost, staging/private websites) +# ========================================== +# Set browserStackLocal to true if your website under test is not accessible publicly over the internet +# Learn more about how BrowserStack Local works here -> https://www.browserstack.com/docs/automate/selenium/local-testing-introduction +browserstackLocal: true # (Default false) +#browserStackLocalOptions: +#Options to be passed to BrowserStack local in-case of advanced configurations +# localIdentifier: # (Default: null) Needed if you need to run multiple instances of local. +# forceLocal: true # (Default: false) Set to true if you need to resolve all your traffic via BrowserStack Local tunnel. +# Entire list of arguments available here -> https://www.browserstack.com/docs/automate/selenium/manage-incoming-connections + +# =================== +# Debugging features +# =================== +debug: false # # Set to true if you need screenshots for every selenium command ran +networkLogs: false # Set to true to enable HAR logs capturing +consoleLogs: errors # Remote browser's console debug levels to be printed (Default: errors) +# Available options are `disable`, `errors`, `warnings`, `info`, `verbose` (Default: errors) diff --git a/iOS/iOS.csproj b/iOS/iOS.csproj new file mode 100644 index 0000000..4ee51ca --- /dev/null +++ b/iOS/iOS.csproj @@ -0,0 +1,25 @@ + + + + net6.0 + mstest_appium_app_browserstack + enable + enable + + false + true + + + + + + + + + + + + + + + diff --git a/mstest-appium-app-browserstack.sln b/mstest-appium-app-browserstack.sln new file mode 100644 index 0000000..1ca396d --- /dev/null +++ b/mstest-appium-app-browserstack.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 25.0.1706.11 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "iOS", "iOS\iOS.csproj", "{4A07079C-2AB5-4339-8139-B9671FE82CF3}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Android", "Android\Android.csproj", "{06E07B7C-52B4-4AAD-93F8-D1476F551BF7}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4A07079C-2AB5-4339-8139-B9671FE82CF3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4A07079C-2AB5-4339-8139-B9671FE82CF3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4A07079C-2AB5-4339-8139-B9671FE82CF3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4A07079C-2AB5-4339-8139-B9671FE82CF3}.Release|Any CPU.Build.0 = Release|Any CPU + {06E07B7C-52B4-4AAD-93F8-D1476F551BF7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {06E07B7C-52B4-4AAD-93F8-D1476F551BF7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {06E07B7C-52B4-4AAD-93F8-D1476F551BF7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {06E07B7C-52B4-4AAD-93F8-D1476F551BF7}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {3C1676DA-BFFB-4C1F-8B33-09C74E8BC7C4} + EndGlobalSection +EndGlobal