Skip to content

Commit 0a5765c

Browse files
committed
Add markdown file
1 parent a6984e7 commit 0a5765c

File tree

4 files changed

+230
-0
lines changed

4 files changed

+230
-0
lines changed
Loading
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
# UI Tests for a Teams application
2+
3+
## Overview
4+
In this section we will provide an overview on how one could implement UI tests for a custom Teams application.
5+
Generally, to ensure a great experience for your end users, you would like to implement automated test which covers your features both in a browser as well as on mobile platforms. In what follows, we will go through learnings we have gained based on previous experience with our customers.
6+
7+
## Web based UI tests
8+
To implement web-based UI tests for your Teams application, you can follow the same approach as for testing any other web application with a UI. [UI testing](./README.md) provides good guidance on that. The starting point for your test would be to launch a browser in an automated way (using Selenium, or similar frameworks) and go to https://teams.microsoft.com/.
9+
10+
If you would like to test a Teams app which was not yet published into the Teams' store, or if you would like to test the DEV/QA version of your app:
11+
<!-- - Publish the app in a tenant, and use for testing a user which has access to it. In this case, your UI testing focuses on testing your functionalities and threats the Teams' manifest as the *shell* for your code. However, in this case, your test would not catch changes in your [Teams' manifest file](https://learn.microsoft.com/en-us/microsoftteams/platform/resources/schema/manifest-schema) (such as: new icons, new names etc). -->
12+
- First, using for example [Teams Toolkit](https://github.com/OfficeDev/TeamsFx), package your app based on the [manifest.json](https://learn.microsoft.com/en-us/microsoftteams/platform/resources/schema/manifest-schema). See below an example on how to achieve that:
13+
```javascript
14+
npx teamsfx package --env dev --manifest-path ...
15+
```
16+
- Then, implement an automated step which [uploads your custom app](https://learn.microsoft.com/en-us/microsoftteams/platform/concepts/deploy-and-publish/apps-upload) into the Teams' of for your test user.
17+
```{note}
18+
The packaging of your app could be done automatically in a pipeline and the output (Zipped file) could be downloaded as part of your UI tests execution.
19+
```
20+
If you would like to test the production version of your app which was already published in the store you would first need to automate the installation of the app from Teams' store for your test user.
21+
22+
Once the app was installed, implement selectors to [access your custom app](https://learn.microsoft.com/en-us/microsoftteams/platform/concepts/deploy-and-publish/apps-upload#access-your-app) and to perform various actions within the app.
23+
24+
### Pipeline
25+
If you are using Selenium and Edge as the browser, consider leveraging the [selenium/standalone-edge](https://hub.docker.com/r/selenium/standalone-edge) Docker image which contains a standalone Selenium server with the Microsoft Edge browser installed. By default, it would run in headless mode, but by setting `START_XVFB` variable to `True`, you can control whether to start a virtual framebuffer server (Xvfb) that allows GUI applications to run without a display. Below is a code snippet which illustrated the usage of the image in a Gitlab pipeline:
26+
27+
```yml
28+
...
29+
run-tests-dev:
30+
allow_failure: false
31+
image: ...
32+
environment:
33+
name: dev
34+
stage: tests
35+
services:
36+
- name: selenium/standalone-edge:latest
37+
alias: selenium
38+
variables:
39+
START_XVFB: "true"
40+
description: "Start Xvfb server"
41+
...
42+
```
43+
44+
When running your test, you would need to use the Selenium server URL for remote execution. With the definition from above, the URL would be: http://selenium:4444/wd/hub. The code snipped below illustrated how one could initialize the Selenium driver to point to the remote Selenium server using JavaScript:
45+
46+
```javascript
47+
var { Builder } = require("selenium-webdriver");
48+
const edge = require("selenium-webdriver/edge");
49+
50+
var buildEdgeDriver = function () {
51+
let builder = new Builder().forBrowser("MicrosoftEdge");
52+
builder = builder.usingServer("http://selenium:4444/wd/hub");
53+
builder.setEdgeOptions(new edge.Options().addArguments("--inprivate"));
54+
return builder.build();
55+
};
56+
```
57+
58+
## Mobile based UI tests
59+
Testing your custom Teams application on mobile devices is not as straight forward as for the web-based approach due to its challenging setup.
60+
Naturally, it implies the usage of actual devices which is generally more complex. Especially running such tests in a CI/CD pipeline can be more difficult and resource-intensive.
61+
62+
One approach is to use real devices or cloud-based emulators from vendors such as BrowserStack. This requires a license to such vendors. Alternatively, you could use virtual devices hosted in Azure Virtual Machines.
63+
64+
In what follows, we will provide guidance on how to achieve both.
65+
66+
<!-- There are two proven ways through which this can still be achieved for Android, based on previous experience with our customers: -->
67+
68+
### 1. Using Android Virtual Devices
69+
70+
This approach enables the creation of Android UI tests using virtual devices. It comes with the advantage of not requiring a paid licenses to certain vendors. However, due to the nature of emulators, compared to real devices, it may prove to be less stable. Always choose the solution that best fits your project requirements and resources.
71+
72+
Overall setup:
73+
- [AVD - Android Virtual Devices](https://developer.android.com/studio/run/managing-avds) - which are virtual representation of physical Android devices.
74+
- [Appium](https://appium.io/) is an open-source project designed to facilitate UI automation of many app platforms, including mobile.
75+
- Appium is based on the [W3C WebDriver specification](https://w3c.github.io/webdriver/).
76+
> Note: If you look at these commands in the WebDriver specification, you will notice that they are not defined in terms of any particular programming language. They are not Java commands, or JavaScript commands, or Python commands. Instead, they form part of an HTTP API which can be accessed from within any programming language.
77+
- Appium implements a client-server architecture:
78+
- The server (consisting of Appium itself along with any drivers or plugins you are using for automation) is connected to the devices under test, and is actually responsible for making automation happen on those devices. [UiAutomator](https://github.com/appium/appium-uiautomator2-driver) driver is compatible with Android platform.
79+
- The [client](https://appium.io/docs/en/2.0/intro/clients/) is responsible for sending commands to the server over the network, and receiving responses from the server as a result. You can choose the language of your choice to write the commands. For example, for Javascript [WebDriverIO](https://webdriver.io/) can be used as client.
80+
> [Here](https://appium.io/docs/en/2.0/ecosystem/) you can read more about Appium ecosystem
81+
- The advantage of this architecture is that it opens the possibility of running the server in a VM, and the client in a pipeline, enabling the tests to be ran automatically on scheduled basis as part of CI/CD pipelines.
82+
83+
### How to run mobile test locally on a Windows machine
84+
In order to run locally such tests, you need two things:
85+
1. An emulator ([AVD - Android Virtual Devices](https://developer.android.com/studio/run/managing-avds)), which will represent the physical device.
86+
1. [Appium server](https://appium.io/docs/en/2.1/), which will redirect the commands from the test to your virtual device.
87+
88+
#### a) Steps to create Android Virtual Device:
89+
1. Install Android Studio from [official link](https://developer.android.com/studio).
90+
> Note: At the time of writing the documentation, the latest version available was Android Studio Giraffe, 2022.3.1 Patch 2 for Window.
91+
1. Set ANDROID_HOME environment variable to point to the installation path of Android SDK. i.e. ` C:Users\<user-name>\AppData\Local\Android\Sdk`
92+
1. Install Java Development Kit (JDK) from [official link](https://www.oracle.com/java/technologies/javase/jdk11-archive-downloads.html). For the most recent devices JDK 9 is required, otherwise JDK 8 is required. Make sure you get the JDK and not the JRE.
93+
1. Set JAVA_HOME environment variable to the installation path, i.e. ` C:\Program Files\Java\jdk-11`
94+
1. Create an AVD (Android Virtual Device):
95+
1. Open Android Studio. From the Android Studio welcome screen, select **More Action -> Virtual Device Manager**, as instructed [here](https://developer.android.com/studio/run/managing-avds#:~:text=1%20Open%20the%20AVD%20Manager%20by%20clicking%20Tools,%20settings%2C%20such%20as%20the%20skin.%20See%20More.)
96+
1. Click **Create Device**.
97+
1. Choose a device definition with **Play Store** enabled. This is important, otherwise Teams cannot be installed on the device.
98+
1. Choose a System image from the **Recommended** tab which includes access to Google Play services. You may need to install it before selecting it.
99+
1. Start the emulator by clicking on the Run button from the Device Manage screen.
100+
1. Manually install Microsoft Teams from Google Playstore on the device.
101+
102+
#### b) Steps to set up Appium
103+
- Install `appium`:
104+
1. Download NodeJs, if it is not already installed on your machine: [Download | Node.js (nodejs.org)](https://nodejs.org/en/download)
105+
1. Install Appium globally: [Install Appium - Appium Documentation](https://appium.io/docs/en/2.0/quickstart/install/)
106+
1. Install the UiAutomator2 driver: [Install the UiAutomator2 Driver - Appium Documentation](https://appium.io/docs/en/2.0/quickstart/uiauto2-driver/). Go through the `Set up Android automation requirements` in the documentation, to make sure you have set up everything correctly.
107+
108+
> [Here](https://appium.io/docs/en/2.0/intro/drivers/) you can read more about Appium Drivers.
109+
1. Start appium server by running `appium` command in a command prompt.
110+
#### Useful commands:
111+
- To list the emulators that you have previously created, without opening Android Studio:
112+
```cli
113+
emulator -list-avds
114+
```
115+
- To start an emulator, without opening Android Studio:
116+
```cli
117+
emulator -avd {name-of-emulator}
118+
```
119+
- To get the name of your AVD, assuming your emulator is running, you can run:
120+
121+
```cli
122+
adb devices
123+
```
124+
You should see a response with *List of devices attached*, where your running device will be listed.
125+
126+
### How to set up an Azure VM for running mobile tests in a pipeline
127+
128+
### 1. VM configuration
129+
This approach essentially hosts a virtual device in a virtual machine. In order to be able to set up the emulator (Android Virtual Device) in an Azure VM, the VM should support [nested virtualization](https://azure.microsoft.com/en-us/blog/nested-virtualization-in-azure/).
130+
131+
Azure VM configuration which, at the time of writing the documentation, worked successfully with AVD and appium:
132+
- Operating system: Windows (Windows-10 Pro)
133+
- VM generation: V1
134+
- Size: Standard D4ds v5 16 GiB memory
135+
136+
### 2. Enable connection from outside to Appium server on the VM
137+
> Note: By default appium server runs on port 4723. The rest of the steps will assume that this is the port where your appium server runs.
138+
139+
In order to be able to reach appium server which runs on the VM from outside, the following steps are needed:
140+
1. Create an [Inbound Rule](https://learn.microsoft.com/en-us/windows/security/operating-system-security/network-security/windows-firewall/create-an-inbound-port-rule) for port 4723 from within the VM.
141+
1. Create an Inbound Security Rule in the NSG (Network Security Group) of the VM to be able to connect from that IP address to port 4723.
142+
- Find out the IP of the machine on which the tests will run on.
143+
- Replace the *Source IP Address* with the IP of your machine.
144+
145+
### 3. Install Android Studio and create AVD inside the VM
146+
1. Follow the instructions from steps a) and b) in **How to run mobile end to end tests on a Windows machine** section above.
147+
1. When you launch the emulator, it may show a warning as below and will eventually crash:
148+
149+
![failure](./images/warning.png)
150+
151+
Solution to fix it:
152+
1. [Enable Windows Hypervisor Platform](https://devblogs.microsoft.com/visualstudio/hyper-v-android-emulator-support/)
153+
1. [Enable Hyper-V](https://learn.microsoft.com/en-us/virtualization/hyper-v-on-windows/quick-start/enable-hyper-v#enable-the-hyper-v-role-through-settings) (if not enabled by default)
154+
1. Restart the VM.
155+
1. Restart the AVD.
156+
157+
158+
### How to inspect the Teams app in Azure Virtual Device (AVD)
159+
Inspecting the app is very useful as you write new tests, as it allows you to find the ID of different elements displayed on the screen - similar to DevTools, which allows you to navigate through the DOM of a web page.
160+
161+
[Appium Inspector](https://inspector.appiumpro.com/) is a very useful tool that allows you to inspect an app runing on an emulator.
162+
163+
> Note: This section assumes that you have already performed the prerequisites from **How to run mobile end to end tests on a Windows machine**
164+
165+
### Steps to inspect Teams app:
166+
1. Run the appium server with [--alow-cors flag](https://appium.readthedocs.io/en/latest/en/writing-running-appium/server-args/) by running the following command in a terminal:
167+
```
168+
appium --allow-cors
169+
```
170+
2. Go to https://inspector.appiumpro.com and type in the following properties:
171+
```json
172+
{
173+
"appium:deviceName": "your-emulator-name",
174+
"appium:appPackage": "com.microsoft.teams",
175+
"appium:appActivity": "com.microsoft.skype.teams.Launcher",
176+
"appium:automationName": "UiAutomator2",
177+
"platformName": "Android"
178+
}
179+
```
180+
181+
1. "appium:deviceName" - is the name of your emulator. In **Useful commands** sections from above, you can see how to get the name of your AVD.
182+
1. "appium:appPackage" - is the name of the package, should be kept to "**com.microsoft.teams**".
183+
1. "appium:appActivity"- is the name of th eactivity in the app that you want to launch, should be kept to "**com.microsoft.skype.teams.Launcher**"
184+
1. "appium:automationName" - is the name of the driver you are using, in this case, "**UiAutomator2**"
185+
186+
If the appium server runs on your local machine at the default portal, then Remote Host and Remote Port can be kept to the default values.
187+
188+
The configuration should look similar to the printscren below:
189+
![appium-inspector](./images/appium-inspector.png)
190+
3. Press on **Start Session**.
191+
- In the browser, you should see a similar view as below:
192+
![teams-appium-inspector](./images/teams-appium-inspector.png)
193+
- You can do any action on the emulator, and if you press on the "Refresh" button in the browser, the left hand side of the Appium Inspector will reflect your app. In the **App Source** you will be able to see the IDs of the elements, so you can write relevant selectors in your tests.
194+
195+
#### How to connect to Appium server
196+
We will provide an example on how to achieve this using JavaScript. Similar approach can be followed for other languages.
197+
Assuming you are using [webdriverio](https://webdriver.io/) as the client, you would need to initialize the remote connection as follows:
198+
199+
```javascript
200+
const opts = {
201+
port: 4723,
202+
hostname: "your-hostname",
203+
capabilities: {
204+
platformName: "android",
205+
"appium:deviceName": "the-name-of-the-virtual-device",
206+
"appium:appPackage": "com.microsoft.teams",
207+
"appium:appActivity": "com.microsoft.skype.teams.Launcher",
208+
"appium:automationName": "the-name-of-the-driver",
209+
},
210+
};
211+
212+
// Create a new WebDriverIO instance with the Appium server URL and capabilities
213+
await wdio.remote(opts);
214+
```
215+
216+
1. "port": the port on which the Appium server runs on. By default, it is 4723.
217+
1. "hostname": the IP of the machine where the Appium sever runs on. If it is running locally, that is 127.0.0.1. If it runs in an Azure VM, it would be the public IP address of the VM. Note: ensure you have followed the steps from **2. Enable connection from outside to Appium server on the VM**.
218+
1. "platformName": Appium can be used to connect to different platforms (Windows, iOS, Android). In our case, it would be "android".
219+
1. "appium:deviceName": the name of the Android Virtual Device. See **Useful commands** on how to find the name of the device.
220+
1. "appium:appPackage": the name of the app's package that you would like to launch. Teams' package name is "com.microsoft.teams".
221+
1. "appium:appActivity": the activity within Teams that you would like to launch on the device. In our case, we would like just to launch the app. The activity name for launching Teams is called "com.microsoft.skype.teams.Launcher".
222+
1. "appium:automationName": the name of the driver you are using. Note: Appium can communicate to different platforms. This is achieved by installing a dedicated driver, designed for each platform. In our case, it would be [UiAutomator2](https://github.com/appium/appium-uiautomator2-driver) or [Espresso](https://github.com/appium/appium-espresso-driver), since they are both designed for Android platform.
223+
224+
### 2. Using BrowserStack
225+
- BrowserStack does not support out of the box the installation of Teams from the App Store or Play Store. However, there is a workaround, described in [their documentation](https://www.browserstack.com/support/faq/app-automate/app/can-i-install-an-app-from-the-app-store-or-play-store). Therefore, if you choose to go this way, you would first need to implement a step that installs Teams on the cloud-based device, by implementing the workaround described above.
226+
- You may encounter issues with Google login, as it requires a newly created Google account, in order to log in to the store. To overcome this, make sure to disable 2FA from Google, further described in [Troubleshooting Google login issues](https://www.browserstack.com/docs/app-automate/appium/advanced-features/setup-google-account#nodejs).
227+
228+
229+
230+

0 commit comments

Comments
 (0)