Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Widget Size and Color Test #1936

Closed
ruveydagunal opened this issue Nov 21, 2023 · 5 comments
Closed

Widget Size and Color Test #1936

ruveydagunal opened this issue Nov 21, 2023 · 5 comments
Assignees
Labels
waiting for response Waiting for user's response

Comments

@ruveydagunal
Copy link

Use case

While Flutter is testing, I want to test the colors and sizes of my widgets, there are not enough documents and I can't do this process.

Proposal

import 'package:flutter/material.dart';
import 'package:patrol_test/home_view.dart';
import 'package:patrol_test/password_forgot.dart';
import 'package:patrol_test/signUp_view.dart';

class SignInView extends StatefulWidget {
@OverRide
_SignInViewState createState() => _SignInViewState();
}

class _SignInViewState extends State {
final GlobalKey _formKey = GlobalKey();
TextEditingController _emailController = TextEditingController();
TextEditingController _passwordController = TextEditingController();
bool _obscureText = true;
bool _formSubmitted = false;

@OverRide
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
'Giriş Sayfası',
key: Key('signInTitle'),
),
leading: IconButton(
icon: Icon(
Icons.arrow_back,
key: Key('arrowBackButton'),
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => HomeView(),
),
);
},
),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Form(
key: _formKey,
child: Column(
children: [
TextFormField(
key: const Key('emailInput'),
controller: _emailController,
decoration: InputDecoration(
labelText: 'E-posta',
errorText: _formSubmitted
? _validateEmail(_emailController.text)
: null,
),
keyboardType: TextInputType.emailAddress,
),
SizedBox(height: 16),
TextFormField(
key: const Key('passwordInput'),
controller: _passwordController,
decoration: InputDecoration(
labelText: 'Şifre',
errorText: _formSubmitted
? _validatePassword(_passwordController.text)
: null,
suffixIcon: IconButton(
icon: Icon(
_obscureText ? Icons.visibility : Icons.visibility_off),
onPressed: () {
setState(() {
_obscureText = !_obscureText;
});
},
),
),
obscureText: _obscureText,
),
SizedBox(height: 24),
ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Colors.red
),
key: const Key('signInButton'),
onPressed: () {
setState(() {
_formSubmitted = true;
});

              String? emailError = _validateEmail(_emailController.text);
              String? passwordError =
                  _validatePassword(_passwordController.text);

              if (emailError == null && passwordError == null) {
                // Eğer e-posta ve şifre uygunsa yönlendirme yap
                Navigator.push(
                  context,
                  MaterialPageRoute(
                    builder: (context) => HomeView(),
                  ),
                );
              }
            },
            child: Text('Giriş Yap'),
          ),
          TextButton(
            key: Key('passwordForgot'),
            onPressed: () {
              Navigator.push(
                context,
                MaterialPageRoute(
                  builder: (context) => PasswordForgot(),
                ),
              );
            },
            child: Text('Şifremi Unuttum'),
          ),
          Text('Hesabınız Yok mu?', key: Key('signUpText'),),
          ElevatedButton(
            key: const Key('signUpButton'),
            onPressed: () {
              setState(() {
                _formSubmitted = true;
              });
              if (_formKey.currentState!.validate()) {
                Navigator.push(
                  context,
                  MaterialPageRoute(
                    builder: (context) => SignUpView(),
                  ),
                );
              }
            },
            child: Text('Üye Ol'),
          ),
        ],
      ),
    ),
  ),
);

}

String? _validateEmail(String value) {
if (value.isEmpty) {
return 'E-posta boş olamaz';
} else if (!RegExp(r'^[\w-]+(.[\w-]+)*@([\w-]+.)+[a-zA-Z]{2,7}$')
.hasMatch(value)) {
return 'Geçersiz e-posta formatı';
}
return null;
}

String? _validatePassword(String value) {
if (value.isEmpty) {
return 'Şifre boş olamaz';
}
return null;
}
}

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:patrol/patrol.dart';
import 'package:patrol_test/main.dart';

void main() {
patrolTest(
'Sign in Successfully',
($) async {
// Uygulamayı başlat
await $.pumpWidgetAndSettle(const MyApp());

  // Appbar title ve buton kontrolü
  expect($(#signInTitle).exists, true);
  expect($(#arrowBackButton).exists, true);

  // Geri butonuna tıklandığında
  await $(#arrowBackButton).tap();
  expect($(#homeView).exists, true);
  await $(#arrowBackButtonHome).tap();

  // // E-posta ve şifre girişi
  await $(#emailInput).enterText('[email protected]');
  await $(#passwordInput).enterText('1q2w3e4r5T.');

  // // Giriş Yap butonuna tıklandığında
  await $(#signInButton).tap();
  expect($(#homeView).exists, true);
  await $(#arrowBackButtonHome).tap();

  await $('Giriş Yap')
    .which<ElevatedButton>((button) => !button.enabled)
    .which<ElevatedButton>(
      (btn) => btn.style?.backgroundColor?.resolve({}) == Colors.red,
    )
    .waitUntilVisible();

  // Şifremi Unuttum kontrolü
  await $(#passwordForgot).tap();
  expect($(#passwordForgotTitle).exists, true);
  await $(#arrowBackButtonForgot).tap();

  // Hesabınız Yok mu? text kontrolü
  expect($(#signUpText).exists, true);

  // Şifremi Unuttum kontrolü
  await $(#signUpButton).tap();
  expect($(#signUpTitle).exists, true);
  await $(#arrowBackButtonSignUp).tap();
},

);
}

@jBorkowska
Copy link
Collaborator

Hi @ruveydagunal! If you want to check widget's properties as size or color, you can access the widget object. Eg.:

   // obtaining Widget object of found element
   final button = $(#signUpButton).evaluate().first.widget as ElevatedButton;
   // accessing properties of that widget, eg. if is enabled
   expect(button.enabled, false);

Let me know if it helped

@jBorkowska jBorkowska self-assigned this Nov 23, 2023
@jBorkowska jBorkowska added the waiting for response Waiting for user's response label Nov 23, 2023
@ruveydagunal
Copy link
Author

ruveydagunal commented Nov 26, 2023 via email

@github-actions github-actions bot removed the waiting for response Waiting for user's response label Nov 26, 2023
@jBorkowska
Copy link
Collaborator

What error did you get? Please post the logs :)

@jBorkowska jBorkowska added the waiting for response Waiting for user's response label Nov 27, 2023
Copy link

github-actions bot commented Dec 4, 2023

Without additional information, we can't resolve this issue. We're therefore reluctantly going to close it.
Feel free to open a new issue with all the required information provided, including a [minimal, reproducible sample]. Make sure to diligently fill out the issue template.
Thanks for your contribution.
[minimal, reproducible sample]: https://stackoverflow.com/help/minimal-reproducible-example

@github-actions github-actions bot closed this as completed Dec 4, 2023
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar problem, please file a new issue. Make sure to follow the template and provide all the information necessary to reproduce the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
waiting for response Waiting for user's response
Projects
None yet
Development

No branches or pull requests

2 participants