This repository demonstrates how to automate a Flutter web application using Selenium and BrowserStack. The project includes modifications to enhance automation compatibility and provides a comprehensive setup for running Selenium Python tests.
The Flutter web app has been modified for better compatibility with Selenium automation. A setup to run Selenium tests on BrowserStack using Python and the BrowserStack SDK. Configuration to run tests on a locally hosted website or live website across various browser platforms.
- Semantic modifications for improved automation
- Cross-browser testing using BrowserStack
import 'package:flutter/rendering.dart';
// Ensure widget binding and enable semantics
WidgetsFlutterBinding.ensureInitialized();
SemanticsBinding.instance.ensureSemantics();
- Added
SemanticsBinding.instance.ensureSemantics()
to activate semantic support - Improves accessibility and automation compatibility
- Generates pseudo elements for better interaction with testing tools
Semantics(
identifier: d.title, // Added for easier automation interaction
child: ListTile(
leading: Icon(d.icon),
title: Text(d.title),
// ... existing implementation
),
)
- Wrapped key UI elements with
Semantics
widget - Added unique identifiers for easier element location
- Enables more reliable Selenium test interactions
- Flutter installed on your system
- Chrome browser
-
Navigate to the project root directory
-
Run the following command:
flutter run -d chrome --web-port=3030
-
Access the web app at:
http://localhost:3030
- Python 3
- BrowserStack Account (free trial available)
-
Clone the repository:
git clone -b dev https://github.com/BrowserStackCE/selenium-flutter-web cd selenium-flutter-web
-
Install dependencies:
python -m venv venv source venv/bin/activate pip3 install -r requirements.txt
Option 1: Update browserstack.yml
with your credentials
Option 2: Set environment variables
- Linux/MacOS:
export BROWSERSTACK_USERNAME=<your-username> export BROWSERSTACK_ACCESS_KEY=<your-access-key>
- Windows:
setx BROWSERSTACK_USERNAME <your-username> setx BROWSERSTACK_ACCESS_KEY <your-access-key>
browserstack-sdk python selenium_tests/live_website_test.py
browserstack-sdk python selenium_tests/local_website_test.py
- Ensure your BrowserStack credentials are correctly configured
- Cross-browser testing supported via BrowserStack configuration
- Verify Flutter and Python installations
- Check BrowserStack credentials
- Ensure all dependencies are installed correctly