Skip to content

Commit 6775828

Browse files
Bill7zzAliandi
authored andcommitted
[Browser-Functional-Tests] Add browser test build YAML file (#1469)
* Add build yaml file to run browser tests * Add step by step guide to configure pipeline * Update yaml file name to browser-tests-build-ci * Update browser functional test readme local steps
1 parent fe300c3 commit 6775828

File tree

6 files changed

+186
-38
lines changed

6 files changed

+186
-38
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
## Description
2+
3+
The library **browser-functional-tests** is a suite of tests running with **Nightwatch** and **Selenium** to check the compatibility of a bot using libraries from BotBuilder-JS with different browsers.
4+
5+
## Run the test locally
6+
7+
_Note: The tests are configured to run in two-terminals, one for the webpack-dev-server which runs the bot, another for running the tests._
8+
9+
1. Go to `libraries/browser-functional-tests`, open a terminal and run `npm install`
10+
11+
12+
2. Go to `libraries/browser-functional-tests/browser-echo-bot`, open a terminal and run the following commands:
13+
* `npm install`
14+
* `npm run start`
15+
This command will start the browser bot using `webpack-dev-server`.
16+
17+
3. In the `botbuilder-js` root directory, open a new terminal and run the following commands:
18+
* `npm install`
19+
* `npm run browser-functional-test browser` where browser is _chrome_ or _firefox_
20+
21+
4. Go to the `.env` file and set the **TestURI** variable with `http://localhost:8080/` value
22+
23+
## Azure Build Pipeline Configuration
24+
The next steps will guide you thought the configuration of a Build pipeline based on YAML file.
25+
26+
### Prerequisites
27+
28+
- Azure DevOps organization. You can find documentation [here](https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/create-organization?view=azure-devops).
29+
- Azure subscription. Required to create and delete Azure resources.
30+
31+
### Step by step
32+
33+
1. Create a pipeline using the classic editor, this options allows to us select the YAML file to configure the pipeline.
34+
![image](https://user-images.githubusercontent.com/38112957/70251315-07982e80-175e-11ea-8edf-6f49af38922f.png)
35+
36+
2. Configure the repository and branch.
37+
![image](https://user-images.githubusercontent.com/38112957/70251361-1da5ef00-175e-11ea-9c2a-777ab959829a.png)
38+
39+
3. In the section Configuration as code select YAML
40+
![image](https://user-images.githubusercontent.com/38112957/70251402-331b1900-175e-11ea-9cb0-58094984e84f.png)
41+
42+
4. In the section YAML, write the build name, select the build YAML file.
43+
![image](https://user-images.githubusercontent.com/38112957/70251437-4201cb80-175e-11ea-89b9-b1da5f7ab552.png)
44+
45+
5. In the Section Variables, Add a variable to save the azure subscription value.
46+
![image](https://user-images.githubusercontent.com/38112957/70251455-4d54f700-175e-11ea-8ddb-e6f6766f25d7.png)
47+
48+
`Variable: AzureSubscription = "YOUR_AZ_SUBSCRIPTION"`
49+
50+
6. Save and queue.
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
trigger:
5+
- master
6+
7+
pr:
8+
- master
9+
10+
pool:
11+
vmImage: 'vs2017-win2016'
12+
13+
variables:
14+
TestResourceGroup: 'BrowserBotTest'
15+
TestAppServicePlan: 'BrowserBotServicePlan'
16+
TestWebApp: 'BrowserBotWebApp'
17+
TESTURI: 'https://$(TestWebApp).azurewebsites.net/'
18+
19+
steps:
20+
21+
- task: NodeTool@0
22+
displayName: 'Use Node 10.'
23+
inputs:
24+
versionSpec: 10.x
25+
26+
- task: Npm@1
27+
displayName: 'npm install bot dependencies'
28+
inputs:
29+
workingDir: 'libraries/browser-functional-tests/browser-echo-bot'
30+
verbose: false
31+
32+
- task: Npm@1
33+
displayName: 'npm build bot '
34+
inputs:
35+
command: custom
36+
workingDir: 'libraries/browser-functional-tests/browser-echo-bot'
37+
verbose: false
38+
customCommand: 'run build'
39+
40+
- powershell: |
41+
# Compress Bot Source Code
42+
43+
cd $(System.DefaultWorkingDirectory)/libraries/browser-functional-tests/browser-echo-bot/dist
44+
$DirToCompress = "$(System.DefaultWorkingDirectory)/libraries/browser-functional-tests/browser-echo-bot/dist"
45+
$files = Get-ChildItem -Path $DirToCompress
46+
$ZipFileResult="$(System.DefaultWorkingDirectory)/libraries/browser-functional-tests/browser-echo-bot/browser-echo-bot.zip"
47+
Compress-Archive -Path $files -DestinationPath $ZipFileResult
48+
displayName: 'Compress Bot Source Code'
49+
50+
- task: AzureCLI@1
51+
displayName: 'Deploy browser bot'
52+
inputs:
53+
azureSubscription: '$(AzureSubscription)'
54+
scriptLocation: inlineScript
55+
inlineScript: |
56+
echo "# Create resource group"
57+
call az group create -l westus -n "$(TestResourceGroup)"
58+
59+
echo "# Create app service plan"
60+
call az appservice plan create -g "$(TestResourceGroup)" -n "$(TestAppServicePlan)" --number-of-workers 4 --sku S1
61+
62+
echo "# Create web app"
63+
call az webapp create -g "$(TestResourceGroup)" -p "$(TestAppServicePlan)" -n "$(TestWebApp)"
64+
65+
echo "# Deploy source code"
66+
call az webapp deployment source config-zip --resource-group "$(TestResourceGroup)" --name "$(TestWebApp)" --src "$(System.DefaultWorkingDirectory)/libraries/browser-functional-tests/browser-echo-bot/browser-echo-bot.zip"
67+
68+
- task: Npm@1
69+
displayName: 'npm install tests dependecies'
70+
inputs:
71+
workingDir: 'libraries/browser-functional-tests'
72+
verbose: false
73+
74+
- task: Npm@1
75+
displayName: 'run chrome tests'
76+
inputs:
77+
command: custom
78+
workingDir: ''
79+
verbose: false
80+
customCommand: 'run browser-functional-test chrome'
81+
82+
- task: Npm@1
83+
displayName: 'run firefox tests'
84+
inputs:
85+
command: custom
86+
workingDir: ''
87+
verbose: false
88+
customCommand: 'run browser-functional-test firefox'
89+
90+
- task: AzureCLI@1
91+
displayName: 'Delete Resource Group'
92+
inputs:
93+
azureSubscription: '$(AzureSubscription)'
94+
scriptLocation: inlineScript
95+
inlineScript: 'call az group delete -n BrowserBotTest --yes'
96+
condition: succeededOrFailed()

libraries/browser-functional-tests/nightwatch.conf.js

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,45 @@
11
const chromedriver = require('chromedriver');
2+
const seleniumServer = require('selenium-server');
3+
const geckodriver = require('geckodriver');
24

35
module.exports = {
46
src_folders: ['tests'],
57
page_objects_path: 'tests/tests_pages',
6-
webdriver: {
7-
start_process: true,
8-
server_path: 'node_modules/.bin/chromedriver',
9-
port: 9515
10-
},
11-
12-
test_workers: {
13-
enabled: false,
14-
workers: 'auto'
15-
},
168
test_settings: {
17-
default: {
18-
webdriver: {
9+
selenium: {
10+
selenium: {
1911
start_process: true,
20-
server_path: chromedriver.path,
2112
port: 9515,
22-
cli_args: ['--port=9515']
13+
server_path: seleniumServer.path,
14+
cli_args: {
15+
'webdriver.gecko.driver': geckodriver.path,
16+
'webdriver.chrome.driver': chromedriver.path
17+
}
2318
},
19+
webdriver: {
20+
start_process: false
21+
}
22+
},
23+
24+
chrome: {
25+
extends: 'selenium',
2426
desiredCapabilities: {
2527
browserName: 'chrome',
2628
javascriptEnabled: true,
2729
acceptSslCerts: true,
28-
chromeOptions: {
29-
args: ['headless', 'disable-gpu']
30+
chromeOptions : {
31+
w3c: false
3032
}
3133
}
3234
},
33-
chrome: {
34-
webdriver: {
35-
start_process: true,
36-
server_path: chromedriver.path,
37-
port: 9515,
38-
cli_args: ['--port=9515']
39-
},
35+
36+
firefox: {
37+
extends: 'selenium',
38+
silent: true,
4039
desiredCapabilities: {
41-
browserName: 'chrome',
40+
browserName: 'firefox',
4241
javascriptEnabled: true,
43-
acceptSslCerts: true,
44-
chromeOptions: {
45-
args: ['headless', 'disable-gpu']
46-
}
42+
acceptSslCerts: true
4743
}
4844
}
4945
}

libraries/browser-functional-tests/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
"description": "Test to check browser compatibility",
55
"main": "",
66
"devDependencies": {
7-
"nightwatch": "^1.2.4",
87
"chromedriver": "^77.0.0",
9-
"dotenv": "^8.0.0"
8+
"dotenv": "^8.0.0",
9+
"nightwatch": "^1.2.4",
10+
"geckodriver": "^1.19.1",
11+
"selenium-server": "^3.141.59"
1012
},
1113
"directories": {
1214
"test": "tests"

libraries/browser-functional-tests/tests/message-handling-tests.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,23 @@ async function assertMessageIsPresentInPage(pageInstance, textSearch, assertMess
4545
await pageInstance.api.elements('@webchatMessagesList', function(messagesWebElements) {
4646
for (let index = 0; (index < messagesWebElements.value.length); index++) {
4747
const webElement = messagesWebElements.value[index];
48-
messagesListPromises.push(new Promise(function(resolve){
49-
pageInstance.api.elementIdText(webElement.ELEMENT, function(elementText) {
48+
messagesListPromises.push((function(resolve) {
49+
// Workaround for different implementations of the WebDriver API
50+
// This will be fixed when all browsers makes use of Selenium Server v4 which is compliant with the W3C WebDriver standards
51+
var elementId = webElement.ELEMENT != undefined ? webElement.ELEMENT : webElement.values()[0];
52+
pageInstance.api.elementIdText(elementId, function(elementText) {
5053
resolve(elementText.value == textSearch);
5154
});
5255
}));
5356
}
5457
}).then(function(){
5558
Promise.all(messagesListPromises)
56-
.then(function (results) {
57-
let messageExists = results.some(function (value) {
58-
return value;
59+
.then(function (results) {
60+
let messageExists = results.some(function (value) {
61+
return value;
62+
});
63+
// Check if any of the existing messages was equal to the needle.
64+
pageInstance.assert.strictEqual(messageExists, true, assertMessage);
5965
});
60-
pageInstance.assert.strictEqual(messageExists, true, assertMessage);
61-
});
6266
});
6367
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"build": "lerna run build",
77
"clean": "lerna run clean",
88
"functional-test": "lerna run build && nyc mocha \"libraries/functional-tests/tests/*.test.js\"",
9-
"browser-functional-test": "cd libraries/browser-functional-tests && node nightwatch.js -e chrome",
9+
"browser-functional-test": "cd libraries/browser-functional-tests && node nightwatch.js -e",
1010
"test": "lerna run build && nyc mocha \"libraries/bot*/tests/**/*.test.js\"",
1111
"test:coveralls": "lerna run build && nyc mocha \"libraries/bot*/tests/**/*.test.js\" && nyc report --reporter=text-lcov | coveralls",
1212
"test-coverage": "nyc mocha \"libraries/bot*/tests/**/*.test.js\"",

0 commit comments

Comments
 (0)