diff --git a/.editorconfig b/.editorconfig index 968afd97..5b99dcca 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,404 +1,334 @@ -########################################## -# Common Settings -########################################## - -# This file is the top-most EditorConfig file root = true -# All Files [*] -charset = utf-8 -end_of_line = crlf indent_style = space -indent_size = 4 -insert_final_newline = false +charset = utf-8 trim_trailing_whitespace = true +insert_final_newline = true +spelling_exclusion_path = spelling.dic + +[*.cs] +indent_size = 4 +dotnet_sort_system_directives_first = true -########################################## -# File Extension Settings -########################################## +# Don't use this. qualifier +dotnet_style_qualification_for_field = false:suggestion +dotnet_style_qualification_for_property = false:suggestion -# Visual Studio Solution Files -[*.sln] -indent_style = tab +# use int x = .. over Int32 +dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion -# Visual Studio XML Project Files -[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}] -indent_size = 2 +# use int.MaxValue over Int32.MaxValue +dotnet_style_predefined_type_for_member_access = true:suggestion -# Various XML Configuration Files -[*.{xml,config,props,targets,nuspec,resx,ruleset,vsixmanifest,vsct}] -indent_size = 2 +# Require var all the time. +csharp_style_var_for_built_in_types = true:suggestion +csharp_style_var_when_type_is_apparent = true:suggestion +csharp_style_var_elsewhere = true:suggestion -# JSON Files -[*.{json,json5}] -indent_size = 2 +# Disallow throw expressions. +csharp_style_throw_expression = false:suggestion + +# Newline settings +csharp_new_line_before_open_brace = all +csharp_new_line_before_else = true +csharp_new_line_before_catch = true +csharp_new_line_before_finally = true +csharp_new_line_before_members_in_object_initializers = true +csharp_new_line_before_members_in_anonymous_types = true + +# Namespace settings +csharp_style_namespace_declarations = file_scoped + +# Brace settings +csharp_prefer_braces = true # Prefer curly braces even for one line of code + +# name all constant fields using PascalCase +dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = warning +dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields +dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style +dotnet_naming_symbols.constant_fields.applicable_kinds = field +dotnet_naming_symbols.constant_fields.required_modifiers = const +dotnet_naming_style.pascal_case_style.capitalization = pascal_case -# YAML Files -[*.{yml,yaml}] +# static fields should have s_ prefix +dotnet_naming_rule.static_fields_should_have_prefix.severity = warning +dotnet_naming_rule.static_fields_should_have_prefix.symbols = static_fields +dotnet_naming_rule.static_fields_should_have_prefix.style = static_prefix_style +dotnet_naming_symbols.static_fields.applicable_kinds = field +dotnet_naming_symbols.static_fields.required_modifiers = static +dotnet_naming_symbols.static_fields.applicable_accessibilities = private, internal, private_protected +dotnet_naming_style.static_prefix_style.required_prefix = s_ +dotnet_naming_style.static_prefix_style.capitalization = camel_case + +# internal and private fields should be _camelCase +dotnet_naming_rule.camel_case_for_private_internal_fields.severity = warning +dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields +dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style +dotnet_naming_symbols.private_internal_fields.applicable_kinds = field +dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal +dotnet_naming_style.camel_case_underscore_style.required_prefix = _ +dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case + +[*.{xml,config,*proj,nuspec,props,resx,targets,yml,tasks}] indent_size = 2 -# Markdown Files -[*.md] -trim_trailing_whitespace = false +# Xml config files +[*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}] +indent_size = 2 -# Web Files -[*.{htm,html,js,ts,tsx,css,sass,scss,less,svg,vue}] +[*.json] indent_size = 2 -insert_final_newline = true -# Batch Files -[*.{cmd,bat}] +[*.{ps1,psm1}] +indent_size = 4 -# Bash Files [*.sh] +indent_size = 4 end_of_line = lf -########################################## -# .NET Language Conventions -# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#language-conventions -########################################## - -# .NET Code Style Settings -[*.{cs,csx,cake,vb}] -# "this." and "Me." qualifiers -# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#this_and_me -#prefer fields to be prefaced with this. in C# or Me. in Visual Basic -dotnet_style_qualification_for_field = true:warning -#prefer properties to be prefaced with this. or Me. in Visual Basic -dotnet_style_qualification_for_property = true:warning -#prefer methods to be prefaced with this. in C# or Me. in Visual Basic -dotnet_style_qualification_for_method = true:warning -#prefer events to be prefaced with this. in C# or Me. in Visual Basic -dotnet_style_qualification_for_event = true:warning - -# Language keywords instead of framework type names for type references -# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#language_keywords -#prefer the language keyword for local variables, method parameters, and class members, instead of the type name, for types that have a keyword to represent them -dotnet_style_predefined_type_for_locals_parameters_members = true:warning -#prefer the language keyword for member access expressions, instead of the type name, for types that have a keyword to represent them -dotnet_style_predefined_type_for_member_access = true:warning - -# Modifier preferences -# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#normalize_modifiers -dotnet_style_require_accessibility_modifiers = always:warning -csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async -visual_basic_preferred_modifier_order = Partial,Default,Private,Protected,Public,Friend,NotOverridable,Overridable,MustOverride,Overloads,Overrides,MustInherit,NotInheritable,Static,Shared,Shadows,ReadOnly,WriteOnly,Dim,Const,WithEvents,Widening,Narrowing,Custom,Async -dotnet_style_readonly_field = true:warning - -# Parentheses preferences -# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#parentheses -dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:warning -dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:warning -dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:warning -dotnet_style_parentheses_in_other_operators = never_if_unnecessary:suggestion - -# Expression-level preferences -# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#expression_level -dotnet_style_object_initializer = true:warning -dotnet_style_collection_initializer = true:warning -dotnet_style_explicit_tuple_names = true:warning -dotnet_style_prefer_inferred_tuple_names = true:warning -dotnet_style_prefer_inferred_anonymous_type_member_names = true:warning -dotnet_style_prefer_auto_properties = true:warning -dotnet_style_prefer_is_null_check_over_reference_equality_method = true:warning -dotnet_style_prefer_conditional_expression_over_assignment = false:suggestion -dotnet_style_prefer_conditional_expression_over_return = false:suggestion - -# Null-checking preferences -# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#null_checking -dotnet_style_coalesce_expression = true:warning -dotnet_style_null_propagation = true:warning - -# C# Code Style Settings -[*.{cs,csx,cake}] -# Implicit and explicit types -# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#implicit-and-explicit-types -#prefer explicit type over var to declare variables with built-in system types such as int -csharp_style_var_for_built_in_types = false:suggestion -#prefer explicit var over type when the type is already mentioned on the right-hand side of a declaration -csharp_style_var_when_type_is_apparent = true:warning -#prefer explicit type over var to declare variables where type is elsewhere -csharp_style_var_elsewhere = false:warning - -# Expression-bodied members -# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#expression_bodied_members -#prefer block bodies for methods -csharp_style_expression_bodied_methods = false:warning -#prefer block bodies for constructors -csharp_style_expression_bodied_constructors = false:warning -#prefer block bodies for operators -csharp_style_expression_bodied_operators = false:warning -#prefer expression-bodied members for properties -csharp_style_expression_bodied_properties = true:warning -#prefer expression-bodied members for indexers -csharp_style_expression_bodied_indexers = true:warning -#prefer expression-bodied members for accessors -csharp_style_expression_bodied_accessors = true:warning - -# Pattern matching -# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#pattern_matching -csharp_style_pattern_matching_over_is_with_cast_check = true:warning -csharp_style_pattern_matching_over_as_with_null_check = true:warning - -# Inlined variable declarations -# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#inlined_variable_declarations -#prefer out variables to be declared inline in the argument list of a method call when possible -csharp_style_inlined_variable_declaration = true:suggestion - -# Expression-level preferences -# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#expression_level_csharp -csharp_prefer_simple_default_expression = true:warning -csharp_style_deconstructed_variable_declaration = true:warning -csharp_style_pattern_local_over_anonymous_function = true:warning - -# "Null" checking preferences -# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#null_checking_csharp -csharp_style_throw_expression = true:warning -csharp_style_conditional_delegate_call = true:warning - -# Code block preferences -# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#code_block -csharp_prefer_braces = true:warning - -########################################## -# .NET Formatting Conventions -# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#formatting-conventions -########################################## - -# Organize usings -# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#usings -#sort System.* using directives alphabetically, and place them before other usings -dotnet_sort_system_directives_first = true +[*.{razor,cshtml}] +charset = utf-8-bom -# Using statement placement (Undocumented) -csharp_using_directive_placement = inside_namespace:warning +[*.{cs,vb}] -# C# formatting settings -# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#c-formatting-settings -csharp_new_line_before_open_brace = all -csharp_new_line_before_else = true -csharp_new_line_before_catch = true -csharp_new_line_before_finally = true -csharp_new_line_before_members_in_object_initializers = true -csharp_new_line_before_members_in_anonymous_types = true -csharp_new_line_between_query_expression_clauses = true - -# Indentation options -# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#indent -#indent switch case contents. -csharp_indent_case_contents = true -#indent switch labels -csharp_indent_switch_labels = true -csharp_indent_labels = no_change - -# Spacing options -# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#spacing -#require NO space between a cast and the value -csharp_space_after_cast = false -#require a space after a keyword in a control flow statement such as a for loop -csharp_space_after_keywords_in_control_flow_statements = true -#place a space character after the opening parenthesis and before the closing parenthesis of a method declaration parameter list. -csharp_space_between_method_declaration_parameter_list_parentheses = false -#do not place space characters after the opening parenthesis and before the closing parenthesis of a method call -csharp_space_between_method_call_parameter_list_parentheses = false -csharp_space_between_parentheses = false -#require a space before the colon for bases or interfaces in a type declaration -csharp_space_before_colon_in_inheritance_clause = true -#require a space before the colon for bases or interfaces in a type declaration -csharp_space_after_colon_in_inheritance_clause = true -csharp_space_around_binary_operators = before_and_after -#remove space within empty parameter list parentheses for a method declaration -csharp_space_between_method_declaration_empty_parameter_list_parentheses = false -#remove space between method call name and opening parenthesis -csharp_space_between_method_call_name_and_opening_parenthesis = false -#remove space within empty argument list parentheses -csharp_space_between_method_call_empty_parameter_list_parentheses = false - -# Wrapping options -# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#wrapping -#leave statements and member declarations on the same line -csharp_preserve_single_line_statements = true -#leave code block on single line -csharp_preserve_single_line_blocks = true - -# More Indentation options (Undocumented) -csharp_indent_block_contents = true -csharp_indent_braces = false - -# Spacing Options (Undocumented) -csharp_space_after_comma = true -csharp_space_after_dot = false -csharp_space_after_semicolon_in_for_statement = true -csharp_space_around_declaration_statements = do_not_ignore -csharp_space_before_comma = false -csharp_space_before_dot = false -csharp_space_before_semicolon_in_for_statement = false -csharp_space_before_open_square_brackets = false -csharp_space_between_empty_square_brackets = false -csharp_space_between_method_declaration_name_and_open_parenthesis = false -csharp_space_between_square_brackets = false - -########################################## -# .NET Naming Conventions -# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-naming-conventions -########################################## - -[*.{cs,csx,cake,vb}] - -########################################## -# Styles -########################################## - -# camel_case_style - Define the camelCase style -dotnet_naming_style.camel_case_style.capitalization = camel_case -# pascal_case_style - Define the Pascal_case style -dotnet_naming_style.pascal_case_style.capitalization = pascal_case -# first_upper_style - The first character must start with an upper-case character -dotnet_naming_style.first_upper_style.capitalization = first_word_upper -# prefix_interface_with_i_style - Interfaces must be PascalCase and the first character of an interface must be an 'I' -dotnet_naming_style.prefix_interface_with_i_style.capitalization = pascal_case -dotnet_naming_style.prefix_interface_with_i_style.required_prefix = I -# prefix_type_parameters_with_t_style - Generic Type Parameters must be PascalCase and the first character must be a 'T' -dotnet_naming_style.prefix_type_parameters_with_t_style.capitalization = pascal_case -dotnet_naming_style.prefix_type_parameters_with_t_style.required_prefix = T -# disallowed_style - Anything that has this style applied is marked as disallowed -dotnet_naming_style.disallowed_style.capitalization = pascal_case -dotnet_naming_style.disallowed_style.required_prefix = ____RULE_VIOLATION____ -dotnet_naming_style.disallowed_style.required_suffix = ____RULE_VIOLATION____ -# internal_error_style - This style should never occur... if it does, it's indicates a bug in file or in the parser using the file -dotnet_naming_style.internal_error_style.capitalization = pascal_case -dotnet_naming_style.internal_error_style.required_prefix = ____INTERNAL_ERROR____ -dotnet_naming_style.internal_error_style.required_suffix = ____INTERNAL_ERROR____ - -########################################## -# .NET Design Guideline Field Naming Rules -# Naming rules for fields follow the .NET Framework design guidelines -# https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/index -########################################## - -# All public/protected/protected_internal constant fields must be PascalCase -# https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/field -dotnet_naming_symbols.public_protected_constant_fields_group.applicable_accessibilities = public, protected, protected_internal -dotnet_naming_symbols.public_protected_constant_fields_group.required_modifiers = const -dotnet_naming_symbols.public_protected_constant_fields_group.applicable_kinds = field -dotnet_naming_rule.public_protected_constant_fields_must_be_pascal_case_rule.symbols = public_protected_constant_fields_group -dotnet_naming_rule.public_protected_constant_fields_must_be_pascal_case_rule.style = pascal_case_style -dotnet_naming_rule.public_protected_constant_fields_must_be_pascal_case_rule.severity = warning - -# All public/protected/protected_internal static readonly fields must be PascalCase -# https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/field -dotnet_naming_symbols.public_protected_static_readonly_fields_group.applicable_accessibilities = public, protected, protected_internal -dotnet_naming_symbols.public_protected_static_readonly_fields_group.required_modifiers = static, readonly -dotnet_naming_symbols.public_protected_static_readonly_fields_group.applicable_kinds = field -dotnet_naming_rule.public_protected_static_readonly_fields_must_be_pascal_case_rule.symbols = public_protected_static_readonly_fields_group -dotnet_naming_rule.public_protected_static_readonly_fields_must_be_pascal_case_rule.style = pascal_case_style -dotnet_naming_rule.public_protected_static_readonly_fields_must_be_pascal_case_rule.severity = warning - -# No other public/protected/protected_internal fields are allowed -# https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/field -dotnet_naming_symbols.other_public_protected_fields_group.applicable_accessibilities = public, protected, protected_internal -dotnet_naming_symbols.other_public_protected_fields_group.applicable_kinds = field -dotnet_naming_rule.other_public_protected_fields_disallowed_rule.symbols = other_public_protected_fields_group -dotnet_naming_rule.other_public_protected_fields_disallowed_rule.style = disallowed_style -dotnet_naming_rule.other_public_protected_fields_disallowed_rule.severity = error - -########################################## -# StyleCop Field Naming Rules -# Naming rules for fields follow the StyleCop analyzers -# This does not override any rules using disallowed_style above -# https://github.com/DotNetAnalyzers/StyleCopAnalyzers -########################################## - -# All constant fields must be PascalCase -# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1303.md -dotnet_naming_symbols.stylecop_constant_fields_group.applicable_accessibilities = public, internal, protected_internal, protected, private_protected, private -dotnet_naming_symbols.stylecop_constant_fields_group.required_modifiers = const -dotnet_naming_symbols.stylecop_constant_fields_group.applicable_kinds = field -dotnet_naming_rule.stylecop_constant_fields_must_be_pascal_case_rule.symbols = stylecop_constant_fields_group -dotnet_naming_rule.stylecop_constant_fields_must_be_pascal_case_rule.style = pascal_case_style -dotnet_naming_rule.stylecop_constant_fields_must_be_pascal_case_rule.severity = warning - -# All static readonly fields must be PascalCase -# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1311.md -dotnet_naming_symbols.stylecop_static_readonly_fields_group.applicable_accessibilities = public, internal, protected_internal, protected, private_protected, private -dotnet_naming_symbols.stylecop_static_readonly_fields_group.required_modifiers = static, readonly -dotnet_naming_symbols.stylecop_static_readonly_fields_group.applicable_kinds = field -dotnet_naming_rule.stylecop_static_readonly_fields_must_be_pascal_case_rule.symbols = stylecop_static_readonly_fields_group -dotnet_naming_rule.stylecop_static_readonly_fields_must_be_pascal_case_rule.style = pascal_case_style -dotnet_naming_rule.stylecop_static_readonly_fields_must_be_pascal_case_rule.severity = warning - -# No non-private instance fields are allowed -# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1401.md -dotnet_naming_symbols.stylecop_fields_must_be_private_group.applicable_accessibilities = public, internal, protected_internal, protected, private_protected -dotnet_naming_symbols.stylecop_fields_must_be_private_group.applicable_kinds = field -dotnet_naming_rule.stylecop_instance_fields_must_be_private_rule.symbols = stylecop_fields_must_be_private_group -dotnet_naming_rule.stylecop_instance_fields_must_be_private_rule.style = disallowed_style -dotnet_naming_rule.stylecop_instance_fields_must_be_private_rule.severity = error - -# Private fields must be camelCase -# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1306.md -dotnet_naming_symbols.stylecop_private_fields_group.applicable_accessibilities = private -dotnet_naming_symbols.stylecop_private_fields_group.applicable_kinds = field -dotnet_naming_rule.stylecop_private_fields_must_be_camel_case_rule.symbols = stylecop_private_fields_group -dotnet_naming_rule.stylecop_private_fields_must_be_camel_case_rule.style = camel_case_style -dotnet_naming_rule.stylecop_private_fields_must_be_camel_case_rule.severity = warning - -# Local variables must be camelCase -# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1312.md -dotnet_naming_symbols.stylecop_local_fields_group.applicable_accessibilities = local -dotnet_naming_symbols.stylecop_local_fields_group.applicable_kinds = local -dotnet_naming_rule.stylecop_local_fields_must_be_camel_case_rule.symbols = stylecop_local_fields_group -dotnet_naming_rule.stylecop_local_fields_must_be_camel_case_rule.style = camel_case_style -dotnet_naming_rule.stylecop_local_fields_must_be_camel_case_rule.severity = silent - -# This rule should never fire. However, it's included for at least two purposes: -# First, it helps to understand, reason about, and root-case certain types of issues, such as bugs in .editorconfig parsers. -# Second, it helps to raise immediate awareness if a new field type is added (as occurred recently in C#). -dotnet_naming_symbols.sanity_check_uncovered_field_case_group.applicable_accessibilities = * -dotnet_naming_symbols.sanity_check_uncovered_field_case_group.applicable_kinds = field -dotnet_naming_rule.sanity_check_uncovered_field_case_rule.symbols = sanity_check_uncovered_field_case_group -dotnet_naming_rule.sanity_check_uncovered_field_case_rule.style = internal_error_style -dotnet_naming_rule.sanity_check_uncovered_field_case_rule.severity = error - - -########################################## -# Other Naming Rules -########################################## - -# All of the following must be PascalCase: -# - Namespaces -# https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/names-of-namespaces -# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1300.md -# - Classes and Enumerations -# https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/names-of-classes-structs-and-interfaces -# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1300.md -# - Delegates -# https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/names-of-classes-structs-and-interfaces#names-of-common-types -# - Constructors, Properties, Events, Methods -# https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/names-of-type-members -dotnet_naming_symbols.element_group.applicable_kinds = namespace, class, enum, struct, delegate, event, method, property -dotnet_naming_rule.element_rule.symbols = element_group -dotnet_naming_rule.element_rule.style = pascal_case_style -dotnet_naming_rule.element_rule.severity = warning - -# Interfaces use PascalCase and are prefixed with uppercase 'I' -# https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/names-of-classes-structs-and-interfaces -dotnet_naming_symbols.interface_group.applicable_kinds = interface -dotnet_naming_rule.interface_rule.symbols = interface_group -dotnet_naming_rule.interface_rule.style = prefix_interface_with_i_style -dotnet_naming_rule.interface_rule.severity = warning - -# Generics Type Parameters use PascalCase and are prefixed with uppercase 'T' -# https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/names-of-classes-structs-and-interfaces -dotnet_naming_symbols.type_parameter_group.applicable_kinds = type_parameter -dotnet_naming_rule.type_parameter_rule.symbols = type_parameter_group -dotnet_naming_rule.type_parameter_rule.style = prefix_type_parameters_with_t_style -dotnet_naming_rule.type_parameter_rule.severity = warning - -# Function parameters use camelCase -# https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/naming-parameters -dotnet_naming_symbols.parameters_group.applicable_kinds = parameter -dotnet_naming_rule.parameters_rule.symbols = parameters_group -dotnet_naming_rule.parameters_rule.style = camel_case_style -dotnet_naming_rule.parameters_rule.severity = warning +# SYSLIB1054: Use 'LibraryImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time +dotnet_diagnostic.SYSLIB1054.severity = warning + +# CA1018: Mark attributes with AttributeUsageAttribute +dotnet_diagnostic.CA1018.severity = warning + +# CA1047: Do not declare protected member in sealed type +dotnet_diagnostic.CA1047.severity = warning + +# CA1305: Specify IFormatProvider +dotnet_diagnostic.CA1305.severity = warning + +# CA1507: Use nameof to express symbol names +dotnet_diagnostic.CA1507.severity = warning + +# CA1510: Use ArgumentNullException throw helper +dotnet_diagnostic.CA1510.severity = warning + +# CA1511: Use ArgumentException throw helper +dotnet_diagnostic.CA1511.severity = warning + +# CA1512: Use ArgumentOutOfRangeException throw helper +dotnet_diagnostic.CA1512.severity = warning + +# CA1513: Use ObjectDisposedException throw helper +dotnet_diagnostic.CA1513.severity = warning + +# CA1725: Parameter names should match base declaration +dotnet_diagnostic.CA1725.severity = suggestion + +# CA1802: Use literals where appropriate +dotnet_diagnostic.CA1802.severity = warning + +# CA1805: Do not initialize unnecessarily +dotnet_diagnostic.CA1805.severity = warning + +# CA1810: Do not initialize unnecessarily +dotnet_diagnostic.CA1810.severity = warning + +# CA1821: Remove empty Finalizers +dotnet_diagnostic.CA1821.severity = warning + +# CA1822: Make member static +dotnet_diagnostic.CA1822.severity = warning +dotnet_code_quality.CA1822.api_surface = private, internal + +# CA1823: Avoid unused private fields +dotnet_diagnostic.CA1823.severity = warning + +# CA1825: Avoid zero-length array allocations +dotnet_diagnostic.CA1825.severity = warning + +# CA1826: Do not use Enumerable methods on indexable collections. Instead use the collection directly +dotnet_diagnostic.CA1826.severity = warning + +# CA1827: Do not use Count() or LongCount() when Any() can be used +dotnet_diagnostic.CA1827.severity = warning + +# CA1828: Do not use CountAsync() or LongCountAsync() when AnyAsync() can be used +dotnet_diagnostic.CA1828.severity = warning + +# CA1829: Use Length/Count property instead of Count() when available +dotnet_diagnostic.CA1829.severity = warning + +# CA1830: Prefer strongly-typed Append and Insert method overloads on StringBuilder +dotnet_diagnostic.CA1830.severity = warning + +# CA1831: Use AsSpan or AsMemory instead of Range-based indexers when appropriate +dotnet_diagnostic.CA1831.severity = warning + +# CA1832: Use AsSpan or AsMemory instead of Range-based indexers when appropriate +dotnet_diagnostic.CA1832.severity = warning + +# CA1833: Use AsSpan or AsMemory instead of Range-based indexers when appropriate +dotnet_diagnostic.CA1833.severity = warning + +# CA1834: Consider using 'StringBuilder.Append(char)' when applicable +dotnet_diagnostic.CA1834.severity = warning + +# CA1835: Prefer the 'Memory'-based overloads for 'ReadAsync' and 'WriteAsync' +dotnet_diagnostic.CA1835.severity = warning + +# CA1836: Prefer IsEmpty over Count +dotnet_diagnostic.CA1836.severity = warning + +# CA1837: Use 'Environment.ProcessId' +dotnet_diagnostic.CA1837.severity = warning + +# CA1838: Avoid 'StringBuilder' parameters for P/Invokes +dotnet_diagnostic.CA1838.severity = warning + +# CA1839: Use 'Environment.ProcessPath' +dotnet_diagnostic.CA1839.severity = warning + +# CA1840: Use 'Environment.CurrentManagedThreadId' +dotnet_diagnostic.CA1840.severity = warning + +# CA1841: Prefer Dictionary.Contains methods +dotnet_diagnostic.CA1841.severity = warning + +# CA1842: Do not use 'WhenAll' with a single task +dotnet_diagnostic.CA1842.severity = warning + +# CA1843: Do not use 'WaitAll' with a single task +dotnet_diagnostic.CA1843.severity = warning + +# CA1844: Provide memory-based overrides of async methods when subclassing 'Stream' +dotnet_diagnostic.CA1844.severity = warning + +# CA1845: Use span-based 'string.Concat' +dotnet_diagnostic.CA1845.severity = warning + +# CA1846: Prefer AsSpan over Substring +dotnet_diagnostic.CA1846.severity = warning + +# CA1847: Use string.Contains(char) instead of string.Contains(string) with single characters +dotnet_diagnostic.CA1847.severity = warning + +# CA1852: Seal internal types +dotnet_diagnostic.CA1852.severity = warning + +# CA1854: Prefer the IDictionary.TryGetValue(TKey, out TValue) method +dotnet_diagnostic.CA1854.severity = warning + +# CA1855: Prefer 'Clear' over 'Fill' +dotnet_diagnostic.CA1855.severity = warning + +# CA1856: Incorrect usage of ConstantExpected attribute +dotnet_diagnostic.CA1856.severity = error + +# CA1857: A constant is expected for the parameter +dotnet_diagnostic.CA1857.severity = warning + +# CA1858: Use 'StartsWith' instead of 'IndexOf' +dotnet_diagnostic.CA1858.severity = warning + +# CA2007: Consider calling ConfigureAwait on the awaited task +dotnet_diagnostic.CA2007.severity = none + +# CA2008: Do not create tasks without passing a TaskScheduler +dotnet_diagnostic.CA2008.severity = warning + +# CA2009: Do not call ToImmutableCollection on an ImmutableCollection value +dotnet_diagnostic.CA2009.severity = warning + +# CA2011: Avoid infinite recursion +dotnet_diagnostic.CA2011.severity = warning + +# CA2012: Use ValueTask correctly +dotnet_diagnostic.CA2012.severity = warning + +# CA2013: Do not use ReferenceEquals with value types +dotnet_diagnostic.CA2013.severity = warning + +# CA2014: Do not use stackalloc in loops. +dotnet_diagnostic.CA2014.severity = warning + +# CA2016: Forward the 'CancellationToken' parameter to methods that take one +dotnet_diagnostic.CA2016.severity = warning + +# CA2200: Rethrow to preserve stack details +dotnet_diagnostic.CA2200.severity = warning + +# CA2201: Do not raise reserved exception types +dotnet_diagnostic.CA2201.severity = warning + +# CA2208: Instantiate argument exceptions correctly +dotnet_diagnostic.CA2208.severity = warning + +# CA2245: Do not assign a property to itself +dotnet_diagnostic.CA2245.severity = warning + +# CA2246: Assigning symbol and its member in the same statement +dotnet_diagnostic.CA2246.severity = warning + +# CA2249: Use string.Contains instead of string.IndexOf to improve readability. +dotnet_diagnostic.CA2249.severity = warning + +# IDE0005: Remove unnecessary usings +dotnet_diagnostic.IDE0005.severity = warning + +# IDE0011: Curly braces to surround blocks of code +dotnet_diagnostic.IDE0011.severity = warning + +# IDE0020: Use pattern matching to avoid is check followed by a cast (with variable) +dotnet_diagnostic.IDE0020.severity = warning + +# IDE0029: Use coalesce expression (non-nullable types) +dotnet_diagnostic.IDE0029.severity = warning + +# IDE0030: Use coalesce expression (nullable types) +dotnet_diagnostic.IDE0030.severity = warning + +# IDE0031: Use null propagation +dotnet_diagnostic.IDE0031.severity = warning + +# IDE0035: Remove unreachable code +dotnet_diagnostic.IDE0035.severity = warning + +# IDE0036: Order modifiers +csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion +dotnet_diagnostic.IDE0036.severity = warning + +# IDE0038: Use pattern matching to avoid is check followed by a cast (without variable) +dotnet_diagnostic.IDE0038.severity = warning + +# IDE0043: Format string contains invalid placeholder +dotnet_diagnostic.IDE0043.severity = warning + +# IDE0044: Make field readonly +dotnet_diagnostic.IDE0044.severity = warning + +# IDE0051: Remove unused private members +dotnet_diagnostic.IDE0051.severity = warning + +# IDE0055: All formatting rules +dotnet_diagnostic.IDE0055.severity = suggestion + +# IDE0059: Unnecessary assignment to a value +dotnet_diagnostic.IDE0059.severity = warning + +# IDE0060: Remove unused parameter +dotnet_code_quality_unused_parameters = non_public +dotnet_diagnostic.IDE0060.severity = warning + +# IDE0062: Make local function static +dotnet_diagnostic.IDE0062.severity = warning + +# IDE1006: Required naming style +dotnet_diagnostic.IDE1006.severity = warning + +# IDE0161: Convert to file-scoped namespace +dotnet_diagnostic.IDE0161.severity = warning + +# IDE0200: Lambda expression can be removed +dotnet_diagnostic.IDE0200.severity = warning + +# IDE2000: Disallow multiple blank lines +dotnet_style_allow_multiple_blank_lines_experimental = false +dotnet_diagnostic.IDE2000.severity = warning diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..671f86ba --- /dev/null +++ b/.gitattributes @@ -0,0 +1,60 @@ +# Set default behavior to automatically normalize line endings. +* text=auto + +# Collapse these files in PRs by default +*.xlf linguist-generated=true +*.lcl linguist-generated=true + +*.jpg binary +*.png binary +*.gif binary + +# Force bash scripts to always use lf line endings so that if a repo is accessed +# in Unix via a file share from Windows, the scripts will work. +*.in text eol=lf +*.sh text eol=lf + +# Likewise, force cmd and batch scripts to always use crlf +*.cmd text eol=crlf +*.bat text eol=crlf + +*.cs text=auto diff=csharp +*.vb text=auto +*.resx text=auto +*.c text=auto +*.cpp text=auto +*.cxx text=auto +*.h text=auto +*.hxx text=auto +*.py text=auto +*.rb text=auto +*.java text=auto +*.html text=auto +*.htm text=auto +*.css text=auto +*.scss text=auto +*.sass text=auto +*.less text=auto +*.js text=auto +*.lisp text=auto +*.clj text=auto +*.sql text=auto +*.php text=auto +*.lua text=auto +*.m text=auto +*.asm text=auto +*.erl text=auto +*.fs text=auto +*.fsx text=auto +*.hs text=auto + +*.csproj text=auto +*.vbproj text=auto +*.fsproj text=auto +*.dbproj text=auto +*.sln text=auto eol=crlf + +# Set linguist language for .h files explicitly based on +# https://github.com/github/linguist/issues/1626#issuecomment-401442069 +# this only affects the repo's language statistics +*.h linguist-language=C diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2229bb3f..e31a605d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,62 +3,71 @@ name: CI on: push: tags: - - v* + - v* branches: - - main + - main paths: - - src/** - - samples/** - - tests/** - - build/** - - tools/** - - .github/workflows/ci.yml + - src/** + - samples/** + - tests/** + - build/** + - tools/** + - .github/workflows/ci.yml pull_request: branches: - - main + - main paths: - - src/** - - samples/** - - tests/** - - build/** - - tools/** - - .github/workflows/ci.yml + - src/** + - samples/** + - tests/** + - build/** + - tools/** + - .github/workflows/ci.yml workflow_dispatch: jobs: build: - env: - BUILD_CONFIG: 'Release' - SOLUTION: 'src/Legerity.sln' + BUILD_CONFIG: "Release" + SOLUTION: "src/Legerity.sln" runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v2 + + - name: Get Build Version + run: | + Import-Module .\build\GetBuildVersion.psm1 + Write-Host $Env:GITHUB_REF + $version = GetBuildVersion -VersionString $Env:GITHUB_REF + echo "BUILD_VERSION=$version" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append + shell: pwsh + + - name: Setup .NET 6.0 + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 6.0.x - - name: Get Build Version - run: | - Import-Module .\build\GetBuildVersion.psm1 - Write-Host $Env:GITHUB_REF - $version = GetBuildVersion -VersionString $Env:GITHUB_REF - echo "BUILD_VERSION=$version" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append - shell: pwsh + - name: Setup .NET 7.0 + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 7.0.x - - name: Setup .NET 6.0 - uses: actions/setup-dotnet@v1 - with: - dotnet-version: 6.0.x + - name: Setup .NET 8.0 + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 8.0.x - - name: Setup NuGet - uses: NuGet/setup-nuget@v1.0.5 + - name: Setup NuGet + uses: NuGet/setup-nuget@v1.0.5 - - name: Restore dependencies - run: dotnet restore $SOLUTION + - name: Restore dependencies + run: dotnet restore $SOLUTION - - name: Build - run: dotnet build $SOLUTION --configuration $BUILD_CONFIG -p:Version=$BUILD_VERSION --no-restore + - name: Build + run: dotnet build $SOLUTION --configuration $BUILD_CONFIG -p:Version=$BUILD_VERSION --no-restore - - name: Publish - if: startsWith(github.ref, 'refs/tags/v') - run: nuget push **\*.nupkg -Source 'https://api.nuget.org/v3/index.json' -ApiKey ${{secrets.NUGET_API_KEY}} + - name: Publish + if: startsWith(github.ref, 'refs/tags/v') + run: nuget push **\*.nupkg -Source 'https://api.nuget.org/v3/index.json' -ApiKey ${{secrets.NUGET_API_KEY}} diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 4ae649ee..59ea65e5 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -3,46 +3,55 @@ name: Docs on: push: branches: - - main + - main paths: - - docs/** - - src/** - - .github/workflows/docs.yml + - docs/** + - src/** + - .github/workflows/docs.yml pull_request: branches: - - main + - main paths: - - docs/** - - .github/workflows/docs.yml + - docs/** + - .github/workflows/docs.yml workflow_dispatch: jobs: generate-docs: - runs-on: windows-latest steps: - - uses: actions/checkout@v2 - - - name: Setup .NET 6.0 - uses: actions/setup-dotnet@v1 - with: - dotnet-version: 6.0.x - - - name: Setup DocFX - uses: crazy-max/ghaction-chocolatey@v1 - with: - args: install docfx - - - name: DocFX Build - working-directory: docs - run: docfx .\docfx.json - continue-on-error: false - - - name: Publish - if: github.event_name == 'push' - uses: peaceiris/actions-gh-pages@v3 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: docs/_site - force_orphan: true + - uses: actions/checkout@v2 + + - name: Setup .NET 6.0 + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 6.0.x + + - name: Setup .NET 7.0 + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 7.0.x + + - name: Setup .NET 8.0 + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 8.0.x + + - name: Setup DocFX + uses: crazy-max/ghaction-chocolatey@v1 + with: + args: install docfx + + - name: DocFX Build + working-directory: docs + run: docfx .\docfx.json + continue-on-error: false + + - name: Publish + if: github.event_name == 'push' + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: docs/_site + force_orphan: true diff --git a/.gitignore b/.gitignore index b958e232..8a30d258 100644 --- a/.gitignore +++ b/.gitignore @@ -396,5 +396,3 @@ FodyWeavers.xsd # JetBrains Rider *.sln.iml -*.dcvr -*.dcvr.settings \ No newline at end of file diff --git a/samples/AndroidCoreSamples/AndroidCoreSamples.csproj b/samples/AndroidCoreSamples/AndroidCoreSamples.csproj index 1cde6b97..1849fad8 100644 --- a/samples/AndroidCoreSamples/AndroidCoreSamples.csproj +++ b/samples/AndroidCoreSamples/AndroidCoreSamples.csproj @@ -1,13 +1,13 @@ - net6.0 + net6.0;net7.0;net8.0 false - + diff --git a/samples/MADESampleApp/MADESampleApp.csproj b/samples/MADESampleApp/MADESampleApp.csproj index 036ca2c6..3b75f0e0 100644 --- a/samples/MADESampleApp/MADESampleApp.csproj +++ b/samples/MADESampleApp/MADESampleApp.csproj @@ -1,13 +1,13 @@ - net6.0 + net6.0;net7.0;net8.0 false - + diff --git a/samples/TelerikUwpSdkSample/TelerikUwpSdkSample.csproj b/samples/TelerikUwpSdkSample/TelerikUwpSdkSample.csproj index 9e241614..d592207f 100644 --- a/samples/TelerikUwpSdkSample/TelerikUwpSdkSample.csproj +++ b/samples/TelerikUwpSdkSample/TelerikUwpSdkSample.csproj @@ -1,13 +1,13 @@ - net6.0 + net6.0;net7.0;net8.0 false - + diff --git a/samples/WindowsCommunityToolkitSampleApp/WindowsCommunityToolkitSampleApp.csproj b/samples/WindowsCommunityToolkitSampleApp/WindowsCommunityToolkitSampleApp.csproj index 4b9ef814..73fb15f2 100644 --- a/samples/WindowsCommunityToolkitSampleApp/WindowsCommunityToolkitSampleApp.csproj +++ b/samples/WindowsCommunityToolkitSampleApp/WindowsCommunityToolkitSampleApp.csproj @@ -1,13 +1,13 @@ - net6.0 + net6.0;net7.0;net8.0 false - + diff --git a/src/Legerity.Android/AndroidByExtras.cs b/src/Legerity.Android/AndroidByExtras.cs index 85c2e8e0..04fe14b3 100644 --- a/src/Legerity.Android/AndroidByExtras.cs +++ b/src/Legerity.Android/AndroidByExtras.cs @@ -1,9 +1,5 @@ namespace Legerity.Android; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Android.UiAutomator; - /// /// Defines a collection of extra locator constraints for . /// @@ -28,4 +24,4 @@ public static By PartialContentDescription(string contentDesc) { return new ByAndroidUIAutomator(new AndroidUiSelector().DescriptionContains(contentDesc)); } -} \ No newline at end of file +} diff --git a/src/Legerity.Android/Elements/AndroidElementWrapper.cs b/src/Legerity.Android/Elements/AndroidElementWrapper.cs index 51eef248..305e12ce 100644 --- a/src/Legerity.Android/Elements/AndroidElementWrapper.cs +++ b/src/Legerity.Android/Elements/AndroidElementWrapper.cs @@ -1,27 +1,20 @@ namespace Legerity.Android.Elements; using System; - -using Legerity.Exceptions; - -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Android; -using OpenQA.Selenium.Remote; -using OpenQA.Selenium.Support.UI; +using Exceptions; /// -/// Defines an element wrapper for a . +/// Defines an element wrapper for an Android . /// -public class AndroidElementWrapper : ElementWrapper +public class AndroidElementWrapper : ElementWrapper { /// /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public AndroidElementWrapper(AndroidElement element) + public AndroidElementWrapper(WebElement element) : base(element) { } @@ -29,50 +22,22 @@ public AndroidElementWrapper(AndroidElement element) /// /// Gets the instance of the Appium driver for the Android application. /// - public AndroidDriver Driver => this.ElementDriver as AndroidDriver; + public AndroidDriver Driver => ElementDriver as AndroidDriver; /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator AndroidElementWrapper(AndroidElement element) + public static implicit operator AndroidElementWrapper(WebElement element) { return new AndroidElementWrapper(element); } - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator AndroidElementWrapper(AppiumWebElement element) - { - return new AndroidElementWrapper(element as AndroidElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator AndroidElementWrapper(RemoteWebElement element) - { - return new AndroidElementWrapper(element as AndroidElement); - } - /// /// Determines whether the specified element is shown with the specified timeout. /// @@ -88,7 +53,7 @@ protected void VerifyDriverElementShown(By locator, TimeSpan? timeout) { try { - if (this.Driver.FindElement(locator) == null) + if (Driver.FindElement(locator) == null) { throw new ElementNotShownException(locator.ToString()); } @@ -100,7 +65,7 @@ protected void VerifyDriverElementShown(By locator, TimeSpan? timeout) } else { - var wait = new WebDriverWait(this.Driver, timeout.Value); + var wait = new WebDriverWait(Driver, timeout.Value); wait.Until(driver => driver.FindElement(locator) != null); } } @@ -119,15 +84,15 @@ protected void VerifyDriverElementsShown(By locator, TimeSpan? timeout) { if (timeout == null) { - if (this.Driver.FindElements(locator).Count == 0) + if (Driver.FindElements(locator).Count == 0) { throw new ElementsNotShownException(locator.ToString()); } } else { - var wait = new WebDriverWait(this.Driver, timeout.Value); + var wait = new WebDriverWait(Driver, timeout.Value); wait.Until(driver => driver.FindElements(locator).Count != 0); } } -} \ No newline at end of file +} diff --git a/src/Legerity.Android/Elements/Core/Button.cs b/src/Legerity.Android/Elements/Core/Button.cs index 6f8a4fab..9bff460f 100644 --- a/src/Legerity.Android/Elements/Core/Button.cs +++ b/src/Legerity.Android/Elements/Core/Button.cs @@ -1,12 +1,9 @@ namespace Legerity.Android.Elements.Core; -using Legerity.Android.Elements; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Android; -using OpenQA.Selenium.Remote; +using Elements; /// -/// Defines a wrapper for the core Android Button control. +/// Defines a wrapper for the core Android Button control. /// public class Button : AndroidElementWrapper { @@ -14,52 +11,24 @@ public class Button : AndroidElementWrapper /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public Button(AndroidElement element) + public Button(WebElement element) : base(element) { } /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator Button(AndroidElement element) + public static implicit operator Button(WebElement element) { return new Button(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator Button(AppiumWebElement element) - { - return new Button(element as AndroidElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator Button(RemoteWebElement element) - { - return new Button(element as AndroidElement); - } -} \ No newline at end of file +} diff --git a/src/Legerity.Android/Elements/Core/CheckBox.cs b/src/Legerity.Android/Elements/Core/CheckBox.cs index 978c5456..a0d519bc 100644 --- a/src/Legerity.Android/Elements/Core/CheckBox.cs +++ b/src/Legerity.Android/Elements/Core/CheckBox.cs @@ -1,13 +1,9 @@ namespace Legerity.Android.Elements.Core; using Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Android; -using OpenQA.Selenium.Remote; /// -/// Defines a wrapper for the core Android CheckBox control. +/// Defines a wrapper for the core Android CheckBox control. /// public class CheckBox : AndroidElementWrapper { @@ -15,9 +11,9 @@ public class CheckBox : AndroidElementWrapper /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public CheckBox(AndroidElement element) + public CheckBox(WebElement element) : base(element) { } @@ -29,47 +25,19 @@ public CheckBox(AndroidElement element) public virtual bool IsChecked => this.GetCheckedState(); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator CheckBox(AndroidElement element) + public static implicit operator CheckBox(WebElement element) { return new CheckBox(element); } - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator CheckBox(AppiumWebElement element) - { - return new CheckBox(element as AndroidElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator CheckBox(RemoteWebElement element) - { - return new CheckBox(element as AndroidElement); - } - /// /// Checks the check box on. /// @@ -78,12 +46,12 @@ public static implicit operator CheckBox(RemoteWebElement element) /// Thrown when an element is no longer valid in the document DOM. public virtual void CheckOn() { - if (this.IsChecked) + if (IsChecked) { return; } - this.Click(); + Click(); } /// @@ -94,11 +62,11 @@ public virtual void CheckOn() /// Thrown when an element is no longer valid in the document DOM. public virtual void CheckOff() { - if (!this.IsChecked) + if (!IsChecked) { return; } - this.Click(); + Click(); } -} \ No newline at end of file +} diff --git a/src/Legerity.Android/Elements/Core/DatePicker.cs b/src/Legerity.Android/Elements/Core/DatePicker.cs index e7f0d06d..b9da2dba 100644 --- a/src/Legerity.Android/Elements/Core/DatePicker.cs +++ b/src/Legerity.Android/Elements/Core/DatePicker.cs @@ -3,17 +3,14 @@ namespace Legerity.Android.Elements.Core; using System; using System.Collections.Generic; using System.Linq; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Android; -using OpenQA.Selenium.Remote; +using Extensions; /// -/// Defines a wrapper for the core Android DatePicker control. +/// Defines a wrapper for the core Android DatePicker control. /// public class DatePicker : AndroidElementWrapper { - private readonly Dictionary months = new() + private readonly Dictionary _months = new() { { "Jan", "01" }, { "Feb", "02" }, @@ -33,9 +30,9 @@ public class DatePicker : AndroidElementWrapper /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public DatePicker(AndroidElement element) + public DatePicker(WebElement element) : base(element) { } @@ -47,7 +44,7 @@ public DatePicker(AndroidElement element) /// /// /// Thrown when no element matches the expected locator. - public virtual TextView DateTextView => this.FindElement(By.Id("android:id/date_picker_header_date")); + public virtual TextView DateTextView => FindElement(By.Id("android:id/date_picker_header_date")); /// /// Gets the element associated with the year text. @@ -56,75 +53,49 @@ public DatePicker(AndroidElement element) /// /// /// Thrown when no element matches the expected locator. - public virtual TextView YearTextView => this.FindElement(By.Id("android:id/date_picker_header_year")); + public virtual TextView YearTextView => FindElement(By.Id("android:id/date_picker_header_year")); /// /// Gets the element associated with the day picker. /// /// Thrown when no element matches the expected locator. - public virtual View DayPickerView => this.FindElement(By.Id("android:id/day_picker_view_pager")); + public virtual View DayPickerView => FindElement(By.Id("android:id/day_picker_view_pager")); /// /// Gets the element associated with the next month button. /// /// Thrown when no element matches the expected locator. - public virtual Button NextMonthButton => this.Element.FindElementByAndroidUIAutomator("UiSelector().description(\"Next month\")"); + public virtual Button NextMonthButton => + Element.FindElementByAndroidUIAutomator("UiSelector().description(\"Next month\")"); /// /// Gets the element associated with the previous month button. /// /// Thrown when no element matches the expected locator. - public virtual Button PreviousMonthButton => this.Element.FindElementByAndroidUIAutomator("UiSelector().description(\"Previous month\")"); + public virtual Button PreviousMonthButton => + Element.FindElementByAndroidUIAutomator("UiSelector().description(\"Previous month\")"); /// /// Gets the selected date/time value. /// /// Thrown when an element is no longer valid in the document DOM. /// Thrown when no element matches the expected locator. - public virtual DateTime SelectedDate => this.GetCurrentViewDate(); + public virtual DateTime SelectedDate => GetCurrentViewDate(); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator DatePicker(AndroidElement element) + public static implicit operator DatePicker(WebElement element) { return new DatePicker(element); } - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator DatePicker(AppiumWebElement element) - { - return new DatePicker(element as AndroidElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator DatePicker(RemoteWebElement element) - { - return new DatePicker(element as AndroidElement); - } - /// /// Sets the selected date of the date picker. /// @@ -135,26 +106,26 @@ public static implicit operator DatePicker(RemoteWebElement element) /// Thrown when no element matches the expected locator. public virtual void SetDate(DateTime date) { - DateTime currentViewDate = this.GetCurrentViewDate(); + var currentViewDate = GetCurrentViewDate(); - int monthDifference = ((date.Year - currentViewDate.Year) * 12) + date.Month - currentViewDate.Month; + var monthDifference = ((date.Year - currentViewDate.Year) * 12) + date.Month - currentViewDate.Month; if (monthDifference > 0) { - for (int i = 0; i < monthDifference; i++) + for (var i = 0; i < monthDifference; i++) { - this.NextMonthButton.Click(); + NextMonthButton.Click(); } } else { - for (int i = 0; i < Math.Abs(monthDifference); i++) + for (var i = 0; i < Math.Abs(monthDifference); i++) { - this.PreviousMonthButton.Click(); + PreviousMonthButton.Click(); } } - View item = this.DayPickerView.Element.FindElementByAndroidUIAutomator($"UiSelector().text(\"{date.Day}\")"); + View item = DayPickerView.Element.FindElementByAndroidUIAutomator($"UiSelector().text(\"{date.Day}\")"); item.Click(); } @@ -162,25 +133,25 @@ public virtual void SetDate(DateTime date) /// Thrown when an element is no longer valid in the document DOM. private DateTime GetCurrentViewDate() { - string currentYear = this.YearTextView.Text; - string currentDate = this.DateTextView.Text; - return this.GetCurrentViewDate(currentDate, currentYear); + var currentYear = YearTextView.Text; + var currentDate = DateTextView.Text; + return GetCurrentViewDate(currentDate, currentYear); } private DateTime GetCurrentViewDate(string currentDate, string currentYear) { - string day = string.Join(string.Empty, currentDate.Where(char.IsDigit)).Trim(); + var day = string.Join(string.Empty, currentDate.Where(char.IsDigit)).Trim(); var currentDateSplit = currentDate.Split(',').ToList(); - string currentMonthPart = currentDateSplit.LastOrDefault(); + var currentMonthPart = currentDateSplit.LastOrDefault(); - this.months.TryGetValue( + _months.TryGetValue( string.Join(string.Empty, (currentMonthPart ?? string.Empty).Where(char.IsLetter)).Trim(), - out string month); + out var month); - string year = string.Join(string.Empty, currentYear.Where(char.IsDigit)).Trim(); + var year = string.Join(string.Empty, currentYear.Where(char.IsDigit)).Trim(); - string dateString = $"{day}/{month}/{year}"; + var dateString = $"{day}/{month}/{year}"; return DateTime.ParseExact(dateString, @"d/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture); } -} \ No newline at end of file +} diff --git a/src/Legerity.Android/Elements/Core/EditText.cs b/src/Legerity.Android/Elements/Core/EditText.cs index 7a837e00..77440513 100644 --- a/src/Legerity.Android/Elements/Core/EditText.cs +++ b/src/Legerity.Android/Elements/Core/EditText.cs @@ -1,20 +1,15 @@ namespace Legerity.Android.Elements.Core; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Android; -using OpenQA.Selenium.Remote; - /// -/// Defines a wrapper for the core Android EditText control. +/// Defines a wrapper for the core Android EditText control. /// public class EditText : AndroidElementWrapper { /// /// Initializes a new instance of the class. /// - /// The representing the element. - public EditText(AndroidElement element) + /// The representing the element. + public EditText(WebElement element) : base(element) { } @@ -22,50 +17,22 @@ public EditText(AndroidElement element) /// /// Gets the text value of the text box. /// - public virtual string Text => this.Element.Text; + public virtual string Text => Element.Text; /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator EditText(AndroidElement element) + public static implicit operator EditText(WebElement element) { return new EditText(element); } - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator EditText(AppiumWebElement element) - { - return new EditText(element as AndroidElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator EditText(RemoteWebElement element) - { - return new EditText(element as AndroidElement); - } - /// /// Sets the text of the text box to the specified text. /// @@ -75,8 +42,8 @@ public static implicit operator EditText(RemoteWebElement element) /// Thrown when an element is not visible. public virtual void SetText(string text) { - this.ClearText(); - this.AppendText(text); + ClearText(); + AppendText(text); } /// @@ -88,8 +55,8 @@ public virtual void SetText(string text) /// Thrown when an element is no longer valid in the document DOM. public virtual void AppendText(string text) { - this.Click(); - this.Element.SendKeys(text); + Click(); + Element.SendKeys(text); } /// @@ -100,7 +67,7 @@ public virtual void AppendText(string text) /// Thrown when an element is no longer valid in the document DOM. public virtual void ClearText() { - this.Click(); - this.Element.Clear(); + Click(); + Element.Clear(); } -} \ No newline at end of file +} diff --git a/src/Legerity.Android/Elements/Core/RadioButton.cs b/src/Legerity.Android/Elements/Core/RadioButton.cs index d3935645..339e44e6 100644 --- a/src/Legerity.Android/Elements/Core/RadioButton.cs +++ b/src/Legerity.Android/Elements/Core/RadioButton.cs @@ -1,13 +1,9 @@ namespace Legerity.Android.Elements.Core; using Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Android; -using OpenQA.Selenium.Remote; /// -/// Defines a wrapper for the core Android RadioButton control. +/// Defines a wrapper for the core Android RadioButton control. /// public class RadioButton : Button { @@ -15,9 +11,9 @@ public class RadioButton : Button /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public RadioButton(AndroidElement element) + public RadioButton(WebElement element) : base(element) { } @@ -29,44 +25,16 @@ public RadioButton(AndroidElement element) public virtual bool IsSelected => this.GetCheckedState(); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator RadioButton(AndroidElement element) + public static implicit operator RadioButton(WebElement element) { return new RadioButton(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator RadioButton(AppiumWebElement element) - { - return new RadioButton(element as AndroidElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator RadioButton(RemoteWebElement element) - { - return new RadioButton(element as AndroidElement); - } -} \ No newline at end of file +} diff --git a/src/Legerity.Android/Elements/Core/Spinner.cs b/src/Legerity.Android/Elements/Core/Spinner.cs index 590ddfe0..f652ca4d 100644 --- a/src/Legerity.Android/Elements/Core/Spinner.cs +++ b/src/Legerity.Android/Elements/Core/Spinner.cs @@ -1,12 +1,7 @@ namespace Legerity.Android.Elements.Core; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Android; -using OpenQA.Selenium.Remote; - /// -/// Defines a wrapper for the core Android Spinner control. +/// Defines a wrapper for the core Android Spinner control. /// public class Spinner : AndroidElementWrapper { @@ -14,9 +9,9 @@ public class Spinner : AndroidElementWrapper /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public Spinner(AndroidElement element) + public Spinner(WebElement element) : base(element) { } @@ -25,50 +20,22 @@ public Spinner(AndroidElement element) /// Gets the currently selected item. /// /// Thrown when no element matches the expected locator. - public virtual string SelectedItem => this.GetSelectedItem(); + public virtual string SelectedItem => GetSelectedItem(); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator Spinner(AndroidElement element) + public static implicit operator Spinner(WebElement element) { return new Spinner(element); } - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator Spinner(AppiumWebElement element) - { - return new Spinner(element as AndroidElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator Spinner(RemoteWebElement element) - { - return new Spinner(element as AndroidElement); - } - /// /// Selects an item in the combo-box with the specified item name. /// @@ -81,12 +48,12 @@ public static implicit operator Spinner(RemoteWebElement element) /// Thrown when no element matches the expected locator. public virtual void SelectItem(string name) { - this.Click(); + Click(); var locator = new ByAndroidUIAutomator( $"new UiScrollable(new UiSelector()).scrollIntoView(new UiSelector().text(\"{name}\"));"); - AndroidElement item = this.Driver.FindElement(locator); + var item = Driver.FindElement(locator); item.Click(); } @@ -101,12 +68,12 @@ public virtual void SelectItem(string name) /// Thrown when no element matches the expected locator. public virtual void SelectItemByPartialName(string partialName) { - this.Click(); + Click(); var locator = new ByAndroidUIAutomator( $"new UiScrollable(new UiSelector()).scrollIntoView(new UiSelector().textContains(\"{partialName}\"));"); - AndroidElement item = this.Driver.FindElement(locator); + var item = Driver.FindElement(locator); item.Click(); } @@ -114,7 +81,7 @@ public virtual void SelectItemByPartialName(string partialName) /// Thrown when no element matches the expected locator. private string GetSelectedItem() { - TextView textElement = this.FindElement(By.ClassName("android.widget.TextView")); + TextView textElement = FindElement(By.ClassName("android.widget.TextView")); return textElement.Text; } -} \ No newline at end of file +} diff --git a/src/Legerity.Android/Elements/Core/Switch.cs b/src/Legerity.Android/Elements/Core/Switch.cs index 66e592ae..45abb2a8 100644 --- a/src/Legerity.Android/Elements/Core/Switch.cs +++ b/src/Legerity.Android/Elements/Core/Switch.cs @@ -1,13 +1,9 @@ namespace Legerity.Android.Elements.Core; using Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Android; -using OpenQA.Selenium.Remote; /// -/// Defines a wrapper for the core Android Switch control. +/// Defines a wrapper for the core Android Switch control. /// public class Switch : AndroidElementWrapper { @@ -15,9 +11,9 @@ public class Switch : AndroidElementWrapper /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public Switch(AndroidElement element) + public Switch(WebElement element) : base(element) { } @@ -29,47 +25,19 @@ public Switch(AndroidElement element) public virtual bool IsOn => this.GetCheckedState(); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator Switch(AndroidElement element) + public static implicit operator Switch(WebElement element) { return new Switch(element); } - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator Switch(AppiumWebElement element) - { - return new Switch(element as AndroidElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator Switch(RemoteWebElement element) - { - return new Switch(element as AndroidElement); - } - /// /// Toggles the switch on. /// @@ -78,12 +46,12 @@ public static implicit operator Switch(RemoteWebElement element) /// Thrown when an element is no longer valid in the document DOM. public virtual void ToggleOn() { - if (this.IsOn) + if (IsOn) { return; } - this.Click(); + Click(); } /// @@ -94,11 +62,11 @@ public virtual void ToggleOn() /// Thrown when an element is no longer valid in the document DOM. public virtual void ToggleOff() { - if (!this.IsOn) + if (!IsOn) { return; } - this.Click(); + Click(); } -} \ No newline at end of file +} diff --git a/src/Legerity.Android/Elements/Core/TextView.cs b/src/Legerity.Android/Elements/Core/TextView.cs index e3ff3850..4a1514b2 100644 --- a/src/Legerity.Android/Elements/Core/TextView.cs +++ b/src/Legerity.Android/Elements/Core/TextView.cs @@ -1,12 +1,7 @@ namespace Legerity.Android.Elements.Core; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Android; -using OpenQA.Selenium.Remote; - /// -/// Defines a wrapper for the core Android TextView control. +/// Defines a wrapper for the core Android TextView control. /// public class TextView : AndroidElementWrapper { @@ -14,9 +9,9 @@ public class TextView : AndroidElementWrapper /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public TextView(AndroidElement element) + public TextView(WebElement element) : base(element) { } @@ -25,47 +20,19 @@ public TextView(AndroidElement element) /// Gets the text value of the text view. /// /// Thrown when an element is no longer valid in the document DOM. - public virtual string Text => this.Element.Text; + public virtual string Text => Element.Text; /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator TextView(AndroidElement element) + public static implicit operator TextView(WebElement element) { return new TextView(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator TextView(AppiumWebElement element) - { - return new TextView(element as AndroidElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator TextView(RemoteWebElement element) - { - return new TextView(element as AndroidElement); - } -} \ No newline at end of file +} diff --git a/src/Legerity.Android/Elements/Core/ToggleButton.cs b/src/Legerity.Android/Elements/Core/ToggleButton.cs index 044325e2..38d78a71 100644 --- a/src/Legerity.Android/Elements/Core/ToggleButton.cs +++ b/src/Legerity.Android/Elements/Core/ToggleButton.cs @@ -1,13 +1,9 @@ namespace Legerity.Android.Elements.Core; using Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Android; -using OpenQA.Selenium.Remote; /// -/// Defines a wrapper for the core Android ToggleButton control. +/// Defines a wrapper for the core Android ToggleButton control. /// public class ToggleButton : Button { @@ -15,9 +11,9 @@ public class ToggleButton : Button /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public ToggleButton(AndroidElement element) + public ToggleButton(WebElement element) : base(element) { } @@ -29,47 +25,19 @@ public ToggleButton(AndroidElement element) public virtual bool IsOn => this.GetCheckedState(); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator ToggleButton(AndroidElement element) + public static implicit operator ToggleButton(WebElement element) { return new ToggleButton(element); } - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator ToggleButton(AppiumWebElement element) - { - return new ToggleButton(element as AndroidElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator ToggleButton(RemoteWebElement element) - { - return new ToggleButton(element as AndroidElement); - } - /// /// Toggles the button on. /// @@ -78,12 +46,12 @@ public static implicit operator ToggleButton(RemoteWebElement element) /// Thrown when an element is no longer valid in the document DOM. public virtual void ToggleOn() { - if (this.IsOn) + if (IsOn) { return; } - this.Click(); + Click(); } /// @@ -94,11 +62,11 @@ public virtual void ToggleOn() /// Thrown when an element is no longer valid in the document DOM. public virtual void ToggleOff() { - if (!this.IsOn) + if (!IsOn) { return; } - this.Click(); + Click(); } -} \ No newline at end of file +} diff --git a/src/Legerity.Android/Elements/Core/View.cs b/src/Legerity.Android/Elements/Core/View.cs index 856c85cd..c837978f 100644 --- a/src/Legerity.Android/Elements/Core/View.cs +++ b/src/Legerity.Android/Elements/Core/View.cs @@ -1,12 +1,9 @@ namespace Legerity.Android.Elements.Core; -using Legerity.Android.Elements; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Android; -using OpenQA.Selenium.Remote; +using Elements; /// -/// Defines a wrapper for the core Android View base control. +/// Defines a wrapper for the core Android View base control. /// public class View : AndroidElementWrapper { @@ -14,52 +11,24 @@ public class View : AndroidElementWrapper /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public View(AndroidElement element) + public View(WebElement element) : base(element) { } /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator View(AndroidElement element) + public static implicit operator View(WebElement element) { return new View(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator View(AppiumWebElement element) - { - return new View(element as AndroidElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator View(RemoteWebElement element) - { - return new View(element as AndroidElement); - } -} \ No newline at end of file +} diff --git a/src/Legerity.Android/Extensions/AndroidElementWrapperExtensions.cs b/src/Legerity.Android/Extensions/AndroidElementWrapperExtensions.cs index 7e1bc936..33b7e338 100644 --- a/src/Legerity.Android/Extensions/AndroidElementWrapperExtensions.cs +++ b/src/Legerity.Android/Extensions/AndroidElementWrapperExtensions.cs @@ -1,9 +1,7 @@ namespace Legerity.Android.Extensions; using System; -using Legerity.Android.Elements; -using OpenQA.Selenium; -using OpenQA.Selenium.Support.UI; +using Elements; /// /// Defines a collection of extensions for objects. @@ -86,4 +84,4 @@ public static TResult WaitUntil( return WaitUntil(element, condition, timeout, retries - 1); } } -} \ No newline at end of file +} diff --git a/src/Legerity.Android/Extensions/AttributeExtensions.cs b/src/Legerity.Android/Extensions/AttributeExtensions.cs index 2bee18ff..52a3eb7d 100644 --- a/src/Legerity.Android/Extensions/AttributeExtensions.cs +++ b/src/Legerity.Android/Extensions/AttributeExtensions.cs @@ -1,7 +1,6 @@ namespace Legerity.Android.Extensions; using System; -using OpenQA.Selenium; /// /// Defines a collection of extensions for retrieving element attributes. @@ -59,4 +58,4 @@ public static bool GetCheckedState(this IElementWrapper elem { return GetCheckedState(element.Element); } -} \ No newline at end of file +} diff --git a/src/Legerity.Android/Extensions/ElementExtensions.cs b/src/Legerity.Android/Extensions/ElementExtensions.cs new file mode 100644 index 00000000..6d1bc7b7 --- /dev/null +++ b/src/Legerity.Android/Extensions/ElementExtensions.cs @@ -0,0 +1,10 @@ +namespace Legerity.Android.Extensions; + +public static class ElementExtensions +{ + /// Thrown when no element matches the expected locator. + public static WebElement FindElementByAndroidUIAutomator(this WebElement element, string selector) + { + return element.FindElement(MobileBy.AndroidUIAutomator(selector)) as WebElement; + } +} diff --git a/src/Legerity.Android/Extensions/LegerityTestClassExtensions.cs b/src/Legerity.Android/Extensions/LegerityTestClassExtensions.cs index 6c87eed6..51fed535 100644 --- a/src/Legerity.Android/Extensions/LegerityTestClassExtensions.cs +++ b/src/Legerity.Android/Extensions/LegerityTestClassExtensions.cs @@ -2,8 +2,6 @@ namespace Legerity.Android.Extensions; using System; using Exceptions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium.Android; /// /// Defines a collection of extensions for instances. @@ -31,13 +29,13 @@ public static class LegerityTestClassExtensions /// Thrown when: /// - The Appium server could not be found when running with true. /// - public static AndroidDriver StartAndroidApp( + public static AndroidDriver StartAndroidApp( this LegerityTestClass testClass, Func waitUntil = default, TimeSpan? waitUntilTimeout = default, int waitUntilRetries = 0) { - return testClass.StartApp(waitUntil, waitUntilTimeout, waitUntilRetries) as AndroidDriver; + return testClass.StartApp(waitUntil, waitUntilTimeout, waitUntilRetries) as AndroidDriver; } /// @@ -67,7 +65,7 @@ public static AndroidDriver StartAndroidApp( /// Thrown when: /// - The Appium server could not be found when running with true. /// - public static AndroidDriver StartAndroidApp( + public static AndroidDriver StartAndroidApp( this LegerityTestClass testClass, AndroidAppManagerOptions options, Func waitUntil = default, @@ -75,6 +73,6 @@ public static AndroidDriver StartAndroidApp( int waitUntilRetries = 0) { return testClass.StartApp(options, waitUntil, waitUntilTimeout, waitUntilRetries) as - AndroidDriver; + AndroidDriver; } -} \ No newline at end of file +} diff --git a/src/Legerity.Android/GlobalUsings.cs b/src/Legerity.Android/GlobalUsings.cs new file mode 100644 index 00000000..f8d561d0 --- /dev/null +++ b/src/Legerity.Android/GlobalUsings.cs @@ -0,0 +1,7 @@ +// Global using directives + +global using OpenQA.Selenium; +global using OpenQA.Selenium.Appium; +global using OpenQA.Selenium.Appium.Android; +global using OpenQA.Selenium.Appium.Android.UiAutomator; +global using OpenQA.Selenium.Support.UI; diff --git a/src/Legerity.Android/Legerity.Android.csproj b/src/Legerity.Android/Legerity.Android.csproj index ea829332..fade1d98 100644 --- a/src/Legerity.Android/Legerity.Android.csproj +++ b/src/Legerity.Android/Legerity.Android.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + net6.0;net7.0;net8.0 true Legerity for Android - Framework for UI testing with Selenium/Appium @@ -22,7 +22,7 @@ - + diff --git a/src/Legerity.Core/Android/AndroidAppManagerOptions.cs b/src/Legerity.Core/Android/AndroidAppManagerOptions.cs index 29d2d5fc..2488d911 100644 --- a/src/Legerity.Core/Android/AndroidAppManagerOptions.cs +++ b/src/Legerity.Core/Android/AndroidAppManagerOptions.cs @@ -1,9 +1,6 @@ namespace Legerity.Android; -using System; using System.Collections.Generic; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Enums; /// /// Defines a specific for an Android application. @@ -113,13 +110,13 @@ public AndroidAppManagerOptions( string deviceId, params (string, object)[] additionalOptions) { - this.AppId = appId; - this.AppActivity = appActivity; - this.AppPath = appPath; - this.OSVersion = osVersion; - this.DeviceName = deviceName; - this.DeviceId = deviceId; - this.AdditionalOptions = additionalOptions; + AppId = appId; + AppActivity = appActivity; + AppPath = appPath; + OSVersion = osVersion; + DeviceName = deviceName; + DeviceId = deviceId; + AdditionalOptions = additionalOptions; } /// @@ -152,11 +149,6 @@ public AndroidAppManagerOptions( /// public string DeviceId { get; set; } - /// - /// Gets or sets a value indicating whether to launch the Appium server instance. - /// - public bool LaunchAppiumServer { get; set; } - /// /// Configures the with the specified additional options. /// @@ -164,36 +156,36 @@ public override void Configure() { base.Configure(); - this.AppiumOptions.AddAdditionalCapability(MobileCapabilityType.PlatformName, "Android"); + AppiumOptions.AddAdditionalAppiumOption(MobileCapabilityType.PlatformName, "Android"); - if (!string.IsNullOrWhiteSpace(this.OSVersion)) + if (!string.IsNullOrWhiteSpace(OSVersion)) { - this.AppiumOptions.AddAdditionalCapability(MobileCapabilityType.PlatformVersion, this.OSVersion); + AppiumOptions.AddAdditionalAppiumOption(MobileCapabilityType.PlatformVersion, OSVersion); } - if (!string.IsNullOrWhiteSpace(this.DeviceName)) + if (!string.IsNullOrWhiteSpace(DeviceName)) { - this.AppiumOptions.AddAdditionalCapability(MobileCapabilityType.DeviceName, this.DeviceName); + AppiumOptions.AddAdditionalAppiumOption(MobileCapabilityType.DeviceName, DeviceName); } - if (!string.IsNullOrWhiteSpace(this.DeviceId)) + if (!string.IsNullOrWhiteSpace(DeviceId)) { - this.AppiumOptions.AddAdditionalCapability(MobileCapabilityType.Udid, this.DeviceId); + AppiumOptions.AddAdditionalAppiumOption(MobileCapabilityType.Udid, DeviceId); } - if (!string.IsNullOrWhiteSpace(this.AppId)) + if (!string.IsNullOrWhiteSpace(AppId)) { - this.AppiumOptions.AddAdditionalCapability("appPackage", this.AppId); + AppiumOptions.AddAdditionalAppiumOption("appPackage", AppId); } - if (!string.IsNullOrWhiteSpace(this.AppActivity)) + if (!string.IsNullOrWhiteSpace(AppActivity)) { - this.AppiumOptions.AddAdditionalCapability("appActivity", this.AppActivity); + AppiumOptions.AddAdditionalAppiumOption("appActivity", AppActivity); } - if (!string.IsNullOrWhiteSpace(this.AppPath)) + if (!string.IsNullOrWhiteSpace(AppPath)) { - this.AppiumOptions.AddAdditionalCapability("app", this.AppPath); + AppiumOptions.AddAdditionalAppiumOption("app", AppPath); } } @@ -205,44 +197,44 @@ public override void Configure() /// public void Configure((string, object)[] additionalOptions) { - this.AdditionalOptions = additionalOptions; - this.Configure(); + AdditionalOptions = additionalOptions; + Configure(); } /// Returns a string that represents the current object. /// A string that represents the current object. public override string ToString() { - return $"Platform [Android], {base.ToString()}, {this.GetOptionDetails()}"; + return $"Platform [Android], {base.ToString()}, {GetOptionDetails()}"; } private string GetOptionDetails() { var options = new List(); - if (!string.IsNullOrWhiteSpace(this.AppId)) + if (!string.IsNullOrWhiteSpace(AppId)) { - options.Add($"App ID [{this.AppId}]"); + options.Add($"App ID [{AppId}]"); } - if (!string.IsNullOrWhiteSpace(this.AppPath)) + if (!string.IsNullOrWhiteSpace(AppPath)) { - options.Add($"App Path [{this.AppPath}]"); + options.Add($"App Path [{AppPath}]"); } - if (!string.IsNullOrWhiteSpace(this.DeviceId)) + if (!string.IsNullOrWhiteSpace(DeviceId)) { - options.Add($"Device ID [{this.DeviceId}]"); + options.Add($"Device ID [{DeviceId}]"); } - if (!string.IsNullOrWhiteSpace(this.DeviceName)) + if (!string.IsNullOrWhiteSpace(DeviceName)) { - options.Add($"Device Name [{this.DeviceName}]"); + options.Add($"Device Name [{DeviceName}]"); } - if (this.AdditionalOptions != null) + if (AdditionalOptions != null) { - foreach ((string name, object value) in this.AdditionalOptions) + foreach (var (name, value) in AdditionalOptions) { options.Add($"{name} [{value}]"); } @@ -250,4 +242,4 @@ private string GetOptionDetails() return string.Join(", ", options); } -} \ No newline at end of file +} diff --git a/src/Legerity.Core/AppManager.cs b/src/Legerity.Core/AppManager.cs index 98ca141d..fa942c78 100644 --- a/src/Legerity.Core/AppManager.cs +++ b/src/Legerity.Core/AppManager.cs @@ -2,32 +2,21 @@ namespace Legerity; using System; using System.Collections.Generic; -using Legerity.Android; -using Legerity.Exceptions; -using Legerity.Extensions; -using Legerity.Helpers; -using Legerity.IOS; -using Legerity.Web; -using Legerity.Windows; +using Android; +using Exceptions; +using Extensions; +using Helpers; +using IOS; using Legerity.Windows.Helpers; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium.Android; -using OpenQA.Selenium.Appium.iOS; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Chrome; -using OpenQA.Selenium.Edge; -using OpenQA.Selenium.Firefox; -using OpenQA.Selenium.IE; -using OpenQA.Selenium.Opera; -using OpenQA.Selenium.Remote; -using OpenQA.Selenium.Safari; +using Web; +using Windows; /// /// Defines a manager for the application under test. /// public static class AppManager { - private static readonly List StartedApps = new(); + private static readonly List s_startedApps = new(); /// /// Gets the instance of the started Windows application. @@ -35,7 +24,7 @@ public static class AppManager /// /// This instance should not be used in parallelized test runs. Instead, use the instance returned by the method. /// - public static WindowsDriver WindowsApp => App as WindowsDriver; + public static WindowsDriver WindowsApp => App as WindowsDriver; /// /// Gets the instance of the started Android application. @@ -43,7 +32,7 @@ public static class AppManager /// /// This instance should not be used in parallelized test runs. Instead, use the instance returned by the method. /// - public static AndroidDriver AndroidApp => App as AndroidDriver; + public static AndroidDriver AndroidApp => App as AndroidDriver; /// /// Gets the instance of the started iOS application. @@ -51,7 +40,7 @@ public static class AppManager /// /// This instance should not be used in parallelized test runs. Instead, use the instance returned by the method. /// - public static IOSDriver IOSApp => App as IOSDriver; + public static IOSDriver IOSApp => App as IOSDriver; /// /// Gets the instance of the started web application. @@ -59,23 +48,23 @@ public static class AppManager /// /// This instance should not be used in parallelized test runs. Instead, use the instance returned by the method. /// - public static RemoteWebDriver WebApp => App; + public static WebDriver WebApp => App; /// /// Gets or sets the instance of the started application. /// - /// This could be a , , , or web driver. + /// This could be a , , , or web driver. /// /// /// /// This instance should not be used in parallelized test runs. Instead, use the instance returned by the method. /// - public static RemoteWebDriver App { get; set; } + public static WebDriver App { get; set; } /// /// Gets the instances of started applications. /// - public static IReadOnlyCollection Apps => StartedApps; + public static IReadOnlyCollection Apps => s_startedApps; /// /// Starts the application ready for testing. @@ -103,13 +92,13 @@ public static class AppManager /// - The WinAppDriver could not be found when running with true. /// - The WinAppDriver failed to load when running with true. /// - public static RemoteWebDriver StartApp( + public static WebDriver StartApp( AppManagerOptions opts, Func waitUntil = default, TimeSpan? waitUntilTimeout = default, int waitUntilRetries = 0) { - RemoteWebDriver app = null; + WebDriver app = null; if (opts is AppiumManagerOptions appiumOpts) { @@ -121,98 +110,17 @@ public static RemoteWebDriver StartApp( switch (opts) { case WebAppManagerOptions webOpts: - { - app = webOpts.DriverType switch - { - WebAppDriverType.Chrome => new ChromeDriver( - webOpts.DriverUri, - webOpts.DriverOptions as ChromeOptions ?? new ChromeOptions()), - WebAppDriverType.Firefox => new FirefoxDriver( - webOpts.DriverUri, - webOpts.DriverOptions as FirefoxOptions ?? new FirefoxOptions()), - WebAppDriverType.Opera => new OperaDriver( - webOpts.DriverUri, - webOpts.DriverOptions as OperaOptions ?? new OperaOptions()), - WebAppDriverType.Safari => new SafariDriver( - webOpts.DriverUri, - webOpts.DriverOptions as SafariOptions ?? new SafariOptions()), - WebAppDriverType.Edge => new EdgeDriver( - webOpts.DriverUri, - webOpts.DriverOptions as EdgeOptions ?? new EdgeOptions()), - WebAppDriverType.InternetExplorer => new InternetExplorerDriver( - webOpts.DriverUri, - webOpts.DriverOptions as InternetExplorerOptions ?? new InternetExplorerOptions()), - WebAppDriverType.EdgeChromium => new Microsoft.Edge.SeleniumTools.EdgeDriver( - webOpts.DriverUri, - webOpts.DriverOptions as Microsoft.Edge.SeleniumTools.EdgeOptions ?? - new Microsoft.Edge.SeleniumTools.EdgeOptions { UseChromium = true }), - _ => null - }; - - VerifyAppDriver(app, webOpts); - - if (webOpts.Maximize) - { - app.Manage().Window.Maximize(); - } - else - { - app.Manage().Window.Size = webOpts.DesiredSize; - } - - app.Url = webOpts.Url; + app = StartWebApp(webOpts); break; - } - case WindowsAppManagerOptions winOpts: - { - if (winOpts.LaunchWinAppDriver) - { - WinAppDriverHelper.Run(); - } - - app = new WindowsDriver( - new Uri(winOpts.DriverUri), - winOpts.AppiumOptions); - - VerifyAppDriver(app, winOpts); - - if (winOpts.Maximize) - { - app.Manage().Window.Maximize(); - } - + app = StartWindowsApp(winOpts); break; - } - case AndroidAppManagerOptions androidOpts: - { - if (androidOpts.LaunchAppiumServer) - { - AppiumServerHelper.Run(); - } - - app = new AndroidDriver( - new Uri(androidOpts.DriverUri), - androidOpts.AppiumOptions); - - VerifyAppDriver(app, androidOpts); + app = StartAndroidApp(androidOpts); break; - } - case IOSAppManagerOptions iosOpts: - { - if (iosOpts.LaunchAppiumServer) - { - AppiumServerHelper.Run(); - } - - app = new IOSDriver(new Uri(iosOpts.DriverUri), iosOpts.AppiumOptions); - - VerifyAppDriver(app, iosOpts); + app = StartIOSApp(iosOpts); break; - } - default: VerifyAppDriver(null, opts); break; @@ -236,7 +144,7 @@ webOpts.DriverOptions as Microsoft.Edge.SeleniumTools.EdgeOptions ?? } App = app; - StartedApps.Add(app); + s_startedApps.Add(app); return app; } @@ -261,10 +169,10 @@ public static void StopApp(bool stopServer = true) /// /// An optional value indicating whether to stop the running Appium or WinAppDriver server. Default, false. /// - public static void StopApp(RemoteWebDriver app, bool stopServer = false) + public static void StopApp(WebDriver app, bool stopServer = false) { app?.Quit(); - StartedApps.Remove(app); + s_startedApps.Remove(app); if (!stopServer) { @@ -280,19 +188,112 @@ public static void StopApp(RemoteWebDriver app, bool stopServer = false) /// public static void StopApps() { - StartedApps.ForEach(driver => driver?.Quit()); - StartedApps.Clear(); + s_startedApps.ForEach(driver => driver?.Quit()); + s_startedApps.Clear(); + } + + + private static WebDriver StartIOSApp(IOSAppManagerOptions iosOpts) + { + if (iosOpts.LaunchAppiumServer) + { + AppiumServerHelper.Run(); + } + + var app = new IOSDriver(new Uri(iosOpts.DriverUri), iosOpts.AppiumOptions); + + VerifyAppDriver(app, iosOpts); + return app; + } + + private static WebDriver StartAndroidApp(AndroidAppManagerOptions androidOpts) + { + if (androidOpts.LaunchAppiumServer) + { + AppiumServerHelper.Run(); + } + + var app = new AndroidDriver( + new Uri(androidOpts.DriverUri), + androidOpts.AppiumOptions); + + VerifyAppDriver(app, androidOpts); + return app; + } + + private static WebDriver StartWindowsApp(WindowsAppManagerOptions winOpts) + { + if (winOpts.LaunchAppiumServer || winOpts.LaunchWinAppDriver) + { + AppiumServerHelper.Run(); + } + + var app = new WindowsDriver( + new Uri(winOpts.DriverUri), + winOpts.AppiumOptions); + + VerifyAppDriver(app, winOpts); + + if (winOpts.Maximize) + { + app.Manage().Window.Maximize(); + } + + return app; + } + + private static WebDriver StartWebApp(WebAppManagerOptions webOpts) + { + WebDriver app = webOpts.DriverType switch + { + WebAppDriverType.Chrome => new ChromeDriver( + webOpts.DriverUri, + webOpts.DriverOptions as ChromeOptions ?? new ChromeOptions()), + WebAppDriverType.Firefox => new FirefoxDriver( + webOpts.DriverUri, + webOpts.DriverOptions as FirefoxOptions ?? new FirefoxOptions()), + WebAppDriverType.Opera => new ChromeDriver( + webOpts.DriverUri, + webOpts.DriverOptions as OperaChromiumOptions ?? new OperaChromiumOptions()), + WebAppDriverType.Safari => new SafariDriver( + webOpts.DriverUri, + webOpts.DriverOptions as SafariOptions ?? new SafariOptions()), + WebAppDriverType.Edge => new EdgeDriver( + webOpts.DriverUri, + webOpts.DriverOptions as EdgeOptions ?? new EdgeOptions()), + WebAppDriverType.InternetExplorer => new InternetExplorerDriver( + webOpts.DriverUri, + webOpts.DriverOptions as InternetExplorerOptions ?? new InternetExplorerOptions()), + WebAppDriverType.EdgeChromium => new EdgeDriver( + webOpts.DriverUri, + webOpts.DriverOptions as EdgeOptions ?? new EdgeOptions()), + _ => null + }; + + VerifyAppDriver(app, webOpts); + + if (webOpts.Maximize) + { + app!.Manage().Window.Maximize(); + } + else + { + app!.Manage().Window.Size = webOpts.DesiredSize; + } + + app.Url = webOpts.Url; + return app; } /// Thrown when the driver could not be verified. - private static void VerifyAppDriver(RemoteWebDriver app, AppManagerOptions opts) + private static void VerifyAppDriver(WebDriver app, AppManagerOptions opts) { if (app?.SessionId == null) { throw new DriverLoadFailedException(opts); } - // Set implicit timeout to 2 seconds to make element search to retry every 500 ms for at most three times. + // Set implicit timeout to make element search retry every x ms. app.Manage().Timeouts().ImplicitWait = opts.ImplicitWait; } -} \ No newline at end of file +} diff --git a/src/Legerity.Core/AppManagerOptions.cs b/src/Legerity.Core/AppManagerOptions.cs index 9659f3aa..41c34d74 100644 --- a/src/Legerity.Core/AppManagerOptions.cs +++ b/src/Legerity.Core/AppManagerOptions.cs @@ -1,7 +1,6 @@ namespace Legerity; using System; -using OpenQA.Selenium; /// /// Defines a base model that represents configuration options for the . @@ -33,6 +32,6 @@ public abstract class AppManagerOptions /// A string that represents the current object. public override string ToString() { - return $"Driver URI [{this.DriverUri}]"; + return $"Driver URI [{DriverUri}]"; } -} \ No newline at end of file +} diff --git a/src/Legerity.Core/AppiumManagerOptions.cs b/src/Legerity.Core/AppiumManagerOptions.cs index 5da86e58..57cdab50 100644 --- a/src/Legerity.Core/AppiumManagerOptions.cs +++ b/src/Legerity.Core/AppiumManagerOptions.cs @@ -1,7 +1,5 @@ namespace Legerity; -using OpenQA.Selenium.Appium; - /// /// Defines a base model that represents Appium specific configuration options for the . /// @@ -21,25 +19,30 @@ public abstract class AppiumManagerOptions : AppManagerOptions /// public AppiumOptions AppiumOptions { - get => this.DriverOptions as AppiumOptions; - set => this.DriverOptions = value; + get => DriverOptions as AppiumOptions; + set => DriverOptions = value; } + /// + /// Gets or sets a value indicating whether to launch the Appium server instance. + /// + public bool LaunchAppiumServer { get; set; } + /// /// Configures the with the specified additional options. /// public virtual void Configure() { - this.AppiumOptions = new AppiumOptions(); + AppiumOptions = new AppiumOptions(); - if (this.AdditionalOptions == null) + if (AdditionalOptions == null) { return; } - foreach ((string capabilityName, object capabilityValue) in this.AdditionalOptions) + foreach (var (capabilityName, capabilityValue) in AdditionalOptions) { - this.AppiumOptions.AddAdditionalCapability(capabilityName, capabilityValue); + AppiumOptions.AddAdditionalAppiumOption(capabilityName, capabilityValue); } } -} \ No newline at end of file +} diff --git a/src/Legerity.Core/ByAll.cs b/src/Legerity.Core/ByAll.cs index 6dc54a09..5c403e23 100644 --- a/src/Legerity.Core/ByAll.cs +++ b/src/Legerity.Core/ByAll.cs @@ -3,7 +3,6 @@ namespace Legerity; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; -using OpenQA.Selenium; /// /// Defines a locator that can be used to find all elements that match all locators in sequence. @@ -19,7 +18,7 @@ namespace Legerity; /// public class ByAll : By { - private readonly By[] locators; + private readonly By[] _locators; /// /// Initializes a new instance of the class. @@ -27,7 +26,7 @@ public class ByAll : By /// The locators to find all references of. public ByAll(params By[] locators) { - this.locators = locators; + _locators = locators; } /// Finds the first element matching the criteria. @@ -36,7 +35,7 @@ public ByAll(params By[] locators) /// Thrown when no element matches the expected locator. public override IWebElement FindElement(ISearchContext context) { - ReadOnlyCollection elements = this.FindElements(context); + var elements = FindElements(context); if (elements.Count == 0) { throw new NoSuchElementException($"No element could be located using locator: {this}"); @@ -51,15 +50,15 @@ public override IWebElement FindElement(ISearchContext context) /// matching the current criteria, or an empty list if nothing matches. public override ReadOnlyCollection FindElements(ISearchContext context) { - if (this.locators.Length == 0) + if (_locators.Length == 0) { return new List().AsReadOnly(); } IEnumerable elements = null; - foreach (By locator in this.locators) + foreach (var locator in _locators) { - ReadOnlyCollection foundElements = locator.FindElements(context); + var foundElements = locator.FindElements(context); if (foundElements.Count == 0) { return new List().AsReadOnly(); @@ -70,4 +69,4 @@ public override ReadOnlyCollection FindElements(ISearchContext cont return (elements ?? new List()).ToList().AsReadOnly(); } -} \ No newline at end of file +} diff --git a/src/Legerity.Core/ByExtras.cs b/src/Legerity.Core/ByExtras.cs index 6c5dfd60..17e84b5b 100644 --- a/src/Legerity.Core/ByExtras.cs +++ b/src/Legerity.Core/ByExtras.cs @@ -1,7 +1,5 @@ namespace Legerity; -using OpenQA.Selenium; - /// /// Defines a collection of extra locator constraints for . /// @@ -26,4 +24,4 @@ public static By PartialText(string text) { return By.XPath($".//*[contains(text(),'{text}')]"); } -} \ No newline at end of file +} diff --git a/src/Legerity.Core/ByNested.cs b/src/Legerity.Core/ByNested.cs index dbe0ad4c..34eeb6f4 100644 --- a/src/Legerity.Core/ByNested.cs +++ b/src/Legerity.Core/ByNested.cs @@ -3,7 +3,6 @@ namespace Legerity; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; -using OpenQA.Selenium; /// /// Defines a locator that can be used to find elements using a sequence of locators that are continuously nested until the final locator is run. @@ -16,7 +15,7 @@ namespace Legerity; /// public class ByNested : By { - private readonly By[] locators; + private readonly By[] _locators; /// /// Initializes a new instance of the class. @@ -24,7 +23,7 @@ public class ByNested : By /// The locators in nesting sequence to find references of. public ByNested(params By[] locators) { - this.locators = locators; + _locators = locators; } /// Finds the first element matching the criteria. @@ -33,7 +32,7 @@ public ByNested(params By[] locators) /// Thrown when no element matches the expected locator. public override IWebElement FindElement(ISearchContext context) { - ReadOnlyCollection elements = this.FindElements(context); + var elements = FindElements(context); if (elements.Count == 0) { throw new NoSuchElementException($"No element could be located using locator: {this}"); @@ -48,13 +47,13 @@ public override IWebElement FindElement(ISearchContext context) /// matching the current criteria, or an empty list if nothing matches. public override ReadOnlyCollection FindElements(ISearchContext context) { - if (this.locators.Length == 0) + if (_locators.Length == 0) { return new List().AsReadOnly(); } IEnumerable elements = null; - foreach (By locator in this.locators) + foreach (var locator in _locators) { var nestedElements = new List(); @@ -64,7 +63,7 @@ public override ReadOnlyCollection FindElements(ISearchContext cont } else { - foreach (IWebElement element in elements) + foreach (var element in elements) { nestedElements.AddRange(element.FindElements(locator)); } @@ -75,4 +74,4 @@ public override ReadOnlyCollection FindElements(ISearchContext cont return (elements ?? new List()).ToList().AsReadOnly(); } -} \ No newline at end of file +} diff --git a/src/Legerity.Core/ElementWrapper`1.cs b/src/Legerity.Core/ElementWrapper{TElement}.cs similarity index 83% rename from src/Legerity.Core/ElementWrapper`1.cs rename to src/Legerity.Core/ElementWrapper{TElement}.cs index e86c5d1b..f65d3f80 100644 --- a/src/Legerity.Core/ElementWrapper`1.cs +++ b/src/Legerity.Core/ElementWrapper{TElement}.cs @@ -1,23 +1,18 @@ namespace Legerity; using System; - -using Legerity.Exceptions; - -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Support.UI; +using Exceptions; /// /// Defines a base wrapper for elements to expose platform element logic. /// /// -/// The type of . +/// The type of . /// public abstract class ElementWrapper : IElementWrapper - where TElement : AppiumWebElement + where TElement : WebElement { - private readonly WeakReference elementReference; + private readonly WeakReference _elementReference; /// /// Initializes a new instance of the class. @@ -27,31 +22,31 @@ public abstract class ElementWrapper : IElementWrapper /// protected ElementWrapper(TElement element) { - this.elementReference = new WeakReference(element); + _elementReference = new WeakReference(element); } /// Gets the original reference object. public TElement Element => - this.elementReference is { IsAlive: true } - ? this.elementReference.Target as TElement + _elementReference is { IsAlive: true } + ? _elementReference.Target as TElement : null; /// /// Gets the driver used to find this element. /// - public IWebDriver ElementDriver => this.Element.WrappedDriver; + public IWebDriver ElementDriver => Element.WrappedDriver; /// /// Gets a value indicating whether the element is visible. /// /// Thrown when an element is no longer valid in the document DOM. - public virtual bool IsVisible => this.Element.Displayed; + public virtual bool IsVisible => Element.Displayed; /// /// Gets a value indicating whether the element is enabled. /// /// Thrown when an element is no longer valid in the document DOM. - public virtual bool IsEnabled => this.Element.Enabled; + public virtual bool IsEnabled => Element.Enabled; /// /// Clicks the element. @@ -61,7 +56,7 @@ protected ElementWrapper(TElement element) /// Thrown when an element is no longer valid in the document DOM. public virtual void Click() { - this.Element.Click(); + Element.Click(); } /// @@ -72,7 +67,7 @@ public virtual void Click() /// Thrown when an element is no longer valid in the document DOM. public string GetAttribute(string attributeName) { - return this.Element.GetAttribute(attributeName); + return Element.GetAttribute(attributeName); } /// @@ -81,9 +76,9 @@ public string GetAttribute(string attributeName) /// The locator to find a child element by. /// The . /// Thrown when no element matches the expected locator. - public AppiumWebElement FindElement(By locator) + public WebElement FindElement(By locator) { - return this.Element.FindElement(locator); + return Element.FindElement(locator) as WebElement; } /// @@ -98,7 +93,7 @@ public void VerifyElementNotShown(By locator) { try { - this.VerifyElementShown(locator); + VerifyElementShown(locator); throw new ElementShownException(locator.ToString()); } catch (ElementNotShownException) @@ -116,7 +111,7 @@ public void VerifyElementNotShown(By locator) /// Thrown when no element matches the expected locator. public void VerifyElementShown(By locator) { - this.VerifyElementShown(locator, null); + VerifyElementShown(locator, null); } /// @@ -134,7 +129,7 @@ public void VerifyElementShown(By locator, TimeSpan? timeout) { try { - if (this.Element.FindElement(locator) == null) + if (Element.FindElement(locator) == null) { throw new ElementNotShownException(locator.ToString()); } @@ -146,7 +141,7 @@ public void VerifyElementShown(By locator, TimeSpan? timeout) } else { - var wait = new WebDriverWait(this.Element.WrappedDriver, timeout.Value); + var wait = new WebDriverWait(Element.WrappedDriver, timeout.Value); wait.Until(driver => driver.FindElement(locator) != null); } } @@ -160,7 +155,7 @@ public void VerifyElementShown(By locator, TimeSpan? timeout) /// Thrown when no elements are shown for the expected locator. public void VerifyElementsShown(By locator) { - this.VerifyElementsShown(locator, null); + VerifyElementsShown(locator, null); } /// @@ -177,15 +172,15 @@ public void VerifyElementsShown(By locator, TimeSpan? timeout) { if (timeout == null) { - if (this.Element.FindElements(locator).Count == 0) + if (Element.FindElements(locator).Count == 0) { throw new ElementsNotShownException(locator.ToString()); } } else { - var wait = new WebDriverWait(this.Element.WrappedDriver, timeout.Value); + var wait = new WebDriverWait(Element.WrappedDriver, timeout.Value); wait.Until(driver => driver.FindElements(locator).Count != 0); } } -} \ No newline at end of file +} diff --git a/src/Legerity.Core/Exceptions/AppiumServerLoadFailedException.cs b/src/Legerity.Core/Exceptions/AppiumServerLoadFailedException.cs index 2b561b1b..0f5a599d 100644 --- a/src/Legerity.Core/Exceptions/AppiumServerLoadFailedException.cs +++ b/src/Legerity.Core/Exceptions/AppiumServerLoadFailedException.cs @@ -15,4 +15,4 @@ internal AppiumServerLoadFailedException(Exception innerException) : base("The Appium server could not be loaded", innerException) { } -} \ No newline at end of file +} diff --git a/src/Legerity.Core/Exceptions/DriverLoadFailedException.cs b/src/Legerity.Core/Exceptions/DriverLoadFailedException.cs index 6da7f8ec..0bf03c8a 100644 --- a/src/Legerity.Core/Exceptions/DriverLoadFailedException.cs +++ b/src/Legerity.Core/Exceptions/DriverLoadFailedException.cs @@ -26,13 +26,14 @@ internal DriverLoadFailedException(AppManagerOptions opts) /// /// The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner exception is specified. internal DriverLoadFailedException(AppManagerOptions opts, Exception innerException) - : base($"The application driver could not be initialized with the specified app manager options: {opts}", innerException) + : base($"The application driver could not be initialized with the specified app manager options: {opts}", + innerException) { - this.AppManagerOptions = opts; + AppManagerOptions = opts; } /// /// Gets the app manager options used to initialize the driver. /// internal AppManagerOptions AppManagerOptions { get; } -} \ No newline at end of file +} diff --git a/src/Legerity.Core/Exceptions/DriverNotInitializedException.cs b/src/Legerity.Core/Exceptions/DriverNotInitializedException.cs index 338c8859..7da17d45 100644 --- a/src/Legerity.Core/Exceptions/DriverNotInitializedException.cs +++ b/src/Legerity.Core/Exceptions/DriverNotInitializedException.cs @@ -13,4 +13,4 @@ internal DriverNotInitializedException(string message) : base(message) { } -} \ No newline at end of file +} diff --git a/src/Legerity.Core/Exceptions/ElementNotShownException.cs b/src/Legerity.Core/Exceptions/ElementNotShownException.cs index f4552a01..923a5a5d 100644 --- a/src/Legerity.Core/Exceptions/ElementNotShownException.cs +++ b/src/Legerity.Core/Exceptions/ElementNotShownException.cs @@ -28,18 +28,11 @@ public ElementNotShownException(string locator) public ElementNotShownException(string locator, Exception innerException) : base($"No element could be located using locator: {locator}", innerException) { - this.ElementName = locator; - this.Locator = locator; + Locator = locator; } /// /// Gets the locator used to locate the element. /// public string Locator { get; } - - /// - /// Gets the name of the element that was not shown. - /// - [Obsolete("ElementName will be removed in a future major release. Please use the Locator instead.")] - public string ElementName { get; } -} \ No newline at end of file +} diff --git a/src/Legerity.Core/Exceptions/ElementShownException.cs b/src/Legerity.Core/Exceptions/ElementShownException.cs index bd1fcec3..f7cbaee2 100644 --- a/src/Legerity.Core/Exceptions/ElementShownException.cs +++ b/src/Legerity.Core/Exceptions/ElementShownException.cs @@ -28,18 +28,11 @@ public ElementShownException(string locator) public ElementShownException(string locator, Exception innerException) : base($"An element was located using locator: {locator}", innerException) { - this.ElementName = locator; - this.Locator = locator; + Locator = locator; } /// /// Gets the locator used to locate the element. /// public string Locator { get; } - - /// - /// Gets the name of the element that was shown. - /// - [Obsolete("ElementName will be removed in a future major release. Please use the Locator instead.")] - public string ElementName { get; } -} \ No newline at end of file +} diff --git a/src/Legerity.Core/Exceptions/ElementsNotShownException.cs b/src/Legerity.Core/Exceptions/ElementsNotShownException.cs index 705402ba..5f8057f7 100644 --- a/src/Legerity.Core/Exceptions/ElementsNotShownException.cs +++ b/src/Legerity.Core/Exceptions/ElementsNotShownException.cs @@ -28,11 +28,11 @@ public ElementsNotShownException(string locator) public ElementsNotShownException(string locator, Exception innerException) : base($"No elements could be located using locator: {locator}", innerException) { - this.Locator = locator; + Locator = locator; } /// /// Gets the locator used to locate the elements. /// public string Locator { get; } -} \ No newline at end of file +} diff --git a/src/Legerity.Core/Exceptions/LegerityException.cs b/src/Legerity.Core/Exceptions/LegerityException.cs index 34b4fa6a..1a924981 100644 --- a/src/Legerity.Core/Exceptions/LegerityException.cs +++ b/src/Legerity.Core/Exceptions/LegerityException.cs @@ -31,4 +31,4 @@ internal LegerityException(string message, Exception innerException) : base(message, innerException) { } -} \ No newline at end of file +} diff --git a/src/Legerity.Core/Exceptions/PageNotShownException.cs b/src/Legerity.Core/Exceptions/PageNotShownException.cs index 38f25a50..d9eda188 100644 --- a/src/Legerity.Core/Exceptions/PageNotShownException.cs +++ b/src/Legerity.Core/Exceptions/PageNotShownException.cs @@ -14,11 +14,11 @@ public class PageNotShownException : LegerityException internal PageNotShownException(string pageName) : base($"No page could be located for page: {pageName}") { - this.PageName = pageName; + PageName = pageName; } /// /// Gets the name of the page that was not shown. /// public string PageName { get; } -} \ No newline at end of file +} diff --git a/src/Legerity.Core/Extensions/AttributeExtensions.cs b/src/Legerity.Core/Extensions/AttributeExtensions.cs index bba328dd..b2f33de9 100644 --- a/src/Legerity.Core/Extensions/AttributeExtensions.cs +++ b/src/Legerity.Core/Extensions/AttributeExtensions.cs @@ -1,8 +1,5 @@ namespace Legerity.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Remote; - /// /// Defines a collection of extensions for retrieving element attributes. /// @@ -23,7 +20,7 @@ public static string GetName(this IWebElement element) /// Retrieves the Name attribute from the specified element. /// /// - /// The type of . + /// The type of . /// /// The to retrieve a Name from. /// The Name of the element. @@ -33,4 +30,4 @@ public static string GetName(this IElementWrapper element) { return GetName(element.Element); } -} \ No newline at end of file +} diff --git a/src/Legerity.Core/Extensions/DriverExtensions.cs b/src/Legerity.Core/Extensions/DriverExtensions.cs index 404d32a4..1eab2294 100644 --- a/src/Legerity.Core/Extensions/DriverExtensions.cs +++ b/src/Legerity.Core/Extensions/DriverExtensions.cs @@ -3,9 +3,6 @@ namespace Legerity.Extensions; using System; using System.Collections.ObjectModel; using System.Linq; -using OpenQA.Selenium; -using OpenQA.Selenium.Remote; -using OpenQA.Selenium.Support.UI; /// /// Defines a collection of extensions for a driver. @@ -17,11 +14,11 @@ public static class DriverExtensions /// /// The remote web driver. /// The locator to find the element. - /// A . + /// A . /// Thrown when no element matches the expected locator. - public static RemoteWebElement FindWebElement(this RemoteWebDriver driver, By locator) + public static WebElement FindWebElement(this WebDriver driver, By locator) { - return driver.FindElement(locator) as RemoteWebElement; + return driver.FindElement(locator) as WebElement; } /// @@ -29,10 +26,10 @@ public static RemoteWebElement FindWebElement(this RemoteWebDriver driver, By lo /// /// The remote web driver. /// The locator to find the elements. - /// A readonly collection of . - public static ReadOnlyCollection FindWebElements(this RemoteWebDriver driver, By locator) + /// A readonly collection of . + public static ReadOnlyCollection FindWebElements(this WebDriver driver, By locator) { - return driver.FindElements(locator).Cast().ToList().AsReadOnly(); + return driver.FindElements(locator).Cast().ToList().AsReadOnly(); } /// @@ -42,7 +39,7 @@ public static ReadOnlyCollection FindWebElements(this RemoteWe /// The text to find. /// A . /// Thrown when no element matches the expected locator. - public static IWebElement FindElementByText(this RemoteWebDriver driver, string text) + public static IWebElement FindElementByText(this WebDriver driver, string text) { return driver.FindElement(ByExtras.Text(text)); } @@ -53,7 +50,7 @@ public static IWebElement FindElementByText(this RemoteWebDriver driver, string /// The remote web driver. /// The text to find. /// A readonly collection of . - public static ReadOnlyCollection FindElementsByText(this RemoteWebDriver driver, string text) + public static ReadOnlyCollection FindElementsByText(this WebDriver driver, string text) { return driver.FindElements(ByExtras.Text(text)); } @@ -65,7 +62,7 @@ public static ReadOnlyCollection FindElementsByText(this RemoteWebD /// The partial text to find. /// A . /// Thrown when no element matches the expected locator. - public static IWebElement FindElementByPartialText(this RemoteWebDriver driver, string text) + public static IWebElement FindElementByPartialText(this WebDriver driver, string text) { return driver.FindElement(ByExtras.PartialText(text)); } @@ -77,7 +74,7 @@ public static IWebElement FindElementByPartialText(this RemoteWebDriver driver, /// The partial text to find. /// A readonly collection of . public static ReadOnlyCollection FindElementsByPartialText( - this RemoteWebDriver driver, + this WebDriver driver, string text) { return driver.FindElements(ByExtras.PartialText(text)); @@ -88,7 +85,7 @@ public static ReadOnlyCollection FindElementsByPartialText( /// /// The remote web driver. /// A readonly collection of . - public static ReadOnlyCollection GetAllElements(this RemoteWebDriver driver) + public static ReadOnlyCollection GetAllElements(this WebDriver driver) { return driver.FindElements(By.XPath("//*")); } @@ -98,7 +95,7 @@ public static ReadOnlyCollection GetAllElements(this RemoteWebDrive /// /// The remote web driver. /// A readonly collection of . - public static ReadOnlyCollection GetAllChildElements(this RemoteWebDriver driver) + public static ReadOnlyCollection GetAllChildElements(this WebDriver driver) { return driver.FindElements(By.XPath(".//*")); } @@ -163,4 +160,24 @@ public static TResult WaitUntil( return WaitUntil(appDriver, condition, timeout, retries - 1); } } -} \ No newline at end of file + + public static WebElement FindElementByXPath(this WebDriver driver, string xpath) + { + return driver.FindElement(By.XPath(xpath)) as WebElement; + } + + public static ReadOnlyCollection FindElementsByXPath(this WebDriver driver, string xpath) + { + return driver.FindElements(By.XPath(xpath)).Cast().ToList().AsReadOnly(); + } + + public static WebElement FindElementById(this WebDriver driver, string id) + { + return driver.FindElement(By.Id(id)) as WebElement; + } + + public static WebElement FindElementByName(this WebDriver driver, string name) + { + return driver.FindElement(By.Name(name)) as WebElement; + } +} diff --git a/src/Legerity.Core/Extensions/ElementExtensions.cs b/src/Legerity.Core/Extensions/ElementExtensions.cs index a547237b..663e4e1c 100644 --- a/src/Legerity.Core/Extensions/ElementExtensions.cs +++ b/src/Legerity.Core/Extensions/ElementExtensions.cs @@ -4,9 +4,6 @@ namespace Legerity.Extensions; using System.Collections.ObjectModel; using System.Drawing; using System.Linq; -using OpenQA.Selenium; -using OpenQA.Selenium.Remote; -using OpenQA.Selenium.Support.UI; /// /// Defines a collection of extensions for elements. @@ -21,8 +18,8 @@ public static class ElementExtensions /// Thrown when an element is no longer valid in the document DOM. public static Rectangle GetBoundingRect(this IWebElement element) { - Point location = element.Location; - Size size = element.Size; + var location = element.Location; + var size = element.Size; return new Rectangle(location.X, location.Y, size.Width, size.Height); } @@ -31,11 +28,11 @@ public static Rectangle GetBoundingRect(this IWebElement element) /// /// The remote web element. /// The locator to find the element. - /// A . + /// A . /// Thrown when no element matches the expected locator. - public static RemoteWebElement FindWebElement(this IWebElement element, By locator) + public static WebElement FindWebElement(this IWebElement element, By locator) { - return element.FindElement(locator) as RemoteWebElement; + return element.FindElement(locator) as WebElement; } /// @@ -43,10 +40,10 @@ public static RemoteWebElement FindWebElement(this IWebElement element, By locat /// /// The remote web element. /// The locator to find the elements. - /// A readonly collection of . - public static ReadOnlyCollection FindWebElements(this IWebElement element, By locator) + /// A readonly collection of . + public static ReadOnlyCollection FindWebElements(this IWebElement element, By locator) { - return element.FindElements(locator).Cast().ToList().AsReadOnly(); + return element.FindElements(locator).Cast().ToList().AsReadOnly(); } /// @@ -116,8 +113,8 @@ public static ReadOnlyCollection GetAllChildElements(this IWebEleme /// Whether the wait was a success. /// Thrown when the callback throws an exception. public static bool TryWaitUntil( - this RemoteWebElement element, - Func condition, + this WebElement element, + Func condition, TimeSpan? timeout = default, int retries = 0, Action exceptionHandler = null) @@ -147,8 +144,8 @@ public static bool TryWaitUntil( /// Thrown when the condition is not met in the allocated timeout period. /// Thrown when the callback throws an exception. public static TResult WaitUntil( - this RemoteWebElement element, - Func condition, + this WebElement element, + Func condition, TimeSpan? timeout = default, int retries = 0) { @@ -176,4 +173,4 @@ public static TResult WaitUntil( return WaitUntil(element, condition, timeout, retries - 1); } } -} \ No newline at end of file +} diff --git a/src/Legerity.Core/Extensions/ElementWrapperExtensions.cs b/src/Legerity.Core/Extensions/ElementWrapperExtensions.cs index 8c9b68dd..5ad9cb94 100644 --- a/src/Legerity.Core/Extensions/ElementWrapperExtensions.cs +++ b/src/Legerity.Core/Extensions/ElementWrapperExtensions.cs @@ -3,9 +3,6 @@ namespace Legerity.Extensions; using System; using System.Collections.ObjectModel; using System.Drawing; -using OpenQA.Selenium; -using OpenQA.Selenium.Remote; -using OpenQA.Selenium.Support.UI; /// /// Defines a collection of extensions for objects. @@ -35,9 +32,9 @@ public static Rectangle GetBoundingRect(this IElementWrapper /// /// The remote web element. /// The locator to find the element. - /// A . + /// A . /// Thrown when no element matches the expected locator. - public static RemoteWebElement FindWebElement(this IElementWrapper element, By locator) + public static WebElement FindWebElement(this IElementWrapper element, By locator) where TElement : IWebElement { return element.Element.FindWebElement(locator); @@ -51,8 +48,8 @@ public static RemoteWebElement FindWebElement(this IElementWrapper /// The remote web element. /// The locator to find the elements. - /// A readonly collection of . - public static ReadOnlyCollection FindWebElements( + /// A readonly collection of . + public static ReadOnlyCollection FindWebElements( this IElementWrapper element, By locator) where TElement : IWebElement { @@ -216,4 +213,4 @@ public static TResult WaitUntil( return WaitUntil(element, condition, timeout, retries - 1); } } -} \ No newline at end of file +} diff --git a/src/Legerity.Core/Extensions/InteractionExtensions.cs b/src/Legerity.Core/Extensions/InteractionExtensions.cs index fa8a3d14..0dbb0c3e 100644 --- a/src/Legerity.Core/Extensions/InteractionExtensions.cs +++ b/src/Legerity.Core/Extensions/InteractionExtensions.cs @@ -1,9 +1,5 @@ namespace Legerity.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Interactions; -using OpenQA.Selenium.Remote; - /// /// Defines a collection of extensions for performing interactions with elements. /// @@ -16,7 +12,7 @@ public static class InteractionExtensions /// The element hold can be released by calling . /// /// The element to click and hold. - public static void ClickAndHold(this RemoteWebElement element) + public static void ClickAndHold(this WebElement element) { var action = new Actions(element.WrappedDriver); action.ClickAndHold(element).Perform(); @@ -35,14 +31,14 @@ public static void ClickAndHold(this RemoteWebElement element) public static void ClickAndHold(this IElementWrapper element) where TElement : IWebElement { - ClickAndHold(element.Element as RemoteWebElement); + ClickAndHold(element.Element as WebElement); } /// /// Releases the hold click from the element. /// /// The element to release the hold from. - public static void ReleaseHold(this RemoteWebElement element) + public static void ReleaseHold(this WebElement element) { var action = new Actions(element.WrappedDriver); action.Release(element).Perform(); @@ -58,14 +54,14 @@ public static void ReleaseHold(this RemoteWebElement element) public static void ReleaseHold(this IElementWrapper element) where TElement : IWebElement { - ReleaseHold(element.Element as RemoteWebElement); + ReleaseHold(element.Element as WebElement); } /// /// Scrolls to the element. /// /// The element to scroll to. - public static void ScrollTo(this RemoteWebElement element) + public static void ScrollTo(this WebElement element) { var action = new Actions(element.WrappedDriver); action.MoveToElement(element).Perform(); @@ -81,6 +77,6 @@ public static void ScrollTo(this RemoteWebElement element) public static void ScrollTo(this IElementWrapper element) where TElement : IWebElement { - ScrollTo(element.Element as RemoteWebElement); + ScrollTo(element.Element as WebElement); } -} \ No newline at end of file +} diff --git a/src/Legerity.Core/Extensions/PageExtensions.cs b/src/Legerity.Core/Extensions/PageExtensions.cs index 306c0994..6c764996 100644 --- a/src/Legerity.Core/Extensions/PageExtensions.cs +++ b/src/Legerity.Core/Extensions/PageExtensions.cs @@ -1,8 +1,7 @@ namespace Legerity.Extensions; using System; -using Legerity.Pages; -using OpenQA.Selenium; +using Pages; using OpenQA.Selenium.Support.UI; /// @@ -87,4 +86,4 @@ public static TPage WaitUntil( return page; } -} \ No newline at end of file +} diff --git a/src/Legerity.Core/Extensions/StringExtensions.cs b/src/Legerity.Core/Extensions/StringExtensions.cs index 3f969f86..3d9f3db1 100644 --- a/src/Legerity.Core/Extensions/StringExtensions.cs +++ b/src/Legerity.Core/Extensions/StringExtensions.cs @@ -49,4 +49,4 @@ public static string RemoveUnicodeCharacters(this string value) { return value == null ? null : new string(value.Where(c => c < 128).ToArray()); } -} \ No newline at end of file +} diff --git a/src/Legerity.Core/GlobalUsings.cs b/src/Legerity.Core/GlobalUsings.cs new file mode 100644 index 00000000..68467a92 --- /dev/null +++ b/src/Legerity.Core/GlobalUsings.cs @@ -0,0 +1,16 @@ +// Global using directives + +global using OpenQA.Selenium; +global using OpenQA.Selenium.Appium; +global using OpenQA.Selenium.Appium.Android; +global using OpenQA.Selenium.Appium.Enums; +global using OpenQA.Selenium.Appium.iOS; +global using OpenQA.Selenium.Appium.Service; +global using OpenQA.Selenium.Appium.Windows; +global using OpenQA.Selenium.Chrome; +global using OpenQA.Selenium.Edge; +global using OpenQA.Selenium.Firefox; +global using OpenQA.Selenium.IE; +global using OpenQA.Selenium.Interactions; +global using OpenQA.Selenium.Safari; +global using OpenQA.Selenium.Support.UI; diff --git a/src/Legerity.Core/Helpers/AppiumServerHelper.cs b/src/Legerity.Core/Helpers/AppiumServerHelper.cs index 1ceb3bd9..3dc52a10 100644 --- a/src/Legerity.Core/Helpers/AppiumServerHelper.cs +++ b/src/Legerity.Core/Helpers/AppiumServerHelper.cs @@ -1,8 +1,7 @@ namespace Legerity.Helpers; using System; -using Legerity.Exceptions; -using OpenQA.Selenium.Appium.Service; +using Exceptions; /// /// Defines a helper class for launching a local Appium server. @@ -49,4 +48,4 @@ public static void Stop() { } } -} \ No newline at end of file +} diff --git a/src/Legerity.Core/Helpers/WaitUntilConditions.cs b/src/Legerity.Core/Helpers/WaitUntilConditions.cs index f6719c49..0bb12ef0 100644 --- a/src/Legerity.Core/Helpers/WaitUntilConditions.cs +++ b/src/Legerity.Core/Helpers/WaitUntilConditions.cs @@ -1,8 +1,7 @@ namespace Legerity.Helpers; using System; -using Legerity.Pages; -using OpenQA.Selenium; +using Pages; /// /// Defines a set of conditions that can be used with the WaitUntil methods of elements and pages. @@ -350,7 +349,7 @@ public static Func FrameAvailableToSwitchTo(By frameLoca { try { - IWebElement frameElement = driver.FindElement(frameLocator); + var frameElement = driver.FindElement(frameLocator); return driver.SwitchTo().Frame(frameElement); } catch (NoSuchFrameException) @@ -359,4 +358,4 @@ public static Func FrameAvailableToSwitchTo(By frameLoca } }; } -} \ No newline at end of file +} diff --git a/src/Legerity.Core/IElementWrapper.cs b/src/Legerity.Core/IElementWrapper{TElement}.cs similarity index 97% rename from src/Legerity.Core/IElementWrapper.cs rename to src/Legerity.Core/IElementWrapper{TElement}.cs index 0d0a03ef..72415a17 100644 --- a/src/Legerity.Core/IElementWrapper.cs +++ b/src/Legerity.Core/IElementWrapper{TElement}.cs @@ -1,7 +1,6 @@ namespace Legerity; using System; -using OpenQA.Selenium; /// /// Defines an interface for a Selenium/Appium element wrapper. @@ -9,7 +8,7 @@ namespace Legerity; /// /// The type of . /// -public interface IElementWrapper +public interface IElementWrapper where TElement : IWebElement { /// Gets the original reference object. @@ -85,4 +84,4 @@ public interface IElementWrapper /// The amount of time the driver should wait when searching for the if it is not immediately present. /// void VerifyElementsShown(By locator, TimeSpan? timeout); -} \ No newline at end of file +} diff --git a/src/Legerity.Core/IOS/IOSAppManagerOptions.cs b/src/Legerity.Core/IOS/IOSAppManagerOptions.cs index d002e4e3..6371e8b5 100644 --- a/src/Legerity.Core/IOS/IOSAppManagerOptions.cs +++ b/src/Legerity.Core/IOS/IOSAppManagerOptions.cs @@ -1,8 +1,6 @@ namespace Legerity.IOS; using System.Collections.Generic; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Enums; /// /// Defines a specific for an iOS application. @@ -61,11 +59,11 @@ public IOSAppManagerOptions( string deviceId, params (string, object)[] additionalOptions) { - this.AppId = appId; - this.OSVersion = osVersion; - this.DeviceName = deviceName; - this.DeviceId = deviceId; - this.AdditionalOptions = additionalOptions; + AppId = appId; + OSVersion = osVersion; + DeviceName = deviceName; + DeviceId = deviceId; + AdditionalOptions = additionalOptions; } /// @@ -96,11 +94,6 @@ public IOSAppManagerOptions( /// public string AutomationName { get; set; } = "XCUITest"; - /// - /// Gets or sets a value indicating whether to launch the Appium server instance. - /// - public bool LaunchAppiumServer { get; set; } - /// /// Configures the with the specified additional options. /// @@ -108,12 +101,12 @@ public override void Configure() { base.Configure(); - this.AppiumOptions.AddAdditionalCapability(MobileCapabilityType.PlatformName, "iOS"); - this.AppiumOptions.AddAdditionalCapability(MobileCapabilityType.PlatformVersion, this.OSVersion); - this.AppiumOptions.AddAdditionalCapability(MobileCapabilityType.DeviceName, this.DeviceName); - this.AppiumOptions.AddAdditionalCapability(MobileCapabilityType.Udid, this.DeviceId); - this.AppiumOptions.AddAdditionalCapability(MobileCapabilityType.App, this.AppId); - this.AppiumOptions.AddAdditionalCapability(MobileCapabilityType.AutomationName, this.AutomationName); + AppiumOptions.AddAdditionalAppiumOption(MobileCapabilityType.PlatformName, "iOS"); + AppiumOptions.AddAdditionalAppiumOption(MobileCapabilityType.PlatformVersion, OSVersion); + AppiumOptions.AddAdditionalAppiumOption(MobileCapabilityType.DeviceName, DeviceName); + AppiumOptions.AddAdditionalAppiumOption(MobileCapabilityType.Udid, DeviceId); + AppiumOptions.AddAdditionalAppiumOption(MobileCapabilityType.App, AppId); + AppiumOptions.AddAdditionalAppiumOption(MobileCapabilityType.AutomationName, AutomationName); } /// @@ -124,39 +117,39 @@ public override void Configure() /// public void Configure((string, object)[] additionalOptions) { - this.AdditionalOptions = additionalOptions; - this.Configure(); + AdditionalOptions = additionalOptions; + Configure(); } /// Returns a string that represents the current object. /// A string that represents the current object. public override string ToString() { - return $"Platform [IOS], {base.ToString()}, {this.GetOptionDetails()}"; + return $"Platform [IOS], {base.ToString()}, {GetOptionDetails()}"; } private string GetOptionDetails() { var options = new List(); - if (!string.IsNullOrWhiteSpace(this.AppId)) + if (!string.IsNullOrWhiteSpace(AppId)) { - options.Add($"App ID [{this.AppId}]"); + options.Add($"App ID [{AppId}]"); } - if (!string.IsNullOrWhiteSpace(this.DeviceId)) + if (!string.IsNullOrWhiteSpace(DeviceId)) { - options.Add($"Device ID [{this.DeviceId}]"); + options.Add($"Device ID [{DeviceId}]"); } - if (!string.IsNullOrWhiteSpace(this.DeviceName)) + if (!string.IsNullOrWhiteSpace(DeviceName)) { - options.Add($"Device Name [{this.DeviceName}]"); + options.Add($"Device Name [{DeviceName}]"); } - if (this.AdditionalOptions != null) + if (AdditionalOptions != null) { - foreach ((string name, object value) in this.AdditionalOptions) + foreach (var (name, value) in AdditionalOptions) { options.Add($"{name} [{value}]"); } @@ -164,4 +157,4 @@ private string GetOptionDetails() return string.Join(", ", options); } -} \ No newline at end of file +} diff --git a/src/Legerity.Core/Legerity.Core.csproj b/src/Legerity.Core/Legerity.Core.csproj index 58c7bc83..ede6f67e 100644 --- a/src/Legerity.Core/Legerity.Core.csproj +++ b/src/Legerity.Core/Legerity.Core.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + net6.0;net7.0;net8.0 true Legerity Core - Framework for UI testing with Selenium/Appium @@ -16,8 +16,8 @@ - - + + diff --git a/src/Legerity.Core/LegerityTestClass.cs b/src/Legerity.Core/LegerityTestClass.cs index d5425379..22636205 100644 --- a/src/Legerity.Core/LegerityTestClass.cs +++ b/src/Legerity.Core/LegerityTestClass.cs @@ -5,11 +5,6 @@ namespace Legerity; using Android; using Exceptions; using IOS; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium.Android; -using OpenQA.Selenium.Appium.iOS; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; using Windows; /// @@ -17,7 +12,7 @@ namespace Legerity; /// public abstract class LegerityTestClass { - private readonly List apps = new(); + private readonly List _apps = new(); /// /// Initializes a new instance of the class. @@ -35,19 +30,19 @@ protected LegerityTestClass() /// The application launch options. protected LegerityTestClass(AppManagerOptions options) { - this.Options = options; + Options = options; } /// /// Gets the instance of the started application. /// - /// This could be a , , , or web driver. + /// This could be a , , , or web driver. /// /// /// /// This instance should not be used in parallelized test runs. Instead, use the instance returned by the or method. /// - protected RemoteWebDriver App { get; private set; } + protected WebDriver App { get; private set; } /// /// Gets or sets the instances of started applications. @@ -55,7 +50,7 @@ protected LegerityTestClass(AppManagerOptions options) /// /// This is useful for accessing drivers in parallelized tests. /// - protected IReadOnlyCollection Apps => this.apps; + protected IReadOnlyCollection Apps => _apps; /// /// Gets or sets the model that represents the configuration options for the . @@ -82,12 +77,12 @@ protected LegerityTestClass(AppManagerOptions options) /// - The WinAppDriver could not be found when running with true. /// - The WinAppDriver failed to load when running with true. /// - public virtual RemoteWebDriver StartApp( + public virtual WebDriver StartApp( Func waitUntil = default, TimeSpan? waitUntilTimeout = default, int waitUntilRetries = 0) { - return this.StartApp(this.Options, waitUntil, waitUntilTimeout, waitUntilRetries); + return StartApp(Options, waitUntil, waitUntilTimeout, waitUntilRetries); } /// @@ -116,20 +111,20 @@ public virtual RemoteWebDriver StartApp( /// - The WinAppDriver failed to load when running with true. /// /// Thrown when the wait until condition is not met in the allocated timeout period if provided. - public virtual RemoteWebDriver StartApp( + public virtual WebDriver StartApp( AppManagerOptions options, Func waitUntil = default, TimeSpan? waitUntilTimeout = default, int waitUntilRetries = 0) { - if (options != default && this.Options != options) + if (options != default && Options != options) { - this.Options = options; + Options = options; } - RemoteWebDriver app = AppManager.StartApp(this.Options, waitUntil, waitUntilTimeout, waitUntilRetries); - this.App = app; - this.apps.Add(app); + var app = AppManager.StartApp(Options, waitUntil, waitUntilTimeout, waitUntilRetries); + App = app; + _apps.Add(app); return app; } @@ -138,7 +133,7 @@ public virtual RemoteWebDriver StartApp( /// public virtual void StopApp() { - this.StopApp(true); + StopApp(true); } /// @@ -149,7 +144,7 @@ public virtual void StopApp() /// public virtual void StopApp(bool stopServer) { - this.StopApp(this.App, stopServer); + StopApp(App, stopServer); } /// @@ -161,9 +156,9 @@ public virtual void StopApp(bool stopServer) /// /// An optional value indicating whether to stop the running Appium or WinAppDriver server. Default, false. /// - public virtual void StopApp(RemoteWebDriver app, bool stopServer = false) + public virtual void StopApp(WebDriver app, bool stopServer = false) { - this.StopAppManagerApp(app, stopServer, true); + StopAppManagerApp(app, stopServer, true); } /// @@ -174,17 +169,17 @@ public virtual void StopApp(RemoteWebDriver app, bool stopServer = false) /// public virtual void StopApps(bool stopServer = true) { - this.apps.ForEach(app => this.StopAppManagerApp(app, stopServer, false)); - this.apps.Clear(); + _apps.ForEach(app => StopAppManagerApp(app, stopServer, false)); + _apps.Clear(); } - private void StopAppManagerApp(RemoteWebDriver app, bool stopServer, bool removeApp) + private void StopAppManagerApp(WebDriver app, bool stopServer, bool removeApp) { if (removeApp) { - this.apps.Remove(app); + _apps.Remove(app); } AppManager.StopApp(app, stopServer); } -} \ No newline at end of file +} diff --git a/src/Legerity.Core/Pages/BasePage.cs b/src/Legerity.Core/Pages/BasePage.cs index 296f18df..fbb683f5 100644 --- a/src/Legerity.Core/Pages/BasePage.cs +++ b/src/Legerity.Core/Pages/BasePage.cs @@ -2,15 +2,8 @@ namespace Legerity.Pages; using System; using System.Collections.ObjectModel; -using System.Linq; -using Legerity.Exceptions; -using Legerity.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium.Android; -using OpenQA.Selenium.Appium.iOS; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; -using OpenQA.Selenium.Support.UI; +using Exceptions; +using Extensions; /// /// Defines a base page for creating tests following the page object pattern. @@ -29,7 +22,7 @@ protected BasePage() } /// - /// Initializes a new instance of the class using a instance that verifies the page has loaded within 2 seconds. + /// Initializes a new instance of the class using a instance that verifies the page has loaded within 2 seconds. /// /// /// The instance of the started application driver that will be used to drive the page interaction. @@ -37,7 +30,7 @@ protected BasePage() /// Thrown when AppManager.StartApp() has not been called. /// Thrown when the page is not shown in 2 seconds. /// Thrown when no element matches the expected locator. - protected BasePage(RemoteWebDriver app) + protected BasePage(WebDriver app) : this(app, TimeSpan.FromSeconds(2)) { } @@ -57,7 +50,7 @@ protected BasePage(TimeSpan? traitTimeout) } /// - /// Initializes a new instance of the class using a instance that verifies the page has loaded within the given timeout. + /// Initializes a new instance of the class using a instance that verifies the page has loaded within the given timeout. /// /// /// The instance of the started application driver that will be used to drive the page interaction. @@ -68,11 +61,11 @@ protected BasePage(TimeSpan? traitTimeout) /// Thrown when AppManager.StartApp() has not been called. /// Thrown when the page is not shown in the given timeout. /// Thrown when no element matches the expected locator. - protected BasePage(RemoteWebDriver app, TimeSpan? traitTimeout) + protected BasePage(WebDriver app, TimeSpan? traitTimeout) { - this.App = app; - this.WaitTimeout = traitTimeout ?? TimeSpan.FromSeconds(2); - this.VerifyPageShown(this.WaitTimeout); + App = app; + WaitTimeout = traitTimeout ?? TimeSpan.FromSeconds(2); + VerifyPageShown(WaitTimeout); } /// @@ -81,10 +74,10 @@ protected BasePage(RemoteWebDriver app, TimeSpan? traitTimeout) /// The instance serves as base for the drivers and can be referenced for basic Selenium functions. /// /// - /// This could be a , , , or web driver. + /// This could be a , , , or web driver. /// /// - public RemoteWebDriver App { get; } + public WebDriver App { get; } /// /// Gets or sets the amount of time the driver should wait when searching for elements if they are not immediately present. @@ -94,22 +87,22 @@ protected BasePage(RemoteWebDriver app, TimeSpan? traitTimeout) /// /// Gets the instance of the started Windows application. /// - protected WindowsDriver WindowsApp => this.App as WindowsDriver; + protected WindowsDriver WindowsApp => App as WindowsDriver; /// /// Gets the instance of the started Android application. /// - protected AndroidDriver AndroidApp => this.App as AndroidDriver; + protected AndroidDriver AndroidApp => App as AndroidDriver; /// /// Gets the instance of the started iOS application. /// - protected IOSDriver IOSApp => this.App as IOSDriver; + protected IOSDriver IOSApp => App as IOSDriver; /// /// Gets the instance of the started web application. /// - protected RemoteWebDriver WebApp => this.App; + protected WebDriver WebApp => App; /// /// Gets a given trait of the page to verify that the page is in view. @@ -120,64 +113,64 @@ protected BasePage(RemoteWebDriver app, TimeSpan? traitTimeout) /// Finds the first element in the page that matches the locator. /// /// The locator to find the element. - /// A . + /// A . /// Thrown when no element matches the expected locator. - public RemoteWebElement FindElement(By locator) + public WebElement FindElement(By locator) { - return this.App.FindWebElement(locator); + return App.FindWebElement(locator); } /// /// Finds all the elements in the page that matches the locator. /// /// The locator to find the elements. - /// A readonly collection of . - public ReadOnlyCollection FindElements(By locator) + /// A readonly collection of . + public ReadOnlyCollection FindElements(By locator) { - return this.App.FindWebElements(locator); + return App.FindWebElements(locator); } /// /// Finds the first element in the page that matches the specified XPath. /// /// The XPath to find the element. - /// A . + /// A . /// Thrown when no element matches the expected locator. - public RemoteWebElement FindElementByXPath(string xpath) + public WebElement FindElementByXPath(string xpath) { - return this.App.FindElementByXPath(xpath) as RemoteWebElement; + return App.FindElementByXPath(xpath); } /// /// Finds all the elements in the page that matches the specified XPath. /// /// The XPath to find the elements. - /// A readonly collection of . - public ReadOnlyCollection FindElementsByXPath(string xpath) + /// A readonly collection of . + public ReadOnlyCollection FindElementsByXPath(string xpath) { - return this.App.FindElementsByXPath(xpath).Cast().ToList().AsReadOnly(); + return App.FindElementsByXPath(xpath); } /// /// Finds the first element in the page that matches the specified ID. /// /// The ID of the element. - /// A . + /// A . /// Thrown when no element matches the expected locator. - public RemoteWebElement FindElementById(string id) + public WebElement FindElementById(string id) { - return this.App.FindElementById(id) as RemoteWebElement; + return App.FindElementById(id); } /// /// Finds the first of element in the page that matches the specified name. /// /// The name of the element. - /// A . + /// A . /// Thrown when no element matches the expected locator. - public RemoteWebElement FindElementByName(string name) + public WebElement FindElementByName(string name) { - return this.App.FindElementByName(name) as RemoteWebElement; + return App.FindElementByName(name); } /// @@ -188,7 +181,7 @@ public RemoteWebElement FindElementByName(string name) /// Thrown when no element matches the expected locator. public void VerifyPageShown() { - this.VerifyPageShown(null); + VerifyPageShown(null); } /// @@ -202,7 +195,7 @@ public void VerifyPageShown() /// Thrown when no element matches the expected locator. public void VerifyPageShown(TimeSpan? timeout) { - if (this.App == null) + if (App == null) { throw new DriverNotInitializedException( $"An app driver has not been initialized. Call 'AppManager.StartApp()' with an instance of an {nameof(AppManagerOptions)} to setup for testing."); @@ -210,16 +203,16 @@ public void VerifyPageShown(TimeSpan? timeout) if (timeout == null) { - if (this.App != null && this.App.FindElement(this.Trait) == null) + if (App != null && App.FindElement(Trait) == null) { - throw new PageNotShownException(this.GetType().Name); + throw new PageNotShownException(GetType().Name); } } else { - if (this.App != null) + if (App != null) { - AttemptWaitForDriverElement(this.Trait, timeout.Value, this.App); + AttemptWaitForDriverElement(Trait, timeout.Value, App); } } } @@ -235,7 +228,7 @@ public void VerifyPageShown(TimeSpan? timeout) /// Thrown when no element matches the expected locator. public void VerifyElementShown(By locator) { - this.VerifyElementShown(locator, null); + VerifyElementShown(locator, null); } /// @@ -252,7 +245,7 @@ public void VerifyElementShown(By locator) /// Thrown when no element matches the expected locator. public void VerifyElementShown(By locator, TimeSpan? timeout) { - if (this.App == null) + if (App == null) { throw new DriverNotInitializedException( $"An app driver has not been initialized. Call 'AppManager.StartApp()' with an instance of an {nameof(AppManagerOptions)} to setup for testing."); @@ -260,16 +253,16 @@ public void VerifyElementShown(By locator, TimeSpan? timeout) if (timeout == null) { - if (this.App != null && this.App.FindElement(locator) == null) + if (App != null && App.FindElement(locator) == null) { throw new ElementNotShownException(locator.ToString()); } } else { - if (this.App != null) + if (App != null) { - AttemptWaitForDriverElement(locator, timeout.Value, this.App); + AttemptWaitForDriverElement(locator, timeout.Value, App); } } } @@ -283,7 +276,7 @@ public void VerifyElementShown(By locator, TimeSpan? timeout) /// Thrown when AppManager.StartApp() has not been called. public void VerifyElementNotShown(By locator) { - if (this.App == null) + if (App == null) { throw new DriverNotInitializedException( $"An app driver has not been initialized. Call 'AppManager.StartApp()' with an instance of an {nameof(AppManagerOptions)} to setup for testing."); @@ -291,7 +284,7 @@ public void VerifyElementNotShown(By locator) try { - this.VerifyElementShown(locator); + VerifyElementShown(locator); } catch (ElementNotShownException) { @@ -307,4 +300,4 @@ private static void AttemptWaitForDriverElement(By locator, TimeSpan timeout, IW var wait = new WebDriverWait(appDriver, timeout); wait.Until(driver => driver.FindElement(locator) != null); } -} \ No newline at end of file +} diff --git a/src/Legerity.Core/Web/OperaChromiumOptions.cs b/src/Legerity.Core/Web/OperaChromiumOptions.cs new file mode 100644 index 00000000..0bdcb13f --- /dev/null +++ b/src/Legerity.Core/Web/OperaChromiumOptions.cs @@ -0,0 +1,48 @@ +using System; +using System.Runtime.InteropServices; + +namespace Legerity.Web; + +public class OperaChromiumOptions : ChromeOptions +{ + public OperaChromiumOptions(string binaryLocation = default) + { + BinaryLocation = DetermineBinaryLocation(binaryLocation); + } + + /// + public sealed override string BinaryLocation + { + get => base.BinaryLocation; + set => base.BinaryLocation = value; + } + + private string DetermineBinaryLocation(string binaryLocation) + { + if (!string.IsNullOrWhiteSpace(binaryLocation)) + { + return binaryLocation; + } + + var isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); + if (isWindows) + { + var userPath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); + return $@"{userPath}\AppData\Local\Programs\Opera\opera.exe"; + } + + var isLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux); + if (isLinux) + { + return "/usr/bin/opera"; + } + + var isMac = RuntimeInformation.IsOSPlatform(OSPlatform.OSX); + if (isMac) + { + return "/Applications/Opera.app/Contents/MacOS/Opera"; + } + + throw new PlatformNotSupportedException("The current operating system is not supported."); + } +} diff --git a/src/Legerity.Core/Web/WebAppDriverType.cs b/src/Legerity.Core/Web/WebAppDriverType.cs index 3a118e7f..8ac448ca 100644 --- a/src/Legerity.Core/Web/WebAppDriverType.cs +++ b/src/Legerity.Core/Web/WebAppDriverType.cs @@ -1,5 +1,7 @@ namespace Legerity.Web; +using System; + /// /// Defines the values associated with the web app driver type. /// @@ -43,5 +45,6 @@ public enum WebAppDriverType /// /// Edge Chromium. Setting this will cause the application driver to launch for Microsoft's Chromium Edge. /// + [Obsolete("Use Edge instead. This will be removed in a future release.")] EdgeChromium, -} \ No newline at end of file +} diff --git a/src/Legerity.Core/Web/WebAppManagerOptions.cs b/src/Legerity.Core/Web/WebAppManagerOptions.cs index aac6faac..f46e8899 100644 --- a/src/Legerity.Core/Web/WebAppManagerOptions.cs +++ b/src/Legerity.Core/Web/WebAppManagerOptions.cs @@ -22,8 +22,8 @@ public WebAppManagerOptions() /// The path to the web application driver directory. public WebAppManagerOptions(WebAppDriverType driverType, string driverDirectoryPath) { - this.DriverType = driverType; - this.DriverUri = driverDirectoryPath; + DriverType = driverType; + DriverUri = driverDirectoryPath; } /// @@ -56,18 +56,18 @@ public WebAppManagerOptions(WebAppDriverType driverType, string driverDirectoryP /// A string that represents the current object. public override string ToString() { - return $"Platform [{this.DriverType}], {base.ToString()}, {this.GetOptionDetails()}"; + return $"Platform [{DriverType}], {base.ToString()}, {GetOptionDetails()}"; } private string GetOptionDetails() { var options = new List(); - if (!string.IsNullOrWhiteSpace(this.Url)) + if (!string.IsNullOrWhiteSpace(Url)) { - options.Add($"URL [{this.Url}]"); + options.Add($"URL [{Url}]"); } return string.Join(", ", options); } -} \ No newline at end of file +} diff --git a/src/Legerity.Core/Windows/Exceptions/WinAppDriverLoadFailedException.cs b/src/Legerity.Core/Windows/Exceptions/WinAppDriverLoadFailedException.cs index 0f4a5760..c300b98b 100644 --- a/src/Legerity.Core/Windows/Exceptions/WinAppDriverLoadFailedException.cs +++ b/src/Legerity.Core/Windows/Exceptions/WinAppDriverLoadFailedException.cs @@ -15,11 +15,11 @@ public class WinAppDriverLoadFailedException : LegerityException internal WinAppDriverLoadFailedException(string path, Exception exception) : base($"The WinAppDriver could not be loaded at {path}.", exception) { - this.Path = path; + Path = path; } /// /// Gets or sets the path where the WinAppDriver should have loaded from. /// public string Path { get; set; } -} \ No newline at end of file +} diff --git a/src/Legerity.Core/Windows/Exceptions/WinAppDriverNotFoundException.cs b/src/Legerity.Core/Windows/Exceptions/WinAppDriverNotFoundException.cs index 0aaa4c79..b3e35e32 100644 --- a/src/Legerity.Core/Windows/Exceptions/WinAppDriverNotFoundException.cs +++ b/src/Legerity.Core/Windows/Exceptions/WinAppDriverNotFoundException.cs @@ -12,11 +12,11 @@ public class WinAppDriverNotFoundException : LegerityException internal WinAppDriverNotFoundException(string path) : base($"The WinAppDriver could not be located at {path}. Please ensure it is installed first.") { - this.Path = path; + Path = path; } /// /// Gets or sets the path where the WinAppDriver should be located. /// public string Path { get; set; } -} \ No newline at end of file +} diff --git a/src/Legerity.Core/Windows/Helpers/WinAppDriverHelper.cs b/src/Legerity.Core/Windows/Helpers/WinAppDriverHelper.cs index 95c50559..1ae3bab5 100644 --- a/src/Legerity.Core/Windows/Helpers/WinAppDriverHelper.cs +++ b/src/Legerity.Core/Windows/Helpers/WinAppDriverHelper.cs @@ -4,11 +4,12 @@ namespace Legerity.Windows.Helpers; using System.Diagnostics; using System.IO; using System.Linq; -using Legerity.Windows.Exceptions; +using Exceptions; /// /// Defines a helper class for the WinAppDriver. /// +[Obsolete("WinAppDriver is not well maintained and is not supported directly by Appium 5 due to W3C standards. Instead, install the appium-windows-driver for the Appium CLI, and use the AppiumServerHelper to initialize.")] public static class WinAppDriverHelper { /// @@ -43,7 +44,7 @@ public static void Run(string path = DefaultInstallLocation) return; } - bool isInstalled = IsInstalled(path); + var isInstalled = IsInstalled(path); if (!isInstalled) { throw new WinAppDriverNotFoundException(path); @@ -75,4 +76,4 @@ public static void Stop() { } } -} \ No newline at end of file +} diff --git a/src/Legerity.Core/Windows/WindowsAppManagerOptions.cs b/src/Legerity.Core/Windows/WindowsAppManagerOptions.cs index ecba6b4c..f227e532 100644 --- a/src/Legerity.Core/Windows/WindowsAppManagerOptions.cs +++ b/src/Legerity.Core/Windows/WindowsAppManagerOptions.cs @@ -1,8 +1,9 @@ +using System; + namespace Legerity.Windows; using System.Collections.Generic; -using Legerity.Windows.Helpers; -using OpenQA.Selenium.Appium; +using Helpers; /// /// Defines a specific for a Windows application. @@ -38,8 +39,8 @@ public WindowsAppManagerOptions(string appId) /// public WindowsAppManagerOptions(string appId, params (string, object)[] additionalOptions) { - this.AppId = appId; - this.AdditionalOptions = additionalOptions; + AppId = appId; + AdditionalOptions = additionalOptions; } /// @@ -50,6 +51,7 @@ public WindowsAppManagerOptions(string appId, params (string, object)[] addition /// /// Gets or sets a value indicating whether to launch the WinAppDriver if it is not already running. /// + [Obsolete("Please use LaunchAppiumServer instead. LaunchWinAppDriver will continue to function, however, the WinAppDriver will not be launched directly due to no direct support by the W3C standard implemented in Appium 5. This property will be removed in a future release.")] public bool LaunchWinAppDriver { get; set; } /// @@ -71,7 +73,8 @@ public WindowsAppManagerOptions(string appId, params (string, object)[] addition public override void Configure() { base.Configure(); - this.AppiumOptions.AddAdditionalCapability("app", this.AppId); + AppiumOptions.App = AppId; + AppiumOptions.AutomationName = "Windows"; } /// @@ -82,34 +85,36 @@ public override void Configure() /// public void Configure((string, object)[] additionalOptions) { - this.AdditionalOptions = additionalOptions; - this.Configure(); + AdditionalOptions = additionalOptions; + Configure(); } /// Returns a string that represents the current object. /// A string that represents the current object. public override string ToString() { - return $"Platform [Windows], {base.ToString()}, {this.GetOptionDetails()}"; + return $"Platform [Windows], {base.ToString()}, {GetOptionDetails()}"; } private string GetOptionDetails() { var options = new List(); - if (!string.IsNullOrWhiteSpace(this.AppId)) + if (!string.IsNullOrWhiteSpace(AppId)) + { + options.Add($"App ID [{AppId}]"); + } + + if (AdditionalOptions == null) { - options.Add($"App ID [{this.AppId}]"); + return string.Join(", ", options); } - if (this.AdditionalOptions != null) + foreach (var (name, value) in AdditionalOptions) { - foreach ((string name, object value) in this.AdditionalOptions) - { - options.Add($"{name} [{value}]"); - } + options.Add($"{name} [{value}]"); } return string.Join(", ", options); } -} \ No newline at end of file +} diff --git a/src/Legerity.IOS/Elements/Core/Button.cs b/src/Legerity.IOS/Elements/Core/Button.cs index ff7de2f4..36a1c597 100644 --- a/src/Legerity.IOS/Elements/Core/Button.cs +++ b/src/Legerity.IOS/Elements/Core/Button.cs @@ -1,13 +1,9 @@ namespace Legerity.IOS.Elements.Core; -using Legerity.IOS.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.iOS; -using OpenQA.Selenium.Remote; +using Extensions; /// -/// Defines a wrapper for the core iOS Button control. +/// Defines a wrapper for the core iOS Button control. /// public class Button : IOSElementWrapper { @@ -15,9 +11,9 @@ public class Button : IOSElementWrapper /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public Button(IOSElement element) + public Button(WebElement element) : base(element) { } @@ -29,44 +25,16 @@ public Button(IOSElement element) public virtual string Label => this.GetLabel(); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator Button(IOSElement element) + public static implicit operator Button(WebElement element) { return new Button(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator Button(AppiumWebElement element) - { - return new Button(element as IOSElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator Button(RemoteWebElement element) - { - return new Button(element as IOSElement); - } -} \ No newline at end of file +} diff --git a/src/Legerity.IOS/Elements/Core/Label.cs b/src/Legerity.IOS/Elements/Core/Label.cs index c1eebf18..0e7011c3 100644 --- a/src/Legerity.IOS/Elements/Core/Label.cs +++ b/src/Legerity.IOS/Elements/Core/Label.cs @@ -1,13 +1,9 @@ namespace Legerity.IOS.Elements.Core; -using Legerity.IOS.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.iOS; -using OpenQA.Selenium.Remote; +using Extensions; /// -/// Defines a wrapper for the core iOS Label control. +/// Defines a wrapper for the core iOS Label control. /// public class Label : IOSElementWrapper { @@ -15,9 +11,9 @@ public class Label : IOSElementWrapper /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public Label(IOSElement element) + public Label(WebElement element) : base(element) { } @@ -29,44 +25,16 @@ public Label(IOSElement element) public virtual string Text => this.GetLabel(); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator Label(IOSElement element) + public static implicit operator Label(WebElement element) { return new Label(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator Label(AppiumWebElement element) - { - return new Label(element as IOSElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator Label(RemoteWebElement element) - { - return new Label(element as IOSElement); - } -} \ No newline at end of file +} diff --git a/src/Legerity.IOS/Elements/Core/ProgressView.cs b/src/Legerity.IOS/Elements/Core/ProgressView.cs index b343c163..09fa4b83 100644 --- a/src/Legerity.IOS/Elements/Core/ProgressView.cs +++ b/src/Legerity.IOS/Elements/Core/ProgressView.cs @@ -1,13 +1,9 @@ namespace Legerity.IOS.Elements.Core; -using Legerity.IOS.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.iOS; -using OpenQA.Selenium.Remote; +using Extensions; /// -/// Defines a wrapper for the core iOS ProgressView control. +/// Defines a wrapper for the core iOS ProgressView control. /// public class ProgressView : IOSElementWrapper { @@ -15,9 +11,9 @@ public class ProgressView : IOSElementWrapper /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public ProgressView(IOSElement element) + public ProgressView(WebElement element) : base(element) { } @@ -29,44 +25,16 @@ public ProgressView(IOSElement element) public virtual double Percentage => double.Parse(this.GetValue().TrimEnd('%')); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator ProgressView(IOSElement element) + public static implicit operator ProgressView(WebElement element) { return new ProgressView(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator ProgressView(AppiumWebElement element) - { - return new ProgressView(element as IOSElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator ProgressView(RemoteWebElement element) - { - return new ProgressView(element as IOSElement); - } -} \ No newline at end of file +} diff --git a/src/Legerity.IOS/Elements/Core/Slider.cs b/src/Legerity.IOS/Elements/Core/Slider.cs index 9860eeaf..83efd9af 100644 --- a/src/Legerity.IOS/Elements/Core/Slider.cs +++ b/src/Legerity.IOS/Elements/Core/Slider.cs @@ -1,14 +1,10 @@ namespace Legerity.IOS.Elements.Core; using System; -using Legerity.IOS.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.iOS; -using OpenQA.Selenium.Remote; +using Extensions; /// -/// Defines a wrapper for the core iOS Slider control. +/// Defines a wrapper for the core iOS Slider control. /// public class Slider : IOSElementWrapper { @@ -16,9 +12,9 @@ public class Slider : IOSElementWrapper /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public Slider(IOSElement element) + public Slider(WebElement element) : base(element) { } @@ -32,50 +28,22 @@ public Slider(IOSElement element) /// /// Gets a value indicating whether the control is in a readonly state. /// - public virtual bool IsReadonly => !this.IsEnabled; + public virtual bool IsReadonly => !IsEnabled; /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator Slider(IOSElement element) + public static implicit operator Slider(WebElement element) { return new Slider(element); } - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator Slider(AppiumWebElement element) - { - return new Slider(element as IOSElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator Slider(RemoteWebElement element) - { - return new Slider(element as IOSElement); - } - /// /// Sets the value of the slider. /// @@ -87,13 +55,13 @@ public static implicit operator Slider(RemoteWebElement element) /// Thrown when an element is no longer valid in the document DOM. public virtual void SetValue(double value) { - this.Click(); + Click(); - double currentValue = this.Value; + var currentValue = Value; while (Math.Abs(currentValue - value) > double.Epsilon) { - this.Element.SendKeys(currentValue < value ? Keys.ArrowRight : Keys.ArrowLeft); - currentValue = this.Value; + Element.SendKeys(currentValue < value ? Keys.ArrowRight : Keys.ArrowLeft); + currentValue = Value; } } -} \ No newline at end of file +} diff --git a/src/Legerity.IOS/Elements/Core/Switch.cs b/src/Legerity.IOS/Elements/Core/Switch.cs index b6f851e8..22ad10d1 100644 --- a/src/Legerity.IOS/Elements/Core/Switch.cs +++ b/src/Legerity.IOS/Elements/Core/Switch.cs @@ -1,13 +1,9 @@ namespace Legerity.IOS.Elements.Core; -using Legerity.IOS.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.iOS; -using OpenQA.Selenium.Remote; +using Extensions; /// -/// Defines a wrapper for the core iOS Switch control. +/// Defines a wrapper for the core iOS Switch control. /// public class Switch : IOSElementWrapper { @@ -17,9 +13,9 @@ public class Switch : IOSElementWrapper /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public Switch(IOSElement element) + public Switch(WebElement element) : base(element) { } @@ -31,47 +27,19 @@ public Switch(IOSElement element) public virtual bool IsOn => this.GetValue() == ToggleOnValue; /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator Switch(IOSElement element) + public static implicit operator Switch(WebElement element) { return new Switch(element); } - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator Switch(AppiumWebElement element) - { - return new Switch(element as IOSElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator Switch(RemoteWebElement element) - { - return new Switch(element as IOSElement); - } - /// /// Toggles the switch on. /// @@ -80,12 +48,12 @@ public static implicit operator Switch(RemoteWebElement element) /// Thrown when an element is no longer valid in the document DOM. public virtual void ToggleOn() { - if (this.IsOn) + if (IsOn) { return; } - this.Click(); + Click(); } /// @@ -96,11 +64,11 @@ public virtual void ToggleOn() /// Thrown when an element is no longer valid in the document DOM. public virtual void ToggleOff() { - if (!this.IsOn) + if (!IsOn) { return; } - this.Click(); + Click(); } -} \ No newline at end of file +} diff --git a/src/Legerity.IOS/Elements/Core/TextField.cs b/src/Legerity.IOS/Elements/Core/TextField.cs index f2974485..a57777ef 100644 --- a/src/Legerity.IOS/Elements/Core/TextField.cs +++ b/src/Legerity.IOS/Elements/Core/TextField.cs @@ -1,22 +1,18 @@ namespace Legerity.IOS.Elements.Core; -using Legerity.IOS.Elements; -using Legerity.IOS.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.iOS; -using OpenQA.Selenium.Remote; +using Elements; +using Extensions; /// -/// Defines a wrapper for the core iOS TextField control. +/// Defines a wrapper for the core iOS TextField control. /// public class TextField : IOSElementWrapper { /// /// Initializes a new instance of the class. /// - /// The representing the element. - public TextField(IOSElement element) + /// The representing the element. + public TextField(WebElement element) : base(element) { } @@ -31,50 +27,22 @@ public TextField(IOSElement element) /// Gets the element associated with the clear text button, if shown. /// /// Thrown when no element matches the expected locator. - public virtual Button ClearTextButton => this.FindElement(IOSByExtras.Label("Clear text")); + public virtual Button ClearTextButton => FindElement(IOSByExtras.Label("Clear text")); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator TextField(IOSElement element) + public static implicit operator TextField(WebElement element) { return new TextField(element); } - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator TextField(AppiumWebElement element) - { - return new TextField(element as IOSElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator TextField(RemoteWebElement element) - { - return new TextField(element as IOSElement); - } - /// /// Sets the text of the text field to the specified text. /// @@ -84,8 +52,8 @@ public static implicit operator TextField(RemoteWebElement element) /// Thrown when an element is no longer valid in the document DOM. public virtual void SetText(string text) { - this.ClearText(); - this.AppendText(text); + ClearText(); + AppendText(text); } /// @@ -97,8 +65,8 @@ public virtual void SetText(string text) /// Thrown when an element is no longer valid in the document DOM. public virtual void AppendText(string text) { - this.Click(); - this.Element.SendKeys(text); + Click(); + Element.SendKeys(text); } /// @@ -109,7 +77,7 @@ public virtual void AppendText(string text) /// Thrown when an element is no longer valid in the document DOM. public virtual void ClearText() { - this.Click(); - this.Element.Clear(); + Click(); + Element.Clear(); } -} \ No newline at end of file +} diff --git a/src/Legerity.IOS/Elements/IOSElementWrapper.cs b/src/Legerity.IOS/Elements/IOSElementWrapper.cs index 992cf130..a4e1915b 100644 --- a/src/Legerity.IOS/Elements/IOSElementWrapper.cs +++ b/src/Legerity.IOS/Elements/IOSElementWrapper.cs @@ -1,27 +1,20 @@ namespace Legerity.IOS.Elements; using System; - -using Legerity.Exceptions; - -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.iOS; -using OpenQA.Selenium.Remote; -using OpenQA.Selenium.Support.UI; +using Exceptions; /// -/// Defines an element wrapper for a . +/// Defines an element wrapper for an iOS . /// -public class IOSElementWrapper : ElementWrapper +public class IOSElementWrapper : ElementWrapper { /// /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public IOSElementWrapper(IOSElement element) + public IOSElementWrapper(WebElement element) : base(element) { } @@ -29,50 +22,22 @@ public IOSElementWrapper(IOSElement element) /// /// Gets the instance of the Appium driver for the iOS application. /// - public IOSDriver Driver => this.ElementDriver as IOSDriver; + public IOSDriver Driver => ElementDriver as IOSDriver; /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator IOSElementWrapper(IOSElement element) + public static implicit operator IOSElementWrapper(WebElement element) { return new IOSElementWrapper(element); } - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator IOSElementWrapper(AppiumWebElement element) - { - return new IOSElementWrapper(element as IOSElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator IOSElementWrapper(RemoteWebElement element) - { - return new IOSElementWrapper(element as IOSElement); - } - /// /// Determines whether the specified element is shown with the specified timeout. /// @@ -88,7 +53,7 @@ protected void VerifyDriverElementShown(By locator, TimeSpan? timeout) { try { - if (this.Driver.FindElement(locator) == null) + if (Driver.FindElement(locator) == null) { throw new ElementNotShownException(locator.ToString()); } @@ -100,7 +65,7 @@ protected void VerifyDriverElementShown(By locator, TimeSpan? timeout) } else { - var wait = new WebDriverWait(this.Driver, timeout.Value); + var wait = new WebDriverWait(Driver, timeout.Value); wait.Until(driver => driver.FindElement(locator) != null); } } @@ -119,15 +84,15 @@ protected void VerifyDriverElementsShown(By locator, TimeSpan? timeout) { if (timeout == null) { - if (this.Driver.FindElements(locator).Count == 0) + if (Driver.FindElements(locator).Count == 0) { throw new ElementsNotShownException(locator.ToString()); } } else { - var wait = new WebDriverWait(this.Driver, timeout.Value); + var wait = new WebDriverWait(Driver, timeout.Value); wait.Until(driver => driver.FindElements(locator).Count != 0); } } -} \ No newline at end of file +} diff --git a/src/Legerity.IOS/Extensions/AttributeExtensions.cs b/src/Legerity.IOS/Extensions/AttributeExtensions.cs index 2eb88629..18ab3c8c 100644 --- a/src/Legerity.IOS/Extensions/AttributeExtensions.cs +++ b/src/Legerity.IOS/Extensions/AttributeExtensions.cs @@ -1,8 +1,5 @@ namespace Legerity.IOS.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Remote; - /// /// Defines a collection of extensions for retrieving element attributes. /// @@ -23,7 +20,7 @@ public static string GetLabel(this IWebElement element) /// Retrieves the label attribute from the specified element. /// /// - /// The type of . + /// The type of . /// /// The to retrieve a label from. /// The label of the element. @@ -49,7 +46,7 @@ public static string GetValue(this IWebElement element) /// Retrieves the value attribute from the specified element. /// /// - /// The type of . + /// The type of . /// /// The to retrieve a value from. /// The value of the element. @@ -59,4 +56,4 @@ public static string GetValue(this IElementWrapper element) { return GetValue(element.Element); } -} \ No newline at end of file +} diff --git a/src/Legerity.IOS/Extensions/IOSElementWrapperExtensions.cs b/src/Legerity.IOS/Extensions/IOSElementWrapperExtensions.cs index fc37ff6c..a8b32a42 100644 --- a/src/Legerity.IOS/Extensions/IOSElementWrapperExtensions.cs +++ b/src/Legerity.IOS/Extensions/IOSElementWrapperExtensions.cs @@ -1,9 +1,7 @@ namespace Legerity.IOS.Extensions; using System; -using Legerity.IOS.Elements; -using OpenQA.Selenium; -using OpenQA.Selenium.Support.UI; +using Elements; /// /// Defines a collection of extensions for objects. @@ -86,4 +84,4 @@ public static TResult WaitUntil( return WaitUntil(element, condition, timeout, retries - 1); } } -} \ No newline at end of file +} diff --git a/src/Legerity.IOS/Extensions/LegerityTestClassExtensions.cs b/src/Legerity.IOS/Extensions/LegerityTestClassExtensions.cs index fcc5fb00..e6756177 100644 --- a/src/Legerity.IOS/Extensions/LegerityTestClassExtensions.cs +++ b/src/Legerity.IOS/Extensions/LegerityTestClassExtensions.cs @@ -2,8 +2,6 @@ namespace Legerity.IOS.Extensions; using System; using Exceptions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium.iOS; /// /// Defines a collection of extensions for instances. @@ -31,13 +29,13 @@ public static class LegerityTestClassExtensions /// Thrown when: /// - The Appium server could not be found when running with true. /// - public static IOSDriver StartIOSApp( + public static IOSDriver StartIOSApp( this LegerityTestClass testClass, Func waitUntil = default, TimeSpan? waitUntilTimeout = default, int waitUntilRetries = 0) { - return testClass.StartApp(waitUntil, waitUntilTimeout, waitUntilRetries) as IOSDriver; + return testClass.StartApp(waitUntil, waitUntilTimeout, waitUntilRetries) as IOSDriver; } /// @@ -67,7 +65,7 @@ public static IOSDriver StartIOSApp( /// Thrown when: /// - The Appium server could not be found when running with true. /// - public static IOSDriver StartIOSApp( + public static IOSDriver StartIOSApp( this LegerityTestClass testClass, IOSAppManagerOptions options, Func waitUntil = default, @@ -75,6 +73,6 @@ public static IOSDriver StartIOSApp( int waitUntilRetries = 0) { return testClass.StartApp(options, waitUntil, waitUntilTimeout, waitUntilRetries) as - IOSDriver; + IOSDriver; } -} \ No newline at end of file +} diff --git a/src/Legerity.IOS/GlobalUsings.cs b/src/Legerity.IOS/GlobalUsings.cs new file mode 100644 index 00000000..80fc043d --- /dev/null +++ b/src/Legerity.IOS/GlobalUsings.cs @@ -0,0 +1,5 @@ +// Global using directives + +global using OpenQA.Selenium; +global using OpenQA.Selenium.Appium.iOS; +global using OpenQA.Selenium.Support.UI; diff --git a/src/Legerity.IOS/IOSByExtras.cs b/src/Legerity.IOS/IOSByExtras.cs index 44805473..a6eb4f7a 100644 --- a/src/Legerity.IOS/IOSByExtras.cs +++ b/src/Legerity.IOS/IOSByExtras.cs @@ -1,7 +1,5 @@ namespace Legerity.IOS; -using OpenQA.Selenium; - /// /// Defines a collection of extra locator constraints for . /// @@ -46,4 +44,4 @@ public static By PartialValue(string value) { return By.XPath($".//*[contains(@value,'{value}')]"); } -} \ No newline at end of file +} diff --git a/src/Legerity.IOS/Legerity.IOS.csproj b/src/Legerity.IOS/Legerity.IOS.csproj index a3c82821..e0d8a757 100644 --- a/src/Legerity.IOS/Legerity.IOS.csproj +++ b/src/Legerity.IOS/Legerity.IOS.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + net6.0;net7.0;net8.0 true Legerity for iOS - Framework for UI testing with Selenium/Appium @@ -12,7 +12,7 @@ - + diff --git a/src/Legerity.MADE/DropDownList.cs b/src/Legerity.MADE/DropDownList.cs index 3b6a344d..0a3ed7fa 100644 --- a/src/Legerity.MADE/DropDownList.cs +++ b/src/Legerity.MADE/DropDownList.cs @@ -1,14 +1,10 @@ namespace Legerity.Windows.Elements.MADE; using Legerity.Exceptions; -using Legerity.Windows.Elements.Core; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; +using Core; /// -/// Defines a wrapper for the MADE.NET UWP DropDownList control. +/// Defines a wrapper for the MADE.NET UWP DropDownList control. /// public class DropDownList : WindowsElementWrapper { @@ -16,9 +12,9 @@ public class DropDownList : WindowsElementWrapper /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public DropDownList(WindowsElement element) + public DropDownList(WebElement element) : base(element) { } @@ -27,50 +23,22 @@ public DropDownList(WindowsElement element) /// Gets the element associated with the drop down content. /// /// Thrown when no element matches the expected locator. - public virtual ListView DropDown => this.FindElement(WindowsByExtras.AutomationId("DropDownContent")); + public virtual ListView DropDown => FindElement(WindowsByExtras.AutomationId("DropDownContent")); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator DropDownList(WindowsElement element) + public static implicit operator DropDownList(WebElement element) { return new DropDownList(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator DropDownList(AppiumWebElement element) - { - return new DropDownList(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator DropDownList(RemoteWebElement element) - { - return new DropDownList(element as WindowsElement); - } - + /// /// Selects an item in the combo-box with the specified item name. /// @@ -84,8 +52,8 @@ public static implicit operator DropDownList(RemoteWebElement element) /// Thrown when no elements are shown for the expected locator. public virtual void SelectItem(string name) { - this.OpenDropDown(); - this.DropDown.ClickItem(name); + OpenDropDown(); + DropDown.ClickItem(name); } /// @@ -99,8 +67,8 @@ public virtual void SelectItem(string name) /// Thrown when no elements are shown for the expected locator. public virtual void SelectItemByPartialName(string partialName) { - this.OpenDropDown(); - this.DropDown.ClickItemByPartialName(partialName); + OpenDropDown(); + DropDown.ClickItemByPartialName(partialName); } /// @@ -111,9 +79,9 @@ public virtual void SelectItemByPartialName(string partialName) /// Thrown when an element is no longer valid in the document DOM. public virtual void OpenDropDown() { - if (!this.IsDropDownOpen()) + if (!IsDropDownOpen()) { - this.Click(); + Click(); } } @@ -128,7 +96,7 @@ public virtual bool IsDropDownOpen() try { - isVisible = this.DropDown.IsVisible; + isVisible = DropDown.IsVisible; } catch (WebDriverException wde) when (wde.Message.Contains("element could not be located")) { @@ -141,4 +109,4 @@ public virtual bool IsDropDownOpen() return isVisible; } -} \ No newline at end of file +} diff --git a/src/Legerity.MADE/GlobalUsings.cs b/src/Legerity.MADE/GlobalUsings.cs new file mode 100644 index 00000000..cb00424d --- /dev/null +++ b/src/Legerity.MADE/GlobalUsings.cs @@ -0,0 +1,3 @@ +// Global using directives + +global using OpenQA.Selenium; diff --git a/src/Legerity.MADE/InputValidator.cs b/src/Legerity.MADE/InputValidator.cs index e307529b..110380b8 100644 --- a/src/Legerity.MADE/InputValidator.cs +++ b/src/Legerity.MADE/InputValidator.cs @@ -1,13 +1,9 @@ namespace Legerity.Windows.Elements.MADE; -using Legerity.Windows.Elements.Core; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; +using Core; /// -/// Defines a wrapper for the MADE.NET UWP InputValidator control. +/// Defines a wrapper for the MADE.NET UWP InputValidator control. /// public class InputValidator : WindowsElementWrapper { @@ -15,9 +11,9 @@ public class InputValidator : WindowsElementWrapper /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public InputValidator(WindowsElement element) + public InputValidator(WebElement element) : base(element) { } @@ -27,65 +23,37 @@ public InputValidator(WindowsElement element) /// /// Thrown when no element matches the expected locator. public virtual TextBlock ValidationFeedback => - this.FindElement(WindowsByExtras.AutomationId("ValidatorFeedbackMessage")); + FindElement(WindowsByExtras.AutomationId("ValidatorFeedbackMessage")); /// /// Gets the validation feedback message associated with the element. /// /// Thrown when an element is no longer valid in the document DOM. - public virtual string Message => this.ValidationFeedback?.Text; + public virtual string Message => ValidationFeedback?.Text; /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator InputValidator(WindowsElement element) + public static implicit operator InputValidator(WebElement element) { return new InputValidator(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator InputValidator(AppiumWebElement element) - { - return new InputValidator(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator InputValidator(RemoteWebElement element) - { - return new InputValidator(element as WindowsElement); - } - + /// /// Retrieves the input element with the given locator. /// /// The locator to find the input element. - /// The if found; otherwise, throws . + /// The if found; otherwise, throws . /// Thrown when no element matches the expected locator. - public AppiumWebElement Input(By locator) + public WebElement Input(By locator) { - return this.FindElement(locator); + return FindElement(locator); } /// @@ -100,7 +68,7 @@ public virtual string FeedbackMessage() try { - message = this.ValidationFeedback.Text; + message = ValidationFeedback.Text; } catch (WebDriverException ex) when (ex.Message.Contains("element could not be located")) { @@ -109,4 +77,4 @@ public virtual string FeedbackMessage() return message; } -} \ No newline at end of file +} diff --git a/src/Legerity.MADE/Legerity.MADE.csproj b/src/Legerity.MADE/Legerity.MADE.csproj index e9e078b0..da670834 100644 --- a/src/Legerity.MADE/Legerity.MADE.csproj +++ b/src/Legerity.MADE/Legerity.MADE.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + net6.0;net7.0;net8.0 true Legerity for MADE.NET - Framework for UI tests with Selenium/Appium @@ -14,7 +14,7 @@ - + diff --git a/src/Legerity.Telerik.Uwp/GlobalUsings.cs b/src/Legerity.Telerik.Uwp/GlobalUsings.cs new file mode 100644 index 00000000..cb00424d --- /dev/null +++ b/src/Legerity.Telerik.Uwp/GlobalUsings.cs @@ -0,0 +1,3 @@ +// Global using directives + +global using OpenQA.Selenium; diff --git a/src/Legerity.Telerik.Uwp/Legerity.Telerik.Uwp.csproj b/src/Legerity.Telerik.Uwp/Legerity.Telerik.Uwp.csproj index 2383448a..c763d0e3 100644 --- a/src/Legerity.Telerik.Uwp/Legerity.Telerik.Uwp.csproj +++ b/src/Legerity.Telerik.Uwp/Legerity.Telerik.Uwp.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + net6.0;net7.0;net8.0 true Legerity for Telerik for UWP - Framework for UI tests with Selenium/Appium @@ -16,7 +16,7 @@ - + diff --git a/src/Legerity.Telerik.Uwp/RadAutoCompleteBox.cs b/src/Legerity.Telerik.Uwp/RadAutoCompleteBox.cs index 259722aa..cceaa5e3 100644 --- a/src/Legerity.Telerik.Uwp/RadAutoCompleteBox.cs +++ b/src/Legerity.Telerik.Uwp/RadAutoCompleteBox.cs @@ -2,26 +2,22 @@ namespace Legerity.Windows.Elements.Telerik; using System; using Legerity.Exceptions; -using Legerity.Windows.Elements.Core; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; +using Core; /// -/// Defines a wrapper for the Telerik UWP RadAutoCompleteBox control. +/// Defines a wrapper for the Telerik UWP RadAutoCompleteBox control. /// public class RadAutoCompleteBox : WindowsElementWrapper { - private readonly By suggestionsControlLocator = WindowsByExtras.AutomationId("PART_SuggestionsControl"); + private readonly By _suggestionsControlLocator = WindowsByExtras.AutomationId("PART_SuggestionsControl"); /// /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public RadAutoCompleteBox(WindowsElement element) + public RadAutoCompleteBox(WebElement element) : base(element) { } @@ -30,56 +26,28 @@ public RadAutoCompleteBox(WindowsElement element) /// Gets the element associated with the text box. /// /// Thrown when no element matches the expected locator. - public virtual TextBox TextBox => this.FindElement(By.ClassName("TextBox")); + public virtual TextBox TextBox => FindElement(By.ClassName("TextBox")); /// /// Gets the value of the auto-suggest box. /// /// Thrown when an element is no longer valid in the document DOM. - public virtual string Text => this.TextBox.Text; + public virtual string Text => TextBox.Text; /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator RadAutoCompleteBox(WindowsElement element) + public static implicit operator RadAutoCompleteBox(WebElement element) { return new RadAutoCompleteBox(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator RadAutoCompleteBox(AppiumWebElement element) - { - return new RadAutoCompleteBox(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator RadAutoCompleteBox(RemoteWebElement element) - { - return new RadAutoCompleteBox(element as WindowsElement); - } - + /// /// Selects a suggestion from the auto-suggest box. /// @@ -92,7 +60,7 @@ public static implicit operator RadAutoCompleteBox(RemoteWebElement element) /// Thrown when no elements are shown for the expected locator. public virtual void SelectSuggestion(string suggestion) { - this.SelectSuggestion(suggestion, suggestion); + SelectSuggestion(suggestion, suggestion); } /// @@ -108,11 +76,11 @@ public virtual void SelectSuggestion(string suggestion) /// Thrown when no elements are shown for the expected locator. public virtual void SelectSuggestion(string value, string suggestion) { - this.SetText(value); + SetText(value); - this.VerifyElementShown(this.suggestionsControlLocator, TimeSpan.FromSeconds(2)); + VerifyElementShown(_suggestionsControlLocator, TimeSpan.FromSeconds(2)); - ListBox suggestionList = this.FindElement(this.suggestionsControlLocator); + ListBox suggestionList = FindElement(_suggestionsControlLocator); suggestionList.ClickItem(suggestion); } @@ -129,11 +97,11 @@ public virtual void SelectSuggestion(string value, string suggestion) /// Thrown when no elements are shown for the expected locator. public virtual void SelectSuggestionByPartialSuggestion(string value, string partialSuggestion) { - this.SetText(value); + SetText(value); - this.VerifyElementShown(this.suggestionsControlLocator, TimeSpan.FromSeconds(2)); + VerifyElementShown(_suggestionsControlLocator, TimeSpan.FromSeconds(2)); - ListBox suggestionList = this.FindElement(this.suggestionsControlLocator); + ListBox suggestionList = FindElement(_suggestionsControlLocator); suggestionList.ClickItemByPartialName(partialSuggestion); } @@ -147,6 +115,6 @@ public virtual void SelectSuggestionByPartialSuggestion(string value, string par /// Thrown when an element is not visible. public virtual void SetText(string value) { - this.TextBox.SetText(value); + TextBox.SetText(value); } -} \ No newline at end of file +} diff --git a/src/Legerity.Telerik.Uwp/RadBulletGraph.cs b/src/Legerity.Telerik.Uwp/RadBulletGraph.cs index a74ad09d..1ddc1eef 100644 --- a/src/Legerity.Telerik.Uwp/RadBulletGraph.cs +++ b/src/Legerity.Telerik.Uwp/RadBulletGraph.cs @@ -1,13 +1,9 @@ namespace Legerity.Windows.Elements.Telerik; -using Legerity.Windows.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; +using Extensions; /// -/// Defines a wrapper for the Telerik UWP RadBulletGraph control. +/// Defines a wrapper for the Telerik UWP RadBulletGraph control. /// public class RadBulletGraph : WindowsElementWrapper { @@ -15,9 +11,9 @@ public class RadBulletGraph : WindowsElementWrapper /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public RadBulletGraph(WindowsElement element) + public RadBulletGraph(WebElement element) : base(element) { } @@ -41,44 +37,16 @@ public RadBulletGraph(WindowsElement element) public virtual double Value => this.GetRangeValue(); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator RadBulletGraph(WindowsElement element) + public static implicit operator RadBulletGraph(WebElement element) { return new RadBulletGraph(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator RadBulletGraph(AppiumWebElement element) - { - return new RadBulletGraph(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator RadBulletGraph(RemoteWebElement element) - { - return new RadBulletGraph(element as WindowsElement); - } -} \ No newline at end of file +} diff --git a/src/Legerity.Telerik.Uwp/RadBusyIndicator.cs b/src/Legerity.Telerik.Uwp/RadBusyIndicator.cs index c825b2a9..8ba833ae 100644 --- a/src/Legerity.Telerik.Uwp/RadBusyIndicator.cs +++ b/src/Legerity.Telerik.Uwp/RadBusyIndicator.cs @@ -1,12 +1,7 @@ namespace Legerity.Windows.Elements.Telerik; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; - /// -/// Defines a wrapper for the Telerik UWP RadBusyIndicator control. +/// Defines a wrapper for the Telerik UWP RadBusyIndicator control. /// public class RadBusyIndicator : WindowsElementWrapper { @@ -16,9 +11,9 @@ public class RadBusyIndicator : WindowsElementWrapper /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public RadBusyIndicator(WindowsElement element) + public RadBusyIndicator(WebElement element) : base(element) { } @@ -27,47 +22,19 @@ public RadBusyIndicator(WindowsElement element) /// Gets a value indicating whether the busy indicator is on. /// /// Thrown when an element is no longer valid in the document DOM. - public virtual bool IsOn => this.GetAttribute("ItemStatus") == OnValue; + public virtual bool IsOn => GetAttribute("ItemStatus") == OnValue; /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator RadBusyIndicator(WindowsElement element) + public static implicit operator RadBusyIndicator(WebElement element) { return new RadBusyIndicator(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator RadBusyIndicator(AppiumWebElement element) - { - return new RadBusyIndicator(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator RadBusyIndicator(RemoteWebElement element) - { - return new RadBusyIndicator(element as WindowsElement); - } -} \ No newline at end of file +} diff --git a/src/Legerity.Telerik.Uwp/RadNumericBox.cs b/src/Legerity.Telerik.Uwp/RadNumericBox.cs index b25451b3..9863d479 100644 --- a/src/Legerity.Telerik.Uwp/RadNumericBox.cs +++ b/src/Legerity.Telerik.Uwp/RadNumericBox.cs @@ -1,15 +1,11 @@ namespace Legerity.Windows.Elements.Telerik; using System; -using Legerity.Windows.Elements.Core; -using Legerity.Windows.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; +using Core; +using Extensions; /// -/// Defines a wrapper for the Telerik UWP RadNumericBox control. +/// Defines a wrapper for the Telerik UWP RadNumericBox control. /// public class RadNumericBox : WindowsElementWrapper { @@ -17,9 +13,9 @@ public class RadNumericBox : WindowsElementWrapper /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public RadNumericBox(WindowsElement element) + public RadNumericBox(WebElement element) : base(element) { } @@ -58,62 +54,34 @@ public RadNumericBox(WindowsElement element) /// Gets the element associated with the increase button. /// /// Thrown when no element matches the expected locator. - public virtual Button Increase => this.FindElement(WindowsByExtras.AutomationId("PART_IncreaseButton")); + public virtual Button Increase => FindElement(WindowsByExtras.AutomationId("PART_IncreaseButton")); /// /// Gets the element associated with the decrease button. /// /// Thrown when no element matches the expected locator. - public virtual Button DecreaseButton => this.FindElement(WindowsByExtras.AutomationId("PART_DecreaseButton")); + public virtual Button DecreaseButton => FindElement(WindowsByExtras.AutomationId("PART_DecreaseButton")); /// /// Gets the element associated with the input text box. /// /// Thrown when no element matches the expected locator. - public virtual TextBox InputBox => this.FindElement(WindowsByExtras.AutomationId("PART_TextBox")); + public virtual TextBox InputBox => FindElement(WindowsByExtras.AutomationId("PART_TextBox")); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator RadNumericBox(WindowsElement element) + public static implicit operator RadNumericBox(WebElement element) { return new RadNumericBox(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator RadNumericBox(AppiumWebElement element) - { - return new RadNumericBox(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator RadNumericBox(RemoteWebElement element) - { - return new RadNumericBox(element as WindowsElement); - } - + /// /// Sets the value of the RadNumericBox. /// @@ -129,10 +97,10 @@ public static implicit operator RadNumericBox(RemoteWebElement element) /// Thrown when no element matches the expected locator. public virtual void SetValue(double value) { - double min = this.Minimum; - double max = this.Maximum; + var min = Minimum; + var max = Maximum; - if (value < this.Minimum) + if (value < Minimum) { throw new ArgumentOutOfRangeException( nameof(value), @@ -140,7 +108,7 @@ public virtual void SetValue(double value) $"Value must be greater than or equal to the minimum value {min}"); } - if (value > this.Maximum) + if (value > Maximum) { throw new ArgumentOutOfRangeException( nameof(value), @@ -148,8 +116,8 @@ public virtual void SetValue(double value) $"Value must be less than or equal to the maximum value {max}"); } - this.InputBox.SetText(value.ToString()); - this.InputBox.Element.SendKeys(Keys.Enter); + InputBox.SetText(value.ToString()); + InputBox.Element.SendKeys(Keys.Enter); } /// @@ -161,7 +129,7 @@ public virtual void SetValue(double value) /// Thrown when an element is no longer valid in the document DOM. public virtual void Increment() { - this.Increase.Click(); + Increase.Click(); } /// @@ -173,6 +141,6 @@ public virtual void Increment() /// Thrown when an element is no longer valid in the document DOM. public virtual void Decrement() { - this.DecreaseButton.Click(); + DecreaseButton.Click(); } -} \ No newline at end of file +} diff --git a/src/Legerity.WCT/BladeView.cs b/src/Legerity.WCT/BladeView.cs index f2ed3a38..830e8a6e 100644 --- a/src/Legerity.WCT/BladeView.cs +++ b/src/Legerity.WCT/BladeView.cs @@ -2,14 +2,10 @@ namespace Legerity.Windows.Elements.WCT; using System.Collections.Generic; using System.Linq; -using Legerity.Windows.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; +using Extensions; /// -/// Defines a wrapper for the Windows Community Toolkit BladeView control. +/// Defines a wrapper for the Windows Community Toolkit BladeView control. /// public class BladeView : WindowsElementWrapper { @@ -17,9 +13,9 @@ public class BladeView : WindowsElementWrapper /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public BladeView(WindowsElement element) + public BladeView(WebElement element) : base(element) { } @@ -28,51 +24,23 @@ public BladeView(WindowsElement element) /// Gets the UI components associated with the child blades. /// public virtual IEnumerable Blades => - this.Element.FindElements(By.ClassName("BladeItem")) - .Select(element => new BladeViewItem(this, element as WindowsElement)); + Element.FindElements(By.ClassName("BladeItem")) + .Select(element => new BladeViewItem(this, element as WebElement)); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator BladeView(WindowsElement element) + public static implicit operator BladeView(WebElement element) { return new BladeView(element); } - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator BladeView(AppiumWebElement element) - { - return new BladeView(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator BladeView(RemoteWebElement element) - { - return new BladeView(element as WindowsElement); - } - /// /// Retrieves a by the given name. /// @@ -81,7 +49,7 @@ public static implicit operator BladeView(RemoteWebElement element) /// Thrown when an element is no longer valid in the document DOM. public virtual BladeViewItem GetBlade(string name) { - return this.Blades.FirstOrDefault(element => element.Element.VerifyNameOrAutomationIdEquals(name)); + return Blades.FirstOrDefault(element => element.Element.VerifyNameOrAutomationIdEquals(name)); } /// @@ -92,7 +60,7 @@ public virtual BladeViewItem GetBlade(string name) /// Thrown when an element is no longer valid in the document DOM. public virtual BladeViewItem GetBladeByPartialName(string partialName) { - return this.Blades.FirstOrDefault(element => element.Element.VerifyNameOrAutomationIdContains(partialName)); + return Blades.FirstOrDefault(element => element.Element.VerifyNameOrAutomationIdContains(partialName)); } /// @@ -105,7 +73,7 @@ public virtual BladeViewItem GetBladeByPartialName(string partialName) /// Thrown when an element is not visible. public virtual void CloseBlade(string name) { - BladeViewItem blade = this.GetBlade(name); + var blade = GetBlade(name); blade.Close(); } @@ -119,7 +87,7 @@ public virtual void CloseBlade(string name) /// Thrown when an element is not visible. public virtual void CloseBladeByPartialName(string partialName) { - BladeViewItem blade = this.GetBladeByPartialName(partialName); + var blade = GetBladeByPartialName(partialName); blade.Close(); } -} \ No newline at end of file +} diff --git a/src/Legerity.WCT/BladeViewItem.cs b/src/Legerity.WCT/BladeViewItem.cs index 05dd3948..2ce8003f 100644 --- a/src/Legerity.WCT/BladeViewItem.cs +++ b/src/Legerity.WCT/BladeViewItem.cs @@ -1,26 +1,22 @@ namespace Legerity.Windows.Elements.WCT; using System; -using Legerity.Windows.Elements.Core; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; +using Core; /// -/// Defines a wrapper for the Windows Community Toolkit BladeViewItem control. +/// Defines a wrapper for the Windows Community Toolkit BladeViewItem control. /// public class BladeViewItem : WindowsElementWrapper { - private readonly WeakReference parentBladeViewReference; + private readonly WeakReference _parentBladeViewReference; /// /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public BladeViewItem(WindowsElement element) + public BladeViewItem(WebElement element) : this(null, element) { } @@ -32,79 +28,51 @@ public BladeViewItem(WindowsElement element) /// The parent . /// /// - /// The reference. + /// The reference. /// public BladeViewItem( BladeView parentBladeView, - WindowsElement element) + WebElement element) : base(element) { if (parentBladeView != null) { - this.parentBladeViewReference = new WeakReference(parentBladeView); + _parentBladeViewReference = new WeakReference(parentBladeView); } } /// Gets the original parent reference object. public BladeView ParentMenuBar => - this.parentBladeViewReference is { IsAlive: true } - ? this.parentBladeViewReference.Target as BladeView + _parentBladeViewReference is { IsAlive: true } + ? _parentBladeViewReference.Target as BladeView : null; /// /// Gets the element associated with the blade enlarge option. /// /// Thrown when no element matches the expected locator. - public virtual Button EnlargeButton => this.FindElement(WindowsByExtras.AutomationId("EnlargeButton")); + public virtual Button EnlargeButton => FindElement(WindowsByExtras.AutomationId("EnlargeButton")); /// /// Gets the element associated with the blade close option. /// /// Thrown when no element matches the expected locator. - public virtual Button CloseButton => this.FindElement(WindowsByExtras.AutomationId("CloseButton")); + public virtual Button CloseButton => FindElement(WindowsByExtras.AutomationId("CloseButton")); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator BladeViewItem(WindowsElement element) + public static implicit operator BladeViewItem(WebElement element) { return new BladeViewItem(element); } - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator BladeViewItem(AppiumWebElement element) - { - return new BladeViewItem(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator BladeViewItem(RemoteWebElement element) - { - return new BladeViewItem(element as WindowsElement); - } - /// /// Closes the blade item. /// @@ -114,6 +82,6 @@ public static implicit operator BladeViewItem(RemoteWebElement element) /// Thrown when an element is no longer valid in the document DOM. public virtual void Close() { - this.CloseButton.Click(); + CloseButton.Click(); } -} \ No newline at end of file +} diff --git a/src/Legerity.WCT/Carousel.cs b/src/Legerity.WCT/Carousel.cs index a113eb6f..86d6c63a 100644 --- a/src/Legerity.WCT/Carousel.cs +++ b/src/Legerity.WCT/Carousel.cs @@ -4,27 +4,23 @@ namespace Legerity.Windows.Elements.WCT; using System.Collections.ObjectModel; using System.Linq; using Legerity.Exceptions; -using Legerity.Windows.Elements.Core; -using Legerity.Windows.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; +using Core; +using Extensions; /// -/// Defines a wrapper for the Windows Community Toolkit Carousel control. +/// Defines a wrapper for the Windows Community Toolkit Carousel control. /// public class Carousel : WindowsElementWrapper { - private readonly By carouselItemLocator = By.ClassName("CarouselItem"); + private readonly By _carouselItemLocator = By.ClassName("CarouselItem"); /// /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public Carousel(WindowsElement element) + public Carousel(WebElement element) : base(element) { } @@ -32,63 +28,35 @@ public Carousel(WindowsElement element) /// /// Gets the collection of items associated with the carousel. /// - public virtual ReadOnlyCollection Items => - this.Element.FindElements(this.carouselItemLocator); + public virtual ReadOnlyCollection Items => + Element.FindElements(_carouselItemLocator).Cast().ToList().AsReadOnly(); /// /// Gets the element associated with the currently selected item. /// /// Thrown when an element is no longer valid in the document DOM. - public virtual AppiumWebElement SelectedItem => this.Items.FirstOrDefault(i => i.IsSelected()); + public virtual WebElement SelectedItem => Items.FirstOrDefault(i => i.IsSelected()); /// /// Gets the index of the element associated with the currently selected item. /// /// Thrown when an element is no longer valid in the document DOM. - public virtual int SelectedIndex => this.Items.IndexOf(this.SelectedItem); + public virtual int SelectedIndex => Items.IndexOf(SelectedItem); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator Carousel(WindowsElement element) + public static implicit operator Carousel(WebElement element) { return new Carousel(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator Carousel(AppiumWebElement element) - { - return new Carousel(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator Carousel(RemoteWebElement element) - { - return new Carousel(element as WindowsElement); - } - + /// /// Clicks on an item in the carousel with the specified item name. /// @@ -101,12 +69,12 @@ public static implicit operator Carousel(RemoteWebElement element) /// Thrown when an element is not visible. public virtual void SelectItem(string name) { - this.VerifyElementsShown(this.carouselItemLocator, TimeSpan.FromSeconds(2)); + VerifyElementsShown(_carouselItemLocator, TimeSpan.FromSeconds(2)); - int index = this.Items.IndexOf(this.Items.FirstOrDefault(element => + var index = Items.IndexOf(Items.FirstOrDefault(element => element.VerifyNameOrAutomationIdEquals(name))); - this.SelectItemAtIndex(index); + SelectItemAtIndex(index); } /// @@ -121,12 +89,12 @@ public virtual void SelectItem(string name) /// Thrown when an element is not visible. public virtual void SelectItemByPartialName(string partialName) { - this.VerifyElementsShown(this.carouselItemLocator, TimeSpan.FromSeconds(2)); + VerifyElementsShown(_carouselItemLocator, TimeSpan.FromSeconds(2)); - int index = this.Items.IndexOf(this.Items.FirstOrDefault(element => + var index = Items.IndexOf(Items.FirstOrDefault(element => element.VerifyNameOrAutomationIdContains(partialName))); - this.SelectItemAtIndex(index); + SelectItemAtIndex(index); } /// @@ -142,15 +110,15 @@ public virtual void SelectItemByPartialName(string partialName) /// Thrown when an element is not visible. public virtual void SelectItem(int index) { - this.VerifyElementsShown(this.carouselItemLocator, TimeSpan.FromSeconds(2)); + VerifyElementsShown(_carouselItemLocator, TimeSpan.FromSeconds(2)); - if (index > this.Items.Count - 1) + if (index > Items.Count - 1) { throw new IndexOutOfRangeException( "Cannot select an element that is outside the range of items available."); } - this.SelectItemAtIndex(index); + SelectItemAtIndex(index); } /// Thrown when an element is no longer valid in the document DOM. @@ -158,11 +126,11 @@ public virtual void SelectItem(int index) /// Thrown when an element is not visible. private void SelectItemAtIndex(int index) { - int selectedIndex = this.SelectedIndex; + var selectedIndex = SelectedIndex; while (Math.Abs(index - selectedIndex) > double.Epsilon) { - this.Element.SendKeys(selectedIndex < index ? Keys.ArrowRight : Keys.ArrowLeft); - selectedIndex = this.SelectedIndex; + Element.SendKeys(selectedIndex < index ? Keys.ArrowRight : Keys.ArrowLeft); + selectedIndex = SelectedIndex; } } -} \ No newline at end of file +} diff --git a/src/Legerity.WCT/Expander.cs b/src/Legerity.WCT/Expander.cs index 3d7d02f5..37dfb630 100644 --- a/src/Legerity.WCT/Expander.cs +++ b/src/Legerity.WCT/Expander.cs @@ -1,14 +1,10 @@ namespace Legerity.Windows.Elements.WCT; -using Legerity.Windows.Elements.Core; -using Legerity.Windows.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; +using Core; +using Extensions; /// -/// Defines a wrapper for the Windows Community Toolkit Expander control. +/// Defines a wrapper for the Windows Community Toolkit Expander control. /// public class Expander : WindowsElementWrapper { @@ -16,9 +12,9 @@ public class Expander : WindowsElementWrapper /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public Expander(WindowsElement element) + public Expander(WebElement element) : base(element) { } @@ -33,50 +29,22 @@ public Expander(WindowsElement element) /// Gets the associated with the expander. /// /// Thrown when no element matches the expected locator. - public virtual ToggleButton ToggleButton => this.FindElement(WindowsByExtras.AutomationId("PART_ExpanderToggleButton")); + public virtual ToggleButton ToggleButton => FindElement(WindowsByExtras.AutomationId("PART_ExpanderToggleButton")); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator Expander(WindowsElement element) + public static implicit operator Expander(WebElement element) { return new Expander(element); } - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator Expander(AppiumWebElement element) - { - return new Expander(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator Expander(RemoteWebElement element) - { - return new Expander(element as WindowsElement); - } - /// /// Expands the content of the expander. /// @@ -86,12 +54,12 @@ public static implicit operator Expander(RemoteWebElement element) /// Thrown when an element is no longer valid in the document DOM. public virtual void Expand() { - if (this.IsExpanded) + if (IsExpanded) { return; } - this.ToggleButton.Click(); + ToggleButton.Click(); } /// @@ -103,11 +71,11 @@ public virtual void Expand() /// Thrown when an element is no longer valid in the document DOM. public virtual void Collapse() { - if (!this.IsExpanded) + if (!IsExpanded) { return; } - this.ToggleButton.Click(); + ToggleButton.Click(); } -} \ No newline at end of file +} diff --git a/src/Legerity.WCT/GlobalUsings.cs b/src/Legerity.WCT/GlobalUsings.cs new file mode 100644 index 00000000..cb00424d --- /dev/null +++ b/src/Legerity.WCT/GlobalUsings.cs @@ -0,0 +1,3 @@ +// Global using directives + +global using OpenQA.Selenium; diff --git a/src/Legerity.WCT/InAppNotification.cs b/src/Legerity.WCT/InAppNotification.cs index e57eb252..c1c54ffe 100644 --- a/src/Legerity.WCT/InAppNotification.cs +++ b/src/Legerity.WCT/InAppNotification.cs @@ -1,14 +1,11 @@ namespace Legerity.Windows.Elements.WCT; using System.Linq; -using Legerity.Windows.Elements.Core; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; +using Extensions; +using Core; /// -/// Defines a wrapper for the Windows Community Toolkit InAppNotification control. +/// Defines a wrapper for the Windows Community Toolkit InAppNotification control. /// public class InAppNotification : WindowsElementWrapper { @@ -16,9 +13,9 @@ public class InAppNotification : WindowsElementWrapper /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public InAppNotification(WindowsElement element) + public InAppNotification(WebElement element) : base(element) { } @@ -27,7 +24,7 @@ public InAppNotification(WindowsElement element) /// Gets the dismiss button. /// /// Thrown when no element matches the expected locator. - public virtual Button DismissButton => this.FindElement(WindowsByExtras.AutomationId("PART_DismissButton")); + public virtual Button DismissButton => FindElement(WindowsByExtras.AutomationId("PART_DismissButton")); /// /// Gets the message displayed. @@ -36,50 +33,22 @@ public InAppNotification(WindowsElement element) /// /// /// Thrown when an element is no longer valid in the document DOM. - public virtual string Message => this.Element.FindElementsByClassName("TextBlock").FirstOrDefault()?.Text; + public virtual string Message => Element.FindElementsByClassName("TextBlock").FirstOrDefault()?.Text; /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator InAppNotification(WindowsElement element) + public static implicit operator InAppNotification(WebElement element) { return new InAppNotification(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator InAppNotification(AppiumWebElement element) - { - return new InAppNotification(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator InAppNotification(RemoteWebElement element) - { - return new InAppNotification(element as WindowsElement); - } - + /// /// Dismissed the in-app notification. /// @@ -89,6 +58,6 @@ public static implicit operator InAppNotification(RemoteWebElement element) /// Thrown when an element is no longer valid in the document DOM. public virtual void Dismiss() { - this.DismissButton.Click(); + DismissButton.Click(); } -} \ No newline at end of file +} diff --git a/src/Legerity.WCT/Legerity.WCT.csproj b/src/Legerity.WCT/Legerity.WCT.csproj index 7c194588..1f6e1d09 100644 --- a/src/Legerity.WCT/Legerity.WCT.csproj +++ b/src/Legerity.WCT/Legerity.WCT.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + net6.0;net7.0;net8.0 true Legerity for Windows Community Toolkit - Framework for UI tests with Selenium/Appium @@ -15,7 +15,7 @@ - + diff --git a/src/Legerity.WCT/RadialGauge.cs b/src/Legerity.WCT/RadialGauge.cs index 2dcf9db5..e1668045 100644 --- a/src/Legerity.WCT/RadialGauge.cs +++ b/src/Legerity.WCT/RadialGauge.cs @@ -1,14 +1,10 @@ namespace Legerity.Windows.Elements.WCT; using System; -using Legerity.Windows.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; +using Extensions; /// -/// Defines a wrapper for the Windows Community Toolkit RadialGauge control. +/// Defines a wrapper for the Windows Community Toolkit RadialGauge control. /// public class RadialGauge : WindowsElementWrapper { @@ -16,9 +12,9 @@ public class RadialGauge : WindowsElementWrapper /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public RadialGauge(WindowsElement element) + public RadialGauge(WebElement element) : base(element) { } @@ -54,47 +50,19 @@ public RadialGauge(WindowsElement element) public virtual bool IsReadonly => this.IsRangeReadonly(); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator RadialGauge(WindowsElement element) + public static implicit operator RadialGauge(WebElement element) { return new RadialGauge(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator RadialGauge(AppiumWebElement element) - { - return new RadialGauge(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator RadialGauge(RemoteWebElement element) - { - return new RadialGauge(element as WindowsElement); - } - + /// /// Sets the value of the gauge. /// @@ -109,10 +77,10 @@ public static implicit operator RadialGauge(RemoteWebElement element) /// Thrown when an element is no longer valid in the document DOM. public virtual void SetValue(double value) { - double min = this.Minimum; - double max = this.Maximum; + var min = Minimum; + var max = Maximum; - if (value < this.Minimum) + if (value < Minimum) { throw new ArgumentOutOfRangeException( nameof(value), @@ -120,7 +88,7 @@ public virtual void SetValue(double value) $"Value must be greater than or equal to the minimum value {min}"); } - if (value > this.Maximum) + if (value > Maximum) { throw new ArgumentOutOfRangeException( nameof(value), @@ -128,13 +96,13 @@ public virtual void SetValue(double value) $"Value must be less than or equal to the maximum value {max}"); } - this.Click(); + Click(); - double currentValue = this.Value; + var currentValue = Value; while (Math.Abs(currentValue - value) > double.Epsilon) { - this.Element.SendKeys(currentValue < value ? Keys.ArrowRight : Keys.ArrowLeft); - currentValue = this.Value; + Element.SendKeys(currentValue < value ? Keys.ArrowRight : Keys.ArrowLeft); + currentValue = Value; } } -} \ No newline at end of file +} diff --git a/src/Legerity.Web.Authentication/GlobalUsings.cs b/src/Legerity.Web.Authentication/GlobalUsings.cs new file mode 100644 index 00000000..cb00424d --- /dev/null +++ b/src/Legerity.Web.Authentication/GlobalUsings.cs @@ -0,0 +1,3 @@ +// Global using directives + +global using OpenQA.Selenium; diff --git a/src/Legerity.Web.Authentication/Legerity.Web.Authentication.csproj b/src/Legerity.Web.Authentication/Legerity.Web.Authentication.csproj index 6419ba18..68e466c3 100644 --- a/src/Legerity.Web.Authentication/Legerity.Web.Authentication.csproj +++ b/src/Legerity.Web.Authentication/Legerity.Web.Authentication.csproj @@ -1,17 +1,17 @@ - netstandard2.0 + net6.0;net7.0;net8.0 true Legerity for Web Authentication - Framework for UI testing with Selenium/Appium An extension to the Legerity UI testing framework to support authenticating with common web identity providers. - UI Test AzureAD Facebook Google Appium Selenium ChromeDriver FirefoxDriver OperaDriver SafariDriver EdgeDriver InternetExplorerDriver RemoteWebDriver Web + UI Test AzureAD Facebook Google Appium Selenium ChromeDriver FirefoxDriver OperaDriver SafariDriver EdgeDriver InternetExplorerDriver WebDriver Web - + diff --git a/src/Legerity.Web.Authentication/Pages/AzureAdLoginPage.cs b/src/Legerity.Web.Authentication/Pages/AzureAdLoginPage.cs index 811640cc..89b5672c 100644 --- a/src/Legerity.Web.Authentication/Pages/AzureAdLoginPage.cs +++ b/src/Legerity.Web.Authentication/Pages/AzureAdLoginPage.cs @@ -4,9 +4,7 @@ namespace Legerity.Web.Authentication.Pages; using Exceptions; using Legerity.Extensions; using Legerity.Pages; -using Legerity.Web.Elements.Core; -using OpenQA.Selenium; -using OpenQA.Selenium.Remote; +using Elements.Core; /// /// Defines a page object for the Azure Active Directory login page. @@ -29,7 +27,7 @@ public AzureAdLoginPage() } /// - /// Initializes a new instance of the class using a instance that verifies the page has loaded within 2 seconds. + /// Initializes a new instance of the class using a instance that verifies the page has loaded within 2 seconds. /// /// /// The instance of the started application driver that will be used to drive the page interaction. @@ -37,7 +35,7 @@ public AzureAdLoginPage() /// Thrown when AppManager.StartApp() has not been called. /// Thrown when the page is not shown in 2 seconds. /// Thrown when no element matches the expected locator. - public AzureAdLoginPage(RemoteWebDriver app) + public AzureAdLoginPage(WebDriver app) : base(app) { } @@ -57,7 +55,7 @@ public AzureAdLoginPage(TimeSpan? traitTimeout) } /// - /// Initializes a new instance of the class using a instance that verifies the page has loaded within the given timeout. + /// Initializes a new instance of the class using a instance that verifies the page has loaded within the given timeout. /// /// /// The instance of the started application driver that will be used to drive the page interaction. @@ -68,7 +66,7 @@ public AzureAdLoginPage(TimeSpan? traitTimeout) /// Thrown when AppManager.StartApp() has not been called. /// Thrown when the page is not shown in the given timeout. /// Thrown when no element matches the expected locator. - public AzureAdLoginPage(RemoteWebDriver app, TimeSpan? traitTimeout) + public AzureAdLoginPage(WebDriver app, TimeSpan? traitTimeout) : base(app, traitTimeout) { } @@ -77,25 +75,25 @@ public AzureAdLoginPage(RemoteWebDriver app, TimeSpan? traitTimeout) /// Gets the input element for providing an email address. /// /// Thrown when no element matches the expected locator. - public virtual TextInput EmailInput => this.FindElement(WebByExtras.InputType("email")); + public virtual TextInput EmailInput => FindElement(WebByExtras.InputType("email")); /// /// Gets the input element for providing a password. /// /// Thrown when no element matches the expected locator. - public virtual TextInput PasswordInput => this.FindElement(WebByExtras.InputType("password")); + public virtual TextInput PasswordInput => FindElement(WebByExtras.InputType("password")); /// /// Gets the button element for continuing the sign-in flow through the Azure AD login UI. /// /// Thrown when no element matches the expected locator. - public virtual Button SignInButton => this.FindElement(By.Id("idSIButton9")); + public virtual Button SignInButton => FindElement(By.Id("idSIButton9")); /// /// Gets the optional "Use Password" button that appears when password-less authentication is enabled. /// /// Thrown when no element matches the expected locator. - public virtual Button UsePasswordButton => this.FindElement(By.Id("idA_PWD_SwitchToPassword")); + public virtual Button UsePasswordButton => FindElement(By.Id("idA_PWD_SwitchToPassword")); /// /// Gets a given trait of the page to verify that the page is in view. @@ -114,31 +112,31 @@ public AzureAdLoginPage(RemoteWebDriver app, TimeSpan? traitTimeout) /// Thrown when an element is not visible. public AzureAdLoginPage Login(string email, string password) { - (bool hasEmailInput, AzureAdLoginPage _) = - this.TryWaitUntil(page => page.EmailInput.IsVisible, this.WaitTimeout); + var (hasEmailInput, _) = + this.TryWaitUntil(page => page.EmailInput.IsVisible, WaitTimeout); if (!hasEmailInput) { // Cannot login as email address input not shown (possibly logged in already?) return this; } - this.EmailInput.SetText(email); + EmailInput.SetText(email); // Azure AD login uses a 2-step process for email and password. - this.SignInButton.Click(); + SignInButton.Click(); // Check to ensure that the user is not authenticating with password-less authentication. - (bool isNotPasswordLogin, AzureAdLoginPage _) = - this.TryWaitUntil(page => page.UsePasswordButton.IsVisible, this.WaitTimeout); + var (isNotPasswordLogin, _) = + this.TryWaitUntil(page => page.UsePasswordButton.IsVisible, WaitTimeout); if (isNotPasswordLogin) { - this.UsePasswordButton.Click(); - this.TryWaitUntil(page => page.PasswordInput.IsVisible, this.WaitTimeout); + UsePasswordButton.Click(); + this.TryWaitUntil(page => page.PasswordInput.IsVisible, WaitTimeout); } - this.PasswordInput.SetText(password); - this.SignInButton.Click(); + PasswordInput.SetText(password); + SignInButton.Click(); return this; } -} \ No newline at end of file +} diff --git a/src/Legerity.Web.Authentication/Pages/FacebookLoginPage.cs b/src/Legerity.Web.Authentication/Pages/FacebookLoginPage.cs index 5f0f6588..3f9d24e4 100644 --- a/src/Legerity.Web.Authentication/Pages/FacebookLoginPage.cs +++ b/src/Legerity.Web.Authentication/Pages/FacebookLoginPage.cs @@ -4,9 +4,7 @@ namespace Legerity.Web.Authentication.Pages; using Exceptions; using Legerity.Extensions; using Legerity.Pages; -using Legerity.Web.Elements.Core; -using OpenQA.Selenium; -using OpenQA.Selenium.Remote; +using Elements.Core; /// /// Defines a page object for the Facebook login page. @@ -29,7 +27,7 @@ public FacebookLoginPage() } /// - /// Initializes a new instance of the class using a instance that verifies the page has loaded within 2 seconds. + /// Initializes a new instance of the class using a instance that verifies the page has loaded within 2 seconds. /// /// /// The instance of the started application driver that will be used to drive the page interaction. @@ -37,7 +35,7 @@ public FacebookLoginPage() /// Thrown when AppManager.StartApp() has not been called. /// Thrown when the page is not shown in 2 seconds. /// Thrown when no element matches the expected locator. - public FacebookLoginPage(RemoteWebDriver app) + public FacebookLoginPage(WebDriver app) : base(app) { } @@ -57,7 +55,7 @@ public FacebookLoginPage(TimeSpan? traitTimeout) } /// - /// Initializes a new instance of the class using a instance that verifies the page has loaded within the given timeout. + /// Initializes a new instance of the class using a instance that verifies the page has loaded within the given timeout. /// /// /// The instance of the started application driver that will be used to drive the page interaction. @@ -68,7 +66,7 @@ public FacebookLoginPage(TimeSpan? traitTimeout) /// Thrown when AppManager.StartApp() has not been called. /// Thrown when the page is not shown in the given timeout. /// Thrown when no element matches the expected locator. - public FacebookLoginPage(RemoteWebDriver app, TimeSpan? traitTimeout) + public FacebookLoginPage(WebDriver app, TimeSpan? traitTimeout) : base(app, traitTimeout) { } @@ -77,19 +75,19 @@ public FacebookLoginPage(RemoteWebDriver app, TimeSpan? traitTimeout) /// Gets the input element for providing an email address. /// /// Thrown when no element matches the expected locator. - public virtual TextInput EmailInput => this.FindElement(By.Id("email")); + public virtual TextInput EmailInput => FindElement(By.Id("email")); /// /// Gets the input element for providing a password. /// /// Thrown when no element matches the expected locator. - public virtual TextInput PasswordInput => this.FindElement(WebByExtras.InputType("password")); + public virtual TextInput PasswordInput => FindElement(WebByExtras.InputType("password")); /// /// Gets the button element for continuing the sign-in flow through the Facebook login UI. /// /// Thrown when no element matches the expected locator. - public virtual Button SignInButton => this.FindElement(By.Id("loginbutton")); + public virtual Button SignInButton => FindElement(By.Id("loginbutton")); /// /// Gets a given trait of the page to verify that the page is in view. @@ -108,17 +106,17 @@ public FacebookLoginPage(RemoteWebDriver app, TimeSpan? traitTimeout) /// Thrown when an element is not visible. public FacebookLoginPage Login(string email, string password) { - (bool hasEmailInput, FacebookLoginPage _) = - this.TryWaitUntil(page => page.EmailInput.IsVisible, this.WaitTimeout); + var (hasEmailInput, _) = + this.TryWaitUntil(page => page.EmailInput.IsVisible, WaitTimeout); if (!hasEmailInput) { // Cannot login as email address input not shown (possibly logged in already?) return this; } - this.EmailInput.SetText(email); - this.PasswordInput.SetText(password); - this.SignInButton.Click(); + EmailInput.SetText(email); + PasswordInput.SetText(password); + SignInButton.Click(); return this; } -} \ No newline at end of file +} diff --git a/src/Legerity.Web.Authentication/Pages/GoogleLoginPage.cs b/src/Legerity.Web.Authentication/Pages/GoogleLoginPage.cs index c307c374..3bc4286e 100644 --- a/src/Legerity.Web.Authentication/Pages/GoogleLoginPage.cs +++ b/src/Legerity.Web.Authentication/Pages/GoogleLoginPage.cs @@ -4,9 +4,7 @@ namespace Legerity.Web.Authentication.Pages; using Exceptions; using Legerity.Extensions; using Legerity.Pages; -using Legerity.Web.Elements.Core; -using OpenQA.Selenium; -using OpenQA.Selenium.Remote; +using Elements.Core; /// /// Defines a page object for the Google login page. @@ -29,7 +27,7 @@ public GoogleLoginPage() } /// - /// Initializes a new instance of the class using a instance that verifies the page has loaded within 2 seconds. + /// Initializes a new instance of the class using a instance that verifies the page has loaded within 2 seconds. /// /// /// The instance of the started application driver that will be used to drive the page interaction. @@ -37,7 +35,7 @@ public GoogleLoginPage() /// Thrown when AppManager.StartApp() has not been called. /// Thrown when the page is not shown in 2 seconds. /// Thrown when no element matches the expected locator. - public GoogleLoginPage(RemoteWebDriver app) + public GoogleLoginPage(WebDriver app) : base(app) { } @@ -57,7 +55,7 @@ public GoogleLoginPage(TimeSpan? traitTimeout) } /// - /// Initializes a new instance of the class using a instance that verifies the page has loaded within the given timeout. + /// Initializes a new instance of the class using a instance that verifies the page has loaded within the given timeout. /// /// /// The instance of the started application driver that will be used to drive the page interaction. @@ -68,7 +66,7 @@ public GoogleLoginPage(TimeSpan? traitTimeout) /// Thrown when AppManager.StartApp() has not been called. /// Thrown when the page is not shown in the given timeout. /// Thrown when no element matches the expected locator. - public GoogleLoginPage(RemoteWebDriver app, TimeSpan? traitTimeout) + public GoogleLoginPage(WebDriver app, TimeSpan? traitTimeout) : base(app, traitTimeout) { } @@ -77,25 +75,25 @@ public GoogleLoginPage(RemoteWebDriver app, TimeSpan? traitTimeout) /// Gets the input element for providing an email address. /// /// Thrown when no element matches the expected locator. - public virtual TextInput EmailInput => this.FindElement(WebByExtras.InputType("email")); + public virtual TextInput EmailInput => FindElement(WebByExtras.InputType("email")); /// /// Gets the input element for providing a password. /// /// Thrown when no element matches the expected locator. - public virtual TextInput PasswordInput => this.FindElement(WebByExtras.InputType("password")); + public virtual TextInput PasswordInput => FindElement(WebByExtras.InputType("password")); /// /// Gets the button element for continuing the sign-in flow through the Google login UI. /// /// Thrown when no element matches the expected locator. - public virtual Button NextButton => this.FindElement(By.Id("identifierNext")); + public virtual Button NextButton => FindElement(By.Id("identifierNext")); /// /// Gets the button element for completing the sign-in flow through the Google login UI. /// /// Thrown when no element matches the expected locator. - public virtual Button SignInButton => this.FindElement(By.Id("passwordNext")); + public virtual Button SignInButton => FindElement(By.Id("passwordNext")); /// /// Gets a given trait of the page to verify that the page is in view. @@ -114,29 +112,29 @@ public GoogleLoginPage(RemoteWebDriver app, TimeSpan? traitTimeout) /// Thrown when an element is not visible. public GoogleLoginPage Login(string email, string password) { - (bool hasEmailInput, GoogleLoginPage _) = - this.TryWaitUntil(page => page.EmailInput.IsVisible, this.WaitTimeout); + var (hasEmailInput, _) = + this.TryWaitUntil(page => page.EmailInput.IsVisible, WaitTimeout); if (!hasEmailInput) { // Cannot login as email address input not shown (possibly logged in already?) return this; } - this.EmailInput.SetText(email); + EmailInput.SetText(email); // Google login uses a 2-step process for email and password. - this.NextButton.Click(); + NextButton.Click(); - (bool isPasswordInputVisible, GoogleLoginPage _) = - this.TryWaitUntil(page => page.PasswordInput.IsVisible, this.WaitTimeout); + var (isPasswordInputVisible, _) = + this.TryWaitUntil(page => page.PasswordInput.IsVisible, WaitTimeout); if (!isPasswordInputVisible) { return this; } - this.PasswordInput.SetText(password); - this.SignInButton.Click(); + PasswordInput.SetText(password); + SignInButton.Click(); return this; } -} \ No newline at end of file +} diff --git a/src/Legerity.Web/Elements/Core/Button.cs b/src/Legerity.Web/Elements/Core/Button.cs index 2fe764e8..b21040e6 100644 --- a/src/Legerity.Web/Elements/Core/Button.cs +++ b/src/Legerity.Web/Elements/Core/Button.cs @@ -1,8 +1,6 @@ namespace Legerity.Web.Elements.Core; -using Legerity.Web.Elements; -using OpenQA.Selenium; -using OpenQA.Selenium.Remote; +using Elements; /// /// Defines a wrapper for the core web Button control. @@ -16,7 +14,7 @@ public class Button : WebElementWrapper /// The reference. /// public Button(IWebElement element) - : this(element as RemoteWebElement) + : this(element as WebElement) { } @@ -24,24 +22,24 @@ public Button(IWebElement element) /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public Button(RemoteWebElement element) + public Button(WebElement element) : base(element) { } /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator Button(RemoteWebElement element) + public static implicit operator Button(WebElement element) { return new Button(element); } -} \ No newline at end of file +} diff --git a/src/Legerity.Web/Elements/Core/CheckBox.cs b/src/Legerity.Web/Elements/Core/CheckBox.cs index 38d1cc6e..59f11517 100644 --- a/src/Legerity.Web/Elements/Core/CheckBox.cs +++ b/src/Legerity.Web/Elements/Core/CheckBox.cs @@ -1,8 +1,6 @@ namespace Legerity.Web.Elements.Core; -using Legerity.Web.Elements; -using OpenQA.Selenium; -using OpenQA.Selenium.Remote; +using Elements; /// /// Defines a wrapper for the core web Input checkbox control. @@ -16,7 +14,7 @@ public class CheckBox : WebElementWrapper /// The reference. /// public CheckBox(IWebElement element) - : this(element as RemoteWebElement) + : this(element as WebElement) { } @@ -24,9 +22,9 @@ public CheckBox(IWebElement element) /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public CheckBox(RemoteWebElement element) + public CheckBox(WebElement element) : base(element) { } @@ -35,18 +33,18 @@ public CheckBox(RemoteWebElement element) /// Gets a value indicating whether the check box is in the checked state. /// /// Thrown when an element is no longer valid in the document DOM. - public virtual bool IsChecked => this.Element.Selected; + public virtual bool IsChecked => Element.Selected; /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator CheckBox(RemoteWebElement element) + public static implicit operator CheckBox(WebElement element) { return new CheckBox(element); } @@ -59,12 +57,12 @@ public static implicit operator CheckBox(RemoteWebElement element) /// Thrown when an element is no longer valid in the document DOM. public virtual void CheckOn() { - if (this.IsChecked) + if (IsChecked) { return; } - this.Click(); + Click(); } /// @@ -75,11 +73,11 @@ public virtual void CheckOn() /// Thrown when an element is no longer valid in the document DOM. public virtual void CheckOff() { - if (!this.IsChecked) + if (!IsChecked) { return; } - this.Click(); + Click(); } -} \ No newline at end of file +} diff --git a/src/Legerity.Web/Elements/Core/DateInput.cs b/src/Legerity.Web/Elements/Core/DateInput.cs index 97675523..ed79f720 100644 --- a/src/Legerity.Web/Elements/Core/DateInput.cs +++ b/src/Legerity.Web/Elements/Core/DateInput.cs @@ -2,9 +2,6 @@ namespace Legerity.Web.Elements.Core; using System; using Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Remote; -using OpenQA.Selenium.Support.Extensions; /// /// Defines a wrapper for the core web Input date control. @@ -18,7 +15,7 @@ public class DateInput : TextInput /// The reference. /// public DateInput(IWebElement element) - : this(element as RemoteWebElement) + : this(element as WebElement) { } @@ -26,9 +23,9 @@ public DateInput(IWebElement element) /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public DateInput(RemoteWebElement element) + public DateInput(WebElement element) : base(element) { } @@ -42,18 +39,18 @@ public DateInput(RemoteWebElement element) /// /// Gets the value of the date picker as a . /// - public virtual DateTime? SelectedDate => this.GetSelectedDate(); + public virtual DateTime? SelectedDate => GetSelectedDate(); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator DateInput(RemoteWebElement element) + public static implicit operator DateInput(WebElement element) { return new DateInput(element); } @@ -65,16 +62,16 @@ public static implicit operator DateInput(RemoteWebElement element) /// Thrown when this instance does not implement . public virtual void SetDate(DateTime date) { - this.ElementDriver.ExecuteJavaScript( + ElementDriver.ExecuteJavaScript( "arguments[0].setAttribute('value', arguments[1])", - this.Element, + Element, date.ToString("yyyy-MM-dd")); } private DateTime? GetSelectedDate() { - string value = this.Value; + var value = Value; return string.IsNullOrEmpty(value) ? default : - DateTime.TryParse(value, out DateTime date) ? date : default(DateTime?); + DateTime.TryParse(value, out var date) ? date : default(DateTime?); } -} \ No newline at end of file +} diff --git a/src/Legerity.Web/Elements/Core/FileInput.cs b/src/Legerity.Web/Elements/Core/FileInput.cs index 8f3dbdd3..95b9343a 100644 --- a/src/Legerity.Web/Elements/Core/FileInput.cs +++ b/src/Legerity.Web/Elements/Core/FileInput.cs @@ -1,9 +1,7 @@ namespace Legerity.Web.Elements.Core; -using Legerity.Web.Elements; -using Legerity.Web.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Remote; +using Elements; +using Extensions; /// /// Defines a wrapper for the core web Input file control. @@ -17,7 +15,7 @@ public class FileInput : WebElementWrapper /// The reference. /// public FileInput(IWebElement element) - : this(element as RemoteWebElement) + : this(element as WebElement) { } @@ -25,9 +23,9 @@ public FileInput(IWebElement element) /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public FileInput(RemoteWebElement element) + public FileInput(WebElement element) : base(element) { } @@ -47,7 +45,7 @@ public FileInput(RemoteWebElement element) /// /// The . /// - public static implicit operator FileInput(RemoteWebElement element) + public static implicit operator FileInput(WebElement element) { return new FileInput(element); } @@ -61,8 +59,8 @@ public static implicit operator FileInput(RemoteWebElement element) /// Thrown when an element is no longer valid in the document DOM. public virtual void SetAbsoluteFilePath(string filePath) { - this.ClearFile(); - this.Element.SendKeys(filePath); + ClearFile(); + Element.SendKeys(filePath); } /// @@ -71,6 +69,6 @@ public virtual void SetAbsoluteFilePath(string filePath) /// Thrown when an element is no longer valid in the document DOM. public virtual void ClearFile() { - this.Element.Clear(); + Element.Clear(); } -} \ No newline at end of file +} diff --git a/src/Legerity.Web/Elements/Core/Form.cs b/src/Legerity.Web/Elements/Core/Form.cs index 10ac7b1c..9d9c9377 100644 --- a/src/Legerity.Web/Elements/Core/Form.cs +++ b/src/Legerity.Web/Elements/Core/Form.cs @@ -1,8 +1,5 @@ namespace Legerity.Web.Elements.Core; -using OpenQA.Selenium; -using OpenQA.Selenium.Remote; - /// /// Defines a wrapper for the core web Form control. /// @@ -23,9 +20,9 @@ public Form(IWebElement element) /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public Form(RemoteWebElement element) + public Form(WebElement element) : base(element) { } @@ -39,8 +36,8 @@ public Form(RemoteWebElement element) /// /// The . /// - public static implicit operator Form(RemoteWebElement element) + public static implicit operator Form(WebElement element) { return new Form(element); } -} \ No newline at end of file +} diff --git a/src/Legerity.Web/Elements/Core/Image.cs b/src/Legerity.Web/Elements/Core/Image.cs index d46344a6..fca274de 100644 --- a/src/Legerity.Web/Elements/Core/Image.cs +++ b/src/Legerity.Web/Elements/Core/Image.cs @@ -1,9 +1,7 @@ namespace Legerity.Web.Elements.Core; using Extensions; -using Legerity.Web.Elements; -using OpenQA.Selenium; -using OpenQA.Selenium.Remote; +using Elements; /// /// Defines a wrapper for the core web Image control. @@ -17,7 +15,7 @@ public class Image : WebElementWrapper /// The reference. /// public Image(IWebElement element) - : this(element as RemoteWebElement) + : this(element as WebElement) { } @@ -25,9 +23,9 @@ public Image(IWebElement element) /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public Image(RemoteWebElement element) + public Image(WebElement element) : base(element) { } @@ -36,13 +34,13 @@ public Image(RemoteWebElement element) /// Gets the source URI of the image. /// /// Thrown when an element is no longer valid in the document DOM. - public virtual string Source => this.GetAttribute("src"); + public virtual string Source => GetAttribute("src"); /// /// Gets the alt text of the image. /// /// Thrown when an element is no longer valid in the document DOM. - public virtual string AltText => this.GetAttribute("alt"); + public virtual string AltText => GetAttribute("alt"); /// /// Gets the width of the image. @@ -65,8 +63,8 @@ public Image(RemoteWebElement element) /// /// The . /// - public static implicit operator Image(RemoteWebElement element) + public static implicit operator Image(WebElement element) { return new Image(element); } -} \ No newline at end of file +} diff --git a/src/Legerity.Web/Elements/Core/List.cs b/src/Legerity.Web/Elements/Core/List.cs index 420ee387..76f2bb2f 100644 --- a/src/Legerity.Web/Elements/Core/List.cs +++ b/src/Legerity.Web/Elements/Core/List.cs @@ -1,9 +1,7 @@ namespace Legerity.Web.Elements.Core; using System.Collections.ObjectModel; -using Legerity.Web.Elements; -using OpenQA.Selenium; -using OpenQA.Selenium.Remote; +using Elements; /// /// Defines a wrapper for the core web ol or ul control. @@ -17,7 +15,7 @@ public class List : WebElementWrapper /// The reference. /// public List(IWebElement element) - : this(element as RemoteWebElement) + : this(element as WebElement) { } @@ -25,9 +23,9 @@ public List(IWebElement element) /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public List(RemoteWebElement element) + public List(WebElement element) : base(element) { } @@ -35,19 +33,19 @@ public List(RemoteWebElement element) /// /// Gets the collection of items associated with the list. /// - public virtual ReadOnlyCollection Items => this.Element.FindElements(WebByExtras.ListItem()); + public virtual ReadOnlyCollection Items => Element.FindElements(WebByExtras.ListItem()); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator List(RemoteWebElement element) + public static implicit operator List(WebElement element) { return new List(element); } -} \ No newline at end of file +} diff --git a/src/Legerity.Web/Elements/Core/NumberInput.cs b/src/Legerity.Web/Elements/Core/NumberInput.cs index 57369b82..e6b8477c 100644 --- a/src/Legerity.Web/Elements/Core/NumberInput.cs +++ b/src/Legerity.Web/Elements/Core/NumberInput.cs @@ -2,8 +2,6 @@ namespace Legerity.Web.Elements.Core; using System; using Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Remote; /// /// Defines a wrapper for the core web Input number control. @@ -17,7 +15,7 @@ public class NumberInput : TextInput /// The reference. /// public NumberInput(IWebElement element) - : this(element as RemoteWebElement) + : this(element as WebElement) { } @@ -25,9 +23,9 @@ public NumberInput(IWebElement element) /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public NumberInput(RemoteWebElement element) + public NumberInput(WebElement element) : base(element) { } @@ -48,18 +46,18 @@ public NumberInput(RemoteWebElement element) /// Gets the value of the NumberBox. /// /// Thrown when an element is no longer valid in the document DOM. - public virtual double Value => double.TryParse(this.Text, out double val) ? val : 0; + public virtual double Value => double.TryParse(Text, out var val) ? val : 0; /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator NumberInput(RemoteWebElement element) + public static implicit operator NumberInput(WebElement element) { return new NumberInput(element); } @@ -78,10 +76,10 @@ public static implicit operator NumberInput(RemoteWebElement element) /// Thrown when an element is not visible. public virtual void SetValue(double value) { - double min = this.Minimum; - double max = this.Maximum; + var min = Minimum; + var max = Maximum; - if (value < this.Minimum) + if (value < Minimum) { throw new ArgumentOutOfRangeException( nameof(value), @@ -89,7 +87,7 @@ public virtual void SetValue(double value) $"Value must be greater than or equal to the minimum value {min}"); } - if (value > this.Maximum) + if (value > Maximum) { throw new ArgumentOutOfRangeException( nameof(value), @@ -97,7 +95,7 @@ public virtual void SetValue(double value) $"Value must be less than or equal to the maximum value {max}"); } - this.SetText(value.ToString()); + SetText(value.ToString()); } /// @@ -108,7 +106,7 @@ public virtual void SetValue(double value) /// Thrown when an element is no longer valid in the document DOM. public virtual void Increment() { - this.Element.SendKeys(Keys.ArrowUp); + Element.SendKeys(Keys.ArrowUp); } /// @@ -119,6 +117,6 @@ public virtual void Increment() /// Thrown when an element is no longer valid in the document DOM. public virtual void Decrement() { - this.Element.SendKeys(Keys.ArrowDown); + Element.SendKeys(Keys.ArrowDown); } -} \ No newline at end of file +} diff --git a/src/Legerity.Web/Elements/Core/Option.cs b/src/Legerity.Web/Elements/Core/Option.cs index c35f31eb..dca945bd 100644 --- a/src/Legerity.Web/Elements/Core/Option.cs +++ b/src/Legerity.Web/Elements/Core/Option.cs @@ -1,9 +1,7 @@ namespace Legerity.Web.Elements.Core; -using Legerity.Web.Elements; -using Legerity.Web.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Remote; +using Elements; +using Extensions; /// /// Defines a wrapper for the core web Option control. @@ -17,7 +15,7 @@ public class Option : WebElementWrapper /// The reference. /// public Option(IWebElement element) - : this(element as RemoteWebElement) + : this(element as WebElement) { } @@ -25,9 +23,9 @@ public Option(IWebElement element) /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public Option(RemoteWebElement element) + public Option(WebElement element) : base(element) { } @@ -42,13 +40,13 @@ public Option(RemoteWebElement element) /// Gets the display value of the option. /// /// Thrown when an element is no longer valid in the document DOM. - public virtual string DisplayValue => this.Element.Text; + public virtual string DisplayValue => Element.Text; /// /// Gets a value indicating whether the option is selected. /// /// Thrown when an element is no longer valid in the document DOM. - public virtual bool IsSelected => this.Element.Selected; + public virtual bool IsSelected => Element.Selected; /// /// Allows conversion of a to the without direct casting. @@ -59,7 +57,7 @@ public Option(RemoteWebElement element) /// /// The . /// - public static implicit operator Option(RemoteWebElement element) + public static implicit operator Option(WebElement element) { return new Option(element); } @@ -72,6 +70,6 @@ public static implicit operator Option(RemoteWebElement element) /// Thrown when an element is not visible. public virtual void Select() { - this.Click(); + Click(); } -} \ No newline at end of file +} diff --git a/src/Legerity.Web/Elements/Core/RadioButton.cs b/src/Legerity.Web/Elements/Core/RadioButton.cs index 0f85cfb5..ab1a733f 100644 --- a/src/Legerity.Web/Elements/Core/RadioButton.cs +++ b/src/Legerity.Web/Elements/Core/RadioButton.cs @@ -1,8 +1,6 @@ namespace Legerity.Web.Elements.Core; -using Legerity.Web.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Remote; +using Extensions; /// /// Defines a wrapper for the core web Input radio control. @@ -16,7 +14,7 @@ public class RadioButton : Button /// The reference. /// public RadioButton(IWebElement element) - : this(element as RemoteWebElement) + : this(element as WebElement) { } @@ -24,9 +22,9 @@ public RadioButton(IWebElement element) /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public RadioButton(RemoteWebElement element) + public RadioButton(WebElement element) : base(element) { } @@ -35,7 +33,7 @@ public RadioButton(RemoteWebElement element) /// Gets a value indicating whether the radio button is selected. /// /// Thrown when an element is no longer valid in the document DOM. - public virtual bool IsSelected => this.Element.Selected; + public virtual bool IsSelected => Element.Selected; /// /// Gets the name of the group for the radio button. @@ -44,16 +42,16 @@ public RadioButton(RemoteWebElement element) public virtual string Group => this.GetName(); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator RadioButton(RemoteWebElement element) + public static implicit operator RadioButton(WebElement element) { return new RadioButton(element); } -} \ No newline at end of file +} diff --git a/src/Legerity.Web/Elements/Core/RangeInput.cs b/src/Legerity.Web/Elements/Core/RangeInput.cs index 5a31a3e8..2f2f96f5 100644 --- a/src/Legerity.Web/Elements/Core/RangeInput.cs +++ b/src/Legerity.Web/Elements/Core/RangeInput.cs @@ -2,8 +2,6 @@ namespace Legerity.Web.Elements.Core; using System; using Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Remote; /// /// Defines a wrapper for the core web Input range control. @@ -17,7 +15,7 @@ public class RangeInput : TextInput /// The reference. /// public RangeInput(IWebElement element) - : this(element as RemoteWebElement) + : this(element as WebElement) { } @@ -25,9 +23,9 @@ public RangeInput(IWebElement element) /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public RangeInput(RemoteWebElement element) + public RangeInput(WebElement element) : base(element) { } @@ -48,18 +46,18 @@ public RangeInput(RemoteWebElement element) /// Gets the value of the range input. /// /// Thrown when an element is no longer valid in the document DOM. - public virtual double Value => double.TryParse(this.Text, out double val) ? val : 0; + public virtual double Value => double.TryParse(Text, out var val) ? val : 0; /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator RangeInput(RemoteWebElement element) + public static implicit operator RangeInput(WebElement element) { return new RangeInput(element); } @@ -78,10 +76,10 @@ public static implicit operator RangeInput(RemoteWebElement element) /// Thrown when an element is no longer valid in the document DOM. public virtual void SetValue(double value) { - double min = this.Minimum; - double max = this.Maximum; + var min = Minimum; + var max = Maximum; - if (value < this.Minimum) + if (value < Minimum) { throw new ArgumentOutOfRangeException( nameof(value), @@ -89,7 +87,7 @@ public virtual void SetValue(double value) $"Value must be greater than or equal to the minimum value {min}"); } - if (value > this.Maximum) + if (value > Maximum) { throw new ArgumentOutOfRangeException( nameof(value), @@ -97,13 +95,13 @@ public virtual void SetValue(double value) $"Value must be less than or equal to the maximum value {max}"); } - this.Click(); + Click(); - double currentValue = this.Value; + var currentValue = Value; while (Math.Abs(currentValue - value) > double.Epsilon) { - this.Element.SendKeys(currentValue < value ? Keys.ArrowRight : Keys.ArrowLeft); - currentValue = this.Value; + Element.SendKeys(currentValue < value ? Keys.ArrowRight : Keys.ArrowLeft); + currentValue = Value; } } @@ -115,7 +113,7 @@ public virtual void SetValue(double value) /// Thrown when an element is no longer valid in the document DOM. public virtual void Increment() { - this.Element.SendKeys(Keys.ArrowUp); + Element.SendKeys(Keys.ArrowUp); } /// @@ -126,6 +124,6 @@ public virtual void Increment() /// Thrown when an element is no longer valid in the document DOM. public virtual void Decrement() { - this.Element.SendKeys(Keys.ArrowDown); + Element.SendKeys(Keys.ArrowDown); } -} \ No newline at end of file +} diff --git a/src/Legerity.Web/Elements/Core/Select.cs b/src/Legerity.Web/Elements/Core/Select.cs index d34a1fb4..877d977f 100644 --- a/src/Legerity.Web/Elements/Core/Select.cs +++ b/src/Legerity.Web/Elements/Core/Select.cs @@ -5,9 +5,7 @@ namespace Legerity.Web.Elements.Core; using System.Globalization; using System.Linq; using Legerity.Extensions; -using Legerity.Web.Elements; -using OpenQA.Selenium; -using OpenQA.Selenium.Remote; +using Elements; /// /// Defines a wrapper for the core web Select control. @@ -21,7 +19,7 @@ public class Select : WebElementWrapper /// The reference. /// public Select(IWebElement element) - : this(element as RemoteWebElement) + : this(element as WebElement) { } @@ -29,9 +27,9 @@ public Select(IWebElement element) /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public Select(RemoteWebElement element) + public Select(WebElement element) : base(element) { } @@ -40,25 +38,25 @@ public Select(RemoteWebElement element) /// Gets a value indicating whether multiple items can be selected. /// /// Thrown when an element is no longer valid in the document DOM. - public virtual bool IsMultiple => this.GetIsMultiple(); + public virtual bool IsMultiple => GetIsMultiple(); /// /// Gets the collection of items associated with the select. /// public virtual IEnumerable /// Thrown when an element is no longer valid in the document DOM. - public virtual int Rows => int.Parse(this.GetAttribute("rows")); + public virtual int Rows => int.Parse(GetAttribute("rows")); /// /// Gets the visible width. /// /// Thrown when an element is no longer valid in the document DOM. - public virtual int Cols => int.Parse(this.GetAttribute("cols")); + public virtual int Cols => int.Parse(GetAttribute("cols")); /// /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator TextArea(RemoteWebElement element) + public static implicit operator TextArea(WebElement element) { return new TextArea(element); } -} \ No newline at end of file +} diff --git a/src/Legerity.Web/Elements/Core/TextInput.cs b/src/Legerity.Web/Elements/Core/TextInput.cs index ec418310..c79025d7 100644 --- a/src/Legerity.Web/Elements/Core/TextInput.cs +++ b/src/Legerity.Web/Elements/Core/TextInput.cs @@ -1,9 +1,7 @@ namespace Legerity.Web.Elements.Core; -using Legerity.Web.Elements; -using Legerity.Web.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Remote; +using Elements; +using Extensions; /// /// Defines a wrapper for the core web Input text control. @@ -17,7 +15,7 @@ public class TextInput : WebElementWrapper /// The reference. /// public TextInput(IWebElement element) - : this(element as RemoteWebElement) + : this(element as WebElement) { } @@ -25,9 +23,9 @@ public TextInput(IWebElement element) /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public TextInput(RemoteWebElement element) + public TextInput(WebElement element) : base(element) { } @@ -47,7 +45,7 @@ public TextInput(RemoteWebElement element) /// /// The . /// - public static implicit operator TextInput(RemoteWebElement element) + public static implicit operator TextInput(WebElement element) { return new TextInput(element); } @@ -61,8 +59,8 @@ public static implicit operator TextInput(RemoteWebElement element) /// Thrown when an element is not visible. public virtual void SetText(string text) { - this.ClearText(); - this.AppendText(text); + ClearText(); + AppendText(text); } /// @@ -74,8 +72,8 @@ public virtual void SetText(string text) /// Thrown when an element is no longer valid in the document DOM. public virtual void AppendText(string text) { - this.Click(); - this.Element.SendKeys(text); + Click(); + Element.SendKeys(text); } /// @@ -86,7 +84,7 @@ public virtual void AppendText(string text) /// Thrown when an element is no longer valid in the document DOM. public virtual void ClearText() { - this.Click(); - this.Element.Clear(); + Click(); + Element.Clear(); } -} \ No newline at end of file +} diff --git a/src/Legerity.Web/Elements/WebElementWrapper.cs b/src/Legerity.Web/Elements/WebElementWrapper.cs index aa68e911..1f28ecb5 100644 --- a/src/Legerity.Web/Elements/WebElementWrapper.cs +++ b/src/Legerity.Web/Elements/WebElementWrapper.cs @@ -2,18 +2,15 @@ namespace Legerity.Web.Elements; using System; using System.Collections.ObjectModel; -using Legerity.Exceptions; +using Exceptions; using Legerity.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Remote; -using OpenQA.Selenium.Support.UI; /// -/// Defines an element wrapper for a . +/// Defines an element wrapper for a . /// -public class WebElementWrapper : IElementWrapper +public class WebElementWrapper : IElementWrapper { - private readonly WeakReference elementReference; + private readonly WeakReference _elementReference; /// /// Initializes a new instance of the class. @@ -22,7 +19,7 @@ public class WebElementWrapper : IElementWrapper /// The reference. /// public WebElementWrapper(IWebElement element) - : this(element as RemoteWebElement) + : this(element as WebElement) { } @@ -30,51 +27,51 @@ public WebElementWrapper(IWebElement element) /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public WebElementWrapper(RemoteWebElement element) + public WebElementWrapper(WebElement element) { - this.elementReference = new WeakReference(element); + _elementReference = new WeakReference(element); } - /// Gets the original reference object. - public RemoteWebElement Element => - this.elementReference is { IsAlive: true } - ? this.elementReference.Target as RemoteWebElement + /// Gets the original reference object. + public WebElement Element => + _elementReference is { IsAlive: true } + ? _elementReference.Target as WebElement : null; /// /// Gets the driver used to find this element. /// - public IWebDriver ElementDriver => this.Element.WrappedDriver; + public IWebDriver ElementDriver => Element.WrappedDriver; /// /// Gets the instance of the driver for the web application. /// - public RemoteWebDriver Driver => this.ElementDriver as RemoteWebDriver; + public WebDriver Driver => ElementDriver as WebDriver; /// /// Gets a value indicating whether the element is enabled. /// /// Thrown when an element is no longer valid in the document DOM. - public virtual bool IsEnabled => this.Element.Enabled; + public virtual bool IsEnabled => Element.Enabled; /// /// Gets a value indicating whether the element is visible. /// /// Thrown when an element is no longer valid in the document DOM. - public virtual bool IsVisible => this.Element.Displayed; + public virtual bool IsVisible => Element.Displayed; /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator WebElementWrapper(RemoteWebElement element) + public static implicit operator WebElementWrapper(WebElement element) { return new WebElementWrapper(element); } @@ -83,21 +80,21 @@ public static implicit operator WebElementWrapper(RemoteWebElement element) /// Finds a child element by the specified locator. /// /// The locator to find a child element by. - /// The . + /// The . /// Thrown when no element matches the expected locator. - public RemoteWebElement FindElement(By locator) + public WebElement FindElement(By locator) { - return this.Element.FindWebElement(locator); + return Element.FindWebElement(locator); } /// /// Finds a collection of child elements by the specified locator. /// /// The locator to find a child element by. - /// The readonly collection of . - public ReadOnlyCollection FindElements(By locator) + /// The readonly collection of . + public ReadOnlyCollection FindElements(By locator) { - return this.Element.FindWebElements(locator); + return Element.FindWebElements(locator); } /// @@ -110,7 +107,7 @@ public void VerifyElementNotShown(By locator) { try { - this.VerifyElementShown(locator); + VerifyElementShown(locator); } catch (ElementNotShownException) { @@ -128,7 +125,7 @@ public void VerifyElementNotShown(By locator) /// Thrown when an element is no longer valid in the document DOM. public virtual void Click() { - this.Element.Click(); + Element.Click(); } /// @@ -139,7 +136,7 @@ public virtual void Click() /// Thrown when an element is no longer valid in the document DOM. public string GetAttribute(string attributeName) { - return this.Element.GetAttribute(attributeName); + return Element.GetAttribute(attributeName); } /// @@ -152,7 +149,7 @@ public string GetAttribute(string attributeName) /// Thrown when no element matches the expected locator. public void VerifyElementShown(By locator) { - this.VerifyElementShown(locator, null); + VerifyElementShown(locator, null); } /// @@ -170,7 +167,7 @@ public void VerifyElementShown(By locator, TimeSpan? timeout) { try { - if (this.Element.FindElement(locator) == null) + if (Element.FindElement(locator) == null) { throw new ElementNotShownException(locator.ToString()); } @@ -182,7 +179,7 @@ public void VerifyElementShown(By locator, TimeSpan? timeout) } else { - var wait = new WebDriverWait(this.Driver, timeout.Value); + var wait = new WebDriverWait(Driver, timeout.Value); wait.Until(driver => driver.FindElement(locator) != null); } } @@ -196,7 +193,7 @@ public void VerifyElementShown(By locator, TimeSpan? timeout) /// Thrown when no elements are shown for the expected locator. public void VerifyElementsShown(By locator) { - this.VerifyElementsShown(locator, null); + VerifyElementsShown(locator, null); } /// @@ -213,15 +210,15 @@ public void VerifyElementsShown(By locator, TimeSpan? timeout) { if (timeout == null) { - if (this.Element.FindElements(locator).Count == 0) + if (Element.FindElements(locator).Count == 0) { throw new ElementsNotShownException(locator.ToString()); } } else { - var wait = new WebDriverWait(this.Driver, timeout.Value); + var wait = new WebDriverWait(Driver, timeout.Value); wait.Until(driver => driver.FindElements(locator).Count != 0); } } -} \ No newline at end of file +} diff --git a/src/Legerity.Web/Extensions/AttributeExtensions.cs b/src/Legerity.Web/Extensions/AttributeExtensions.cs index 7b657e17..a92ff3a0 100644 --- a/src/Legerity.Web/Extensions/AttributeExtensions.cs +++ b/src/Legerity.Web/Extensions/AttributeExtensions.cs @@ -1,8 +1,5 @@ namespace Legerity.Web.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Remote; - /// /// Defines a collection of extensions for retrieving element attributes. /// @@ -23,7 +20,7 @@ public static string GetName(this IWebElement element) /// Retrieves the name attribute from the specified element. /// /// - /// The type of . + /// The type of . /// /// The to retrieve a name from. /// The name of the element. @@ -49,7 +46,7 @@ public static string GetValue(this IWebElement element) /// Retrieves the value attribute from the specified element. /// /// - /// The type of . + /// The type of . /// /// The to retrieve a value from. /// The value of the element. @@ -75,7 +72,7 @@ public static string GetClass(this IWebElement element) /// Retrieves the class attribute from the specified element. /// /// - /// The type of . + /// The type of . /// /// The to retrieve a class from. /// The class of the element. @@ -101,7 +98,7 @@ public static double GetWidth(this IWebElement element) /// Retrieves the width attribute from the specified element. /// /// - /// The type of . + /// The type of . /// /// The to retrieve a width from. /// The width of the element. @@ -127,7 +124,7 @@ public static double GetHeight(this IWebElement element) /// Retrieves the height attribute from the specified element. /// /// - /// The type of . + /// The type of . /// /// The to retrieve a height from. /// The height of the element. @@ -153,7 +150,7 @@ public static double GetMinimum(this IWebElement element) /// Retrieves the minimum attribute from the specified element. /// /// - /// The type of . + /// The type of . /// /// The to retrieve a minimum from. /// The minimum value of the element. @@ -179,7 +176,7 @@ public static double GetMaximum(this IWebElement element) /// Retrieves the maximum attribute from the specified element. /// /// - /// The type of . + /// The type of . /// /// The to retrieve a maximum from. /// The maximum value of the element. @@ -189,4 +186,4 @@ public static double GetMaximum(this IElementWrapper element { return GetMaximum(element.Element); } -} \ No newline at end of file +} diff --git a/src/Legerity.Web/Extensions/IWebElementExtensions.cs b/src/Legerity.Web/Extensions/IWebElementExtensions.cs index b9090159..2bf52af5 100644 --- a/src/Legerity.Web/Extensions/IWebElementExtensions.cs +++ b/src/Legerity.Web/Extensions/IWebElementExtensions.cs @@ -1,8 +1,6 @@ namespace Legerity.Web.Extensions; using System; -using OpenQA.Selenium; -using OpenQA.Selenium.Remote; /// /// Defines a collection of extensions for the class. @@ -24,7 +22,7 @@ public static string GetInnerHtml(this IWebElement element) /// Retrieves the value attribute from the specified element. /// /// - /// The type of . + /// The type of . /// /// The to retrieve the inner HTML from. /// The inner HTML of the element. @@ -52,7 +50,7 @@ public static bool HasClass(this IWebElement element, string className) /// Determines whether the specified has the specified class. /// /// - /// The type of . + /// The type of . /// /// The to check. /// The name of the class the element should have. @@ -64,4 +62,4 @@ public static bool HasClass(this IElementWrapper element, st { return HasClass(element.Element, className); } -} \ No newline at end of file +} diff --git a/src/Legerity.Web/Extensions/WebElementWrapperExtensions.cs b/src/Legerity.Web/Extensions/WebElementWrapperExtensions.cs index 4a57de1b..7f07bf63 100644 --- a/src/Legerity.Web/Extensions/WebElementWrapperExtensions.cs +++ b/src/Legerity.Web/Extensions/WebElementWrapperExtensions.cs @@ -1,9 +1,7 @@ namespace Legerity.Web.Extensions; using System; -using Legerity.Web.Elements; -using OpenQA.Selenium; -using OpenQA.Selenium.Support.UI; +using Elements; /// /// Defines a collection of extensions for objects. @@ -86,4 +84,4 @@ public static TResult WaitUntil( return WaitUntil(element, condition, timeout, retries - 1); } } -} \ No newline at end of file +} diff --git a/src/Legerity.Web/GlobalUsings.cs b/src/Legerity.Web/GlobalUsings.cs new file mode 100644 index 00000000..9bdbe875 --- /dev/null +++ b/src/Legerity.Web/GlobalUsings.cs @@ -0,0 +1,5 @@ +// Global using directives + +global using OpenQA.Selenium; +global using OpenQA.Selenium.Support.Extensions; +global using OpenQA.Selenium.Support.UI; diff --git a/src/Legerity.Web/Legerity.Web.csproj b/src/Legerity.Web/Legerity.Web.csproj index e405f378..3d723382 100644 --- a/src/Legerity.Web/Legerity.Web.csproj +++ b/src/Legerity.Web/Legerity.Web.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + net6.0;net7.0;net8.0 true Legerity for Web - Framework for UI testing with Selenium/Appium @@ -20,11 +20,11 @@ - TextArea, a multi-line text input element - TextInput, a default text input element - UI Test Appium Selenium ChromeDriver FirefoxDriver OperaDriver SafariDriver EdgeDriver InternetExplorerDriver RemoteWebDriver Web + UI Test Appium Selenium ChromeDriver FirefoxDriver OperaDriver SafariDriver EdgeDriver InternetExplorerDriver WebDriver Web - + diff --git a/src/Legerity.Web/WebByExtras.cs b/src/Legerity.Web/WebByExtras.cs index 7b367145..5964cc15 100644 --- a/src/Legerity.Web/WebByExtras.cs +++ b/src/Legerity.Web/WebByExtras.cs @@ -1,7 +1,5 @@ namespace Legerity.Web; -using OpenQA.Selenium; - /// /// Defines a collection of extra locator constraints for . /// @@ -61,4 +59,4 @@ public static By TableDataRow() { return By.XPath("//tr[td]"); } -} \ No newline at end of file +} diff --git a/src/Legerity.WinUI/GlobalUsings.cs b/src/Legerity.WinUI/GlobalUsings.cs new file mode 100644 index 00000000..cb00424d --- /dev/null +++ b/src/Legerity.WinUI/GlobalUsings.cs @@ -0,0 +1,3 @@ +// Global using directives + +global using OpenQA.Selenium; diff --git a/src/Legerity.WinUI/InfoBar.cs b/src/Legerity.WinUI/InfoBar.cs index b5e2a795..357f961b 100644 --- a/src/Legerity.WinUI/InfoBar.cs +++ b/src/Legerity.WinUI/InfoBar.cs @@ -1,13 +1,9 @@ namespace Legerity.Windows.Elements.WinUI; -using Legerity.Windows.Elements.Core; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; +using Core; /// -/// Defines a wrapper for the WinUI InfoBar control. +/// Defines a wrapper for the WinUI InfoBar control. /// public class InfoBar : WindowsElementWrapper { @@ -15,9 +11,9 @@ public class InfoBar : WindowsElementWrapper /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public InfoBar(WindowsElement element) + public InfoBar(WebElement element) : base(element) { } @@ -25,79 +21,51 @@ public InfoBar(WindowsElement element) /// /// Gets the title of the info bar. /// - public virtual string Title => this.TitleTextBlock.Text; + public virtual string Title => TitleTextBlock.Text; /// /// Gets the message of the info bar. /// - public virtual string Message => this.MessageTextBlock.Text; + public virtual string Message => MessageTextBlock.Text; /// /// Gets a value indicating whether the info bar is open. /// /// Thrown when an element is no longer valid in the document DOM. - public virtual bool IsOpen => !bool.Parse(this.GetAttribute("IsOffscreen")); + public virtual bool IsOpen => !bool.Parse(GetAttribute("IsOffscreen")); /// /// Gets the element associated with the title . /// /// Thrown when no element matches the expected locator. - public virtual TextBlock TitleTextBlock => this.FindElement(WindowsByExtras.AutomationId("Title")); + public virtual TextBlock TitleTextBlock => FindElement(WindowsByExtras.AutomationId("Title")); /// /// Gets the element associated with the message . /// /// Thrown when no element matches the expected locator. - public virtual TextBlock MessageTextBlock => this.FindElement(WindowsByExtras.AutomationId("Message")); + public virtual TextBlock MessageTextBlock => FindElement(WindowsByExtras.AutomationId("Message")); /// /// Gets the element associated with the close . /// /// Thrown when no element matches the expected locator. - public virtual Button CloseButton => this.FindElement(WindowsByExtras.AutomationId("CloseButton")); + public virtual Button CloseButton => FindElement(WindowsByExtras.AutomationId("CloseButton")); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator InfoBar(WindowsElement element) + public static implicit operator InfoBar(WebElement element) { return new InfoBar(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator InfoBar(AppiumWebElement element) - { - return new InfoBar(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator InfoBar(RemoteWebElement element) - { - return new InfoBar(element as WindowsElement); - } - + /// /// Closes the info bar. /// @@ -107,6 +75,6 @@ public static implicit operator InfoBar(RemoteWebElement element) /// Thrown when an element is no longer valid in the document DOM. public virtual void Close() { - this.CloseButton.Click(); + CloseButton.Click(); } -} \ No newline at end of file +} diff --git a/src/Legerity.WinUI/Legerity.WinUI.csproj b/src/Legerity.WinUI/Legerity.WinUI.csproj index a2c9aab2..9d7c2b89 100644 --- a/src/Legerity.WinUI/Legerity.WinUI.csproj +++ b/src/Legerity.WinUI/Legerity.WinUI.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + net6.0;net7.0;net8.0 true Legerity for WinUI - Framework for UI tests with Selenium/Appium @@ -18,7 +18,7 @@ - + diff --git a/src/Legerity.WinUI/MenuBar.cs b/src/Legerity.WinUI/MenuBar.cs index 7926efca..147fcb85 100644 --- a/src/Legerity.WinUI/MenuBar.cs +++ b/src/Legerity.WinUI/MenuBar.cs @@ -5,13 +5,9 @@ namespace Legerity.Windows.Elements.WinUI; using System.Globalization; using System.Linq; using Legerity.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; /// -/// Defines a wrapper for the WinUI UWP MenuBar control. +/// Defines a wrapper for the WinUI UWP MenuBar control. /// public class MenuBar : WindowsElementWrapper { @@ -19,9 +15,9 @@ public class MenuBar : WindowsElementWrapper /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public MenuBar(WindowsElement element) + public MenuBar(WebElement element) : base(element) { } @@ -30,51 +26,23 @@ public MenuBar(WindowsElement element) /// Gets the UI components associated with the menu items. /// public virtual IEnumerable MenuItems => - this.Element.FindElements(By.ClassName("Microsoft.UI.Xaml.Controls.MenuBarItem")) - .Select(element => new MenuBarItem(this, element as WindowsElement)); + Element.FindElements(By.ClassName("Microsoft.UI.Xaml.Controls.MenuBarItem")) + .Select(element => new MenuBarItem(this, element as WebElement)); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator MenuBar(WindowsElement element) + public static implicit operator MenuBar(WebElement element) { return new MenuBar(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator MenuBar(AppiumWebElement element) - { - return new MenuBar(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator MenuBar(RemoteWebElement element) - { - return new MenuBar(element as WindowsElement); - } - + /// /// Clicks on a child menu option with the specified item name. /// @@ -90,7 +58,7 @@ public static implicit operator MenuBar(RemoteWebElement element) /// Thrown when an element is no longer valid in the document DOM. public virtual MenuBarItem ClickOption(string name) { - MenuBarItem item = this.MenuItems.FirstOrDefault( + var item = MenuItems.FirstOrDefault( element => element.GetName() .Equals(name, StringComparison.CurrentCultureIgnoreCase)); @@ -118,7 +86,7 @@ public virtual MenuBarItem ClickOption(string name) /// Thrown when an element is no longer valid in the document DOM. public virtual MenuBarItem ClickOptionByPartialName(string name) { - MenuBarItem item = this.MenuItems.FirstOrDefault( + var item = MenuItems.FirstOrDefault( element => element.GetName() .Contains(name, CultureInfo.CurrentCulture, CompareOptions.IgnoreCase)); @@ -130,4 +98,4 @@ public virtual MenuBarItem ClickOptionByPartialName(string name) item.Click(); return item; } -} \ No newline at end of file +} diff --git a/src/Legerity.WinUI/MenuBarItem.cs b/src/Legerity.WinUI/MenuBarItem.cs index 98c3ddda..789e3801 100644 --- a/src/Legerity.WinUI/MenuBarItem.cs +++ b/src/Legerity.WinUI/MenuBarItem.cs @@ -5,26 +5,22 @@ namespace Legerity.Windows.Elements.WinUI; using System.Globalization; using System.Linq; using Legerity.Extensions; -using Legerity.Windows.Elements.Core; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; +using Core; /// -/// Defines a wrapper for the WinUI MenuBarItem control. +/// Defines a wrapper for the WinUI MenuBarItem control. /// public class MenuBarItem : WindowsElementWrapper { - private readonly WeakReference parentMenuBarReference; + private readonly WeakReference _parentMenuBarReference; /// /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public MenuBarItem(WindowsElement element) + public MenuBarItem(WebElement element) : this(null, element) { } @@ -36,79 +32,51 @@ public MenuBarItem(WindowsElement element) /// The parent . /// /// - /// The reference. + /// The reference. /// public MenuBarItem( MenuBar parentMenuBar, - WindowsElement element) + WebElement element) : base(element) { if (parentMenuBar != null) { - this.parentMenuBarReference = new WeakReference(parentMenuBar); + _parentMenuBarReference = new WeakReference(parentMenuBar); } } /// Gets the original parent reference object. public virtual MenuBar ParentMenuBar => - this.parentMenuBarReference is { IsAlive: true } - ? this.parentMenuBarReference.Target as MenuBar + _parentMenuBarReference is { IsAlive: true } + ? _parentMenuBarReference.Target as MenuBar : null; /// /// Gets the UI components associated with the child menu items. /// /// Thrown when no element matches the expected locator. - public virtual IEnumerable ChildMenuItems => this.GetChildMenuItems(); + public virtual IEnumerable ChildMenuItems => GetChildMenuItems(); /// /// Gets the UI components associated with the child menu sub-items. /// /// Thrown when no element matches the expected locator. - public virtual IEnumerable ChildMenuSubItems => this.GetChildMenuSubItems(); + public virtual IEnumerable ChildMenuSubItems => GetChildMenuSubItems(); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator MenuBarItem(WindowsElement element) + public static implicit operator MenuBarItem(WebElement element) { return new MenuBarItem(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator MenuBarItem(AppiumWebElement element) - { - return new MenuBarItem(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator MenuBarItem(RemoteWebElement element) - { - return new MenuBarItem(element as WindowsElement); - } - + /// /// Clicks on a child menu option with the specified item name. /// @@ -124,7 +92,7 @@ public static implicit operator MenuBarItem(RemoteWebElement element) /// Thrown when an element is no longer valid in the document DOM. public virtual MenuFlyoutItem ClickChildOption(string name) { - MenuFlyoutItem item = this.ChildMenuItems.FirstOrDefault( + var item = ChildMenuItems.FirstOrDefault( element => element.GetName() .Equals(name, StringComparison.CurrentCultureIgnoreCase)); @@ -152,7 +120,7 @@ public virtual MenuFlyoutItem ClickChildOption(string name) /// Thrown when an element is not visible. public virtual MenuFlyoutItem ClickChildOptionByPartialName(string name) { - MenuFlyoutItem item = this.ChildMenuItems.FirstOrDefault( + var item = ChildMenuItems.FirstOrDefault( element => element.GetName() .Contains(name, CultureInfo.CurrentCulture, CompareOptions.IgnoreCase)); @@ -176,7 +144,7 @@ public virtual MenuFlyoutItem ClickChildOptionByPartialName(string name) /// Thrown when an element is no longer valid in the document DOM. public virtual MenuFlyoutSubItem ClickChildSubOption(string name) { - MenuFlyoutSubItem item = this.ChildMenuSubItems.FirstOrDefault( + var item = ChildMenuSubItems.FirstOrDefault( element => element.GetName() .Equals(name, StringComparison.CurrentCultureIgnoreCase)); @@ -200,7 +168,7 @@ public virtual MenuFlyoutSubItem ClickChildSubOption(string name) /// Thrown when an element is not visible. public virtual MenuFlyoutSubItem ClickChildSubOptionByPartialName(string name) { - MenuFlyoutSubItem item = this.ChildMenuSubItems.FirstOrDefault( + var item = ChildMenuSubItems.FirstOrDefault( element => element.GetName() .Contains(name, CultureInfo.CurrentCulture, CompareOptions.IgnoreCase)); @@ -216,16 +184,16 @@ public virtual MenuFlyoutSubItem ClickChildSubOptionByPartialName(string name) /// Thrown when no element matches the expected locator. private IEnumerable GetChildMenuItems() { - return this.Driver.FindElement(By.ClassName("MenuFlyout")) + return Driver.FindElement(By.ClassName("MenuFlyout")) .FindElements(By.ClassName(nameof(MenuFlyoutItem))).Select( - element => new MenuFlyoutItem(element as WindowsElement)); + element => new MenuFlyoutItem(element)); } /// Thrown when no element matches the expected locator. private IEnumerable GetChildMenuSubItems() { - return this.Driver.FindElement(By.ClassName("MenuFlyout")) + return Driver.FindElement(By.ClassName("MenuFlyout")) .FindElements(By.ClassName(nameof(MenuFlyoutSubItem))).Select( - element => new MenuFlyoutSubItem(element as WindowsElement)); + element => new MenuFlyoutSubItem(element)); } -} \ No newline at end of file +} diff --git a/src/Legerity.WinUI/NavigationView.cs b/src/Legerity.WinUI/NavigationView.cs index 653fb48a..79ed4725 100644 --- a/src/Legerity.WinUI/NavigationView.cs +++ b/src/Legerity.WinUI/NavigationView.cs @@ -6,14 +6,10 @@ namespace Legerity.Windows.Elements.WinUI; using System.Linq; using Extensions; using Legerity.Extensions; -using Legerity.Windows.Elements.Core; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; +using Core; /// -/// Defines a wrapper for the WinUI NavigationView control. +/// Defines a wrapper for the WinUI NavigationView control. /// public class NavigationView : WindowsElementWrapper { @@ -21,9 +17,9 @@ public class NavigationView : WindowsElementWrapper /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public NavigationView(WindowsElement element) + public NavigationView(WebElement element) : base(element) { } @@ -32,16 +28,16 @@ public NavigationView(WindowsElement element) /// Gets the UI component associated with displaying the menu items. /// /// Thrown when no element matches the expected locator. - public virtual AppiumWebElement MenuItemsView => - this.FindElement(WindowsByExtras.AutomationId("MenuItemsHost")); + public virtual WebElement MenuItemsView => + FindElement(WindowsByExtras.AutomationId("MenuItemsHost")); /// /// Gets the UI components associated with the menu items. /// /// Thrown when no element matches the expected locator. public virtual IEnumerable MenuItems => - this.MenuItemsView.FindElements(By.ClassName("Microsoft.UI.Xaml.Controls.NavigationViewItem")) - .Select(element => new NavigationViewItem(this, element as WindowsElement)); + MenuItemsView.FindElements(By.ClassName("Microsoft.UI.Xaml.Controls.NavigationViewItem")) + .Select(element => new NavigationViewItem(this, element as WebElement)); /// /// Gets the currently selected menu item. @@ -49,34 +45,34 @@ public NavigationView(WindowsElement element) /// Thrown when no element matches the expected locator. /// Thrown when an element is no longer valid in the document DOM. public virtual NavigationViewItem SelectedMenuItem => - this.MenuItems.FirstOrDefault(item => item.IsSelected()); + MenuItems.FirstOrDefault(item => item.IsSelected()); /// /// Gets the UI component associated with the settings menu item. /// /// Thrown when no element matches the expected locator. - public virtual AppiumWebElement SettingsMenuItem => - this.FindElement(WindowsByExtras.AutomationId("SettingsItem")); + public virtual WebElement SettingsMenuItem => + FindElement(WindowsByExtras.AutomationId("SettingsItem")); /// /// Gets the UI component associated with the navigation pane toggle button. /// /// Thrown when no element matches the expected locator. public virtual Button ToggleNavigationPaneButton => - this.FindElement(WindowsByExtras.AutomationId("TogglePaneButton")); + FindElement(WindowsByExtras.AutomationId("TogglePaneButton")); /// /// Gets the UI component associated with the navigation back button. /// /// Thrown when no element matches the expected locator. public virtual Button BackButton => - this.FindElement(WindowsByExtras.AutomationId("NavigationViewBackButton")); + FindElement(WindowsByExtras.AutomationId("NavigationViewBackButton")); /// /// Gets a value indicating whether the pane is currently open. /// /// Thrown when no element matches the expected locator. - public virtual bool IsPaneOpen => this.VerifyPaneOpen(this.ExpectedCompactPaneWidth); + public virtual bool IsPaneOpen => VerifyPaneOpen(ExpectedCompactPaneWidth); /// /// Gets or sets the expected compact pane width used to determine the pane open state. @@ -84,47 +80,19 @@ public NavigationView(WindowsElement element) public virtual int ExpectedCompactPaneWidth { get; set; } = 72; /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator NavigationView(WindowsElement element) + public static implicit operator NavigationView(WebElement element) { return new NavigationView(element); } - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator NavigationView(AppiumWebElement element) - { - return new NavigationView(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator NavigationView(RemoteWebElement element) - { - return new NavigationView(element as WindowsElement); - } - /// /// Opens the navigation pane. /// @@ -134,12 +102,12 @@ public static implicit operator NavigationView(RemoteWebElement element) /// Thrown when an element is no longer valid in the document DOM. public virtual void OpenNavigationPane() { - if (this.IsPaneOpen) + if (IsPaneOpen) { return; } - this.ToggleNavigationPaneButton.Click(); + ToggleNavigationPaneButton.Click(); } /// @@ -151,12 +119,12 @@ public virtual void OpenNavigationPane() /// Thrown when an element is no longer valid in the document DOM. public virtual void CloseNavigationPane() { - if (!this.IsPaneOpen) + if (!IsPaneOpen) { return; } - this.ToggleNavigationPaneButton.Click(); + ToggleNavigationPaneButton.Click(); } /// @@ -168,9 +136,9 @@ public virtual void CloseNavigationPane() /// Thrown when an element is no longer valid in the document DOM. public virtual void GoBack() { - if (this.BackButton.IsEnabled) + if (BackButton.IsEnabled) { - this.BackButton.Click(); + BackButton.Click(); } } @@ -189,7 +157,7 @@ public virtual void GoBack() /// Thrown when an element is no longer valid in the document DOM. public virtual NavigationViewItem ClickMenuOption(string name) { - NavigationViewItem item = this.MenuItems.FirstOrDefault( + var item = MenuItems.FirstOrDefault( element => element.GetName().Equals(name, StringComparison.CurrentCultureIgnoreCase)); if (item == null) @@ -216,7 +184,7 @@ public virtual NavigationViewItem ClickMenuOption(string name) /// Thrown when an element is not visible. public virtual NavigationViewItem ClickMenuOptionByPartialName(string name) { - NavigationViewItem item = this.MenuItems.FirstOrDefault( + var item = MenuItems.FirstOrDefault( element => element.GetName().Contains(name, CultureInfo.CurrentCulture, CompareOptions.IgnoreCase)); if (item == null) @@ -237,7 +205,7 @@ public virtual NavigationViewItem ClickMenuOptionByPartialName(string name) /// Thrown when an element is no longer valid in the document DOM. public virtual void OpenSettings() { - this.SettingsMenuItem.Click(); + SettingsMenuItem.Click(); } /// @@ -246,10 +214,11 @@ public virtual void OpenSettings() /// The expected compact pane width when closed. /// True if the pane is open; otherwise, false. /// Thrown when no element matches the expected locator. + /// Thrown when an element is no longer valid in the document DOM. public virtual bool VerifyPaneOpen(int expectedCompactPaneWidth) { - AppiumWebElement pane = this.FindElement(WindowsByExtras.AutomationId("PaneRoot")); - int paneWidth = pane.Rect.Width; + var pane = FindElement(WindowsByExtras.AutomationId("PaneRoot")); + var paneWidth = pane.GetBoundingRect().Width; return paneWidth > expectedCompactPaneWidth; } -} \ No newline at end of file +} diff --git a/src/Legerity.WinUI/NavigationViewItem.cs b/src/Legerity.WinUI/NavigationViewItem.cs index 57480032..427c0cb8 100644 --- a/src/Legerity.WinUI/NavigationViewItem.cs +++ b/src/Legerity.WinUI/NavigationViewItem.cs @@ -5,29 +5,25 @@ namespace Legerity.Windows.Elements.WinUI; using System.Globalization; using System.Linq; using Legerity.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; /// -/// Defines a wrapper for the WinUI NavigationViewItem control. +/// Defines a wrapper for the WinUI NavigationViewItem control. /// public class NavigationViewItem : WindowsElementWrapper { - private readonly By navigationViewItemLocator = By.ClassName("Microsoft.UI.Xaml.Controls.NavigationViewItem"); + private readonly By _navigationViewItemLocator = By.ClassName("Microsoft.UI.Xaml.Controls.NavigationViewItem"); - private readonly WeakReference parentNavigationViewReference; + private readonly WeakReference _parentNavigationViewReference; - private readonly WeakReference parentItemReference; + private readonly WeakReference _parentItemReference; /// /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public NavigationViewItem(WindowsElement element) + public NavigationViewItem(WebElement element) : this(null, null, element) { } @@ -39,9 +35,9 @@ public NavigationViewItem(WindowsElement element) /// The parent . /// /// - /// The reference. + /// The reference. /// - public NavigationViewItem(NavigationView parentNavigationView, WindowsElement element) + public NavigationViewItem(NavigationView parentNavigationView, WebElement element) : this(parentNavigationView, null, element) { } @@ -53,9 +49,9 @@ public NavigationViewItem(NavigationView parentNavigationView, WindowsElement el /// The parent . /// /// - /// The reference. + /// The reference. /// - public NavigationViewItem(NavigationViewItem parentItem, WindowsElement element) + public NavigationViewItem(NavigationViewItem parentItem, WebElement element) : this(null, parentItem, element) { } @@ -70,85 +66,57 @@ public NavigationViewItem(NavigationViewItem parentItem, WindowsElement element) /// The parent . /// /// - /// The reference. + /// The reference. /// public NavigationViewItem( NavigationView parentNavigationView, NavigationViewItem parentItem, - WindowsElement element) + WebElement element) : base(element) { if (parentNavigationView != null) { - this.parentNavigationViewReference = new WeakReference(parentNavigationView); + _parentNavigationViewReference = new WeakReference(parentNavigationView); } if (parentItem != null) { - this.parentItemReference = new WeakReference(parentItem); + _parentItemReference = new WeakReference(parentItem); } } /// Gets the original parent reference object. public NavigationView ParentNavigationView => - this.parentNavigationViewReference is { IsAlive: true } - ? this.parentNavigationViewReference.Target as NavigationView + _parentNavigationViewReference is { IsAlive: true } + ? _parentNavigationViewReference.Target as NavigationView : null; /// Gets the original parent reference object. public NavigationViewItem ParentItem => - this.parentItemReference is { IsAlive: true } - ? this.parentItemReference.Target as NavigationViewItem + _parentItemReference is { IsAlive: true } + ? _parentItemReference.Target as NavigationViewItem : null; /// /// Gets the UI components associated with the child menu items. /// /// Thrown when no element matches the expected locator. - public virtual IEnumerable ChildMenuItems => this.GetChildMenuItems(); + public virtual IEnumerable ChildMenuItems => GetChildMenuItems(); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator NavigationViewItem(WindowsElement element) + public static implicit operator NavigationViewItem(WebElement element) { return new NavigationViewItem(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator NavigationViewItem(AppiumWebElement element) - { - return new NavigationViewItem(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator NavigationViewItem(RemoteWebElement element) - { - return new NavigationViewItem(element as WindowsElement); - } - + /// /// Clicks on a child menu option with the specified item name. /// @@ -164,7 +132,7 @@ public static implicit operator NavigationViewItem(RemoteWebElement element) /// Thrown when an element is no longer valid in the document DOM. public virtual NavigationViewItem ClickChildOption(string name) { - NavigationViewItem item = this.ChildMenuItems.FirstOrDefault( + var item = ChildMenuItems.FirstOrDefault( element => element.GetName() .Equals(name, StringComparison.CurrentCultureIgnoreCase)); @@ -192,7 +160,7 @@ public virtual NavigationViewItem ClickChildOption(string name) /// Thrown when an element is no longer valid in the document DOM. public virtual NavigationViewItem ClickChildOptionByPartialName(string name) { - NavigationViewItem item = this.ChildMenuItems.FirstOrDefault( + var item = ChildMenuItems.FirstOrDefault( element => element.GetName() .Contains(name, CultureInfo.CurrentCulture, CompareOptions.IgnoreCase)); @@ -208,14 +176,14 @@ public virtual NavigationViewItem ClickChildOptionByPartialName(string name) /// Thrown when no element matches the expected locator. private IEnumerable GetChildMenuItems() { - if (this.ParentNavigationView == null || this.ParentNavigationView.IsPaneOpen) + if (ParentNavigationView == null || ParentNavigationView.IsPaneOpen) { - return this.Element.FindElements(this.navigationViewItemLocator).Select( - element => new NavigationViewItem(this.ParentNavigationView, this, element as WindowsElement)); + return Element.FindElements(_navigationViewItemLocator).Select( + element => new NavigationViewItem(ParentNavigationView, this, element as WebElement)); } - return this.Driver.FindElement(WindowsByExtras.AutomationId("ChildrenFlyout")) - .FindElements(this.navigationViewItemLocator).Select( - element => new NavigationViewItem(this.ParentNavigationView, this, element as WindowsElement)); + return Driver.FindElement(WindowsByExtras.AutomationId("ChildrenFlyout")) + .FindElements(_navigationViewItemLocator).Select( + element => new NavigationViewItem(ParentNavigationView, this, element)); } -} \ No newline at end of file +} diff --git a/src/Legerity.WinUI/NumberBox.cs b/src/Legerity.WinUI/NumberBox.cs index 4e440dcd..6a8bf68c 100644 --- a/src/Legerity.WinUI/NumberBox.cs +++ b/src/Legerity.WinUI/NumberBox.cs @@ -1,15 +1,11 @@ namespace Legerity.Windows.Elements.WinUI; using System; -using Legerity.Windows.Elements.Core; -using Legerity.Windows.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; +using Core; +using Extensions; /// -/// Defines a wrapper for the WinUI NumberBox control. +/// Defines a wrapper for the WinUI NumberBox control. /// public class NumberBox : WindowsElementWrapper { @@ -17,9 +13,9 @@ public class NumberBox : WindowsElementWrapper /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public NumberBox(WindowsElement element) + public NumberBox(WebElement element) : base(element) { } @@ -58,63 +54,35 @@ public NumberBox(WindowsElement element) /// Gets the element associated with the inline up button. /// /// Thrown when no element matches the expected locator. - public virtual Button InlineUpButton => this.FindElement(WindowsByExtras.AutomationId("UpSpinButton")); + public virtual Button InlineUpButton => FindElement(WindowsByExtras.AutomationId("UpSpinButton")); /// /// Gets the element associated with the inline down button. /// /// Thrown when no element matches the expected locator. public virtual Button InlineDownButton => - this.FindElement(WindowsByExtras.AutomationId("DownSpinButton")); + FindElement(WindowsByExtras.AutomationId("DownSpinButton")); /// /// Gets the element associated with the input text box. /// /// Thrown when no element matches the expected locator. - public virtual TextBox InputBox => this.FindElement(WindowsByExtras.AutomationId("InputBox")); + public virtual TextBox InputBox => FindElement(WindowsByExtras.AutomationId("InputBox")); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator NumberBox(WindowsElement element) + public static implicit operator NumberBox(WebElement element) { return new NumberBox(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator NumberBox(AppiumWebElement element) - { - return new NumberBox(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator NumberBox(RemoteWebElement element) - { - return new NumberBox(element as WindowsElement); - } - + /// /// Sets the value of the NumberBox. /// @@ -130,10 +98,10 @@ public static implicit operator NumberBox(RemoteWebElement element) /// Thrown when an element is not visible. public virtual void SetValue(double value) { - double min = this.Minimum; - double max = this.Maximum; + var min = Minimum; + var max = Maximum; - if (value < this.Minimum) + if (value < Minimum) { throw new ArgumentOutOfRangeException( nameof(value), @@ -141,7 +109,7 @@ public virtual void SetValue(double value) $"Value must be greater than or equal to the minimum value {min}"); } - if (value > this.Maximum) + if (value > Maximum) { throw new ArgumentOutOfRangeException( nameof(value), @@ -149,8 +117,8 @@ public virtual void SetValue(double value) $"Value must be less than or equal to the maximum value {max}"); } - this.InputBox.SetText(value.ToString()); - this.InputBox.Element.SendKeys(Keys.Enter); + InputBox.SetText(value.ToString()); + InputBox.Element.SendKeys(Keys.Enter); } /// @@ -161,7 +129,7 @@ public virtual void SetValue(double value) /// Thrown when an element is not visible. public virtual void Increment() { - this.Element.SendKeys(Keys.ArrowUp); + Element.SendKeys(Keys.ArrowUp); } /// @@ -172,6 +140,6 @@ public virtual void Increment() /// Thrown when an element is no longer valid in the document DOM. public virtual void Decrement() { - this.Element.SendKeys(Keys.ArrowDown); + Element.SendKeys(Keys.ArrowDown); } -} \ No newline at end of file +} diff --git a/src/Legerity.WinUI/RatingControl.cs b/src/Legerity.WinUI/RatingControl.cs index aef3ca8c..fafc2493 100644 --- a/src/Legerity.WinUI/RatingControl.cs +++ b/src/Legerity.WinUI/RatingControl.cs @@ -1,14 +1,10 @@ namespace Legerity.Windows.Elements.WinUI; using System; -using Legerity.Windows.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; +using Extensions; /// -/// Defines a wrapper for the WinUI Rating control. +/// Defines a wrapper for the WinUI Rating control. /// public class RatingControl : WindowsElementWrapper { @@ -16,9 +12,9 @@ public class RatingControl : WindowsElementWrapper /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public RatingControl(WindowsElement element) + public RatingControl(WebElement element) : base(element) { } @@ -48,47 +44,19 @@ public RatingControl(WindowsElement element) public virtual double Maximum => this.GetRangeMaximum(); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator RatingControl(WindowsElement element) + public static implicit operator RatingControl(WebElement element) { return new RatingControl(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator RatingControl(AppiumWebElement element) - { - return new RatingControl(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator RatingControl(RemoteWebElement element) - { - return new RatingControl(element as WindowsElement); - } - + /// /// Sets the value of the slider. /// @@ -103,10 +71,10 @@ public static implicit operator RatingControl(RemoteWebElement element) /// Thrown when an element is not visible. public virtual void SetValue(double value) { - double min = this.Minimum; - double max = this.Maximum; + var min = Minimum; + var max = Maximum; - if (value < this.Minimum) + if (value < Minimum) { throw new ArgumentOutOfRangeException( nameof(value), @@ -114,7 +82,7 @@ public virtual void SetValue(double value) $"Value must be greater than or equal to the minimum value {min}"); } - if (value > this.Maximum) + if (value > Maximum) { throw new ArgumentOutOfRangeException( nameof(value), @@ -122,13 +90,13 @@ public virtual void SetValue(double value) $"Value must be less than or equal to the maximum value {max}"); } - this.Click(); + Click(); - double currentValue = this.Value; + var currentValue = Value; while (Math.Abs(currentValue - value) > double.Epsilon) { - this.Element.SendKeys(currentValue < value ? Keys.ArrowRight : Keys.ArrowLeft); - currentValue = this.Value; + Element.SendKeys(currentValue < value ? Keys.ArrowRight : Keys.ArrowLeft); + currentValue = Value; } } -} \ No newline at end of file +} diff --git a/src/Legerity.WinUI/TabView.cs b/src/Legerity.WinUI/TabView.cs index 9e05f4f9..f0745eb4 100644 --- a/src/Legerity.WinUI/TabView.cs +++ b/src/Legerity.WinUI/TabView.cs @@ -4,27 +4,23 @@ namespace Legerity.Windows.Elements.WinUI; using System.Collections.ObjectModel; using System.Linq; using Legerity.Exceptions; -using Legerity.Windows.Elements.Core; -using Legerity.Windows.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; +using Core; +using Extensions; /// -/// Defines a wrapper for the WinUI TabView control. +/// Defines a wrapper for the WinUI TabView control. /// public class TabView : WindowsElementWrapper { - private readonly By tabListViewLocator = WindowsByExtras.AutomationId("TabListView"); + private readonly By _tabListViewLocator = WindowsByExtras.AutomationId("TabListView"); /// /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public TabView(WindowsElement element) + public TabView(WebElement element) : base(element) { } @@ -33,66 +29,38 @@ public TabView(WindowsElement element) /// Gets the element associated with the add tab button. /// /// Thrown when no element matches the expected locator. - public virtual Button AddTabButton => this.FindElement(WindowsByExtras.AutomationId("AddButton")); + public virtual Button AddTabButton => FindElement(WindowsByExtras.AutomationId("AddButton")); /// /// Gets the collection of items associated with the pivot. /// /// Thrown when no element matches the expected locator. - public virtual ReadOnlyCollection Tabs => this.TabsListView.Items; + public virtual ReadOnlyCollection Tabs => TabsListView.Items; /// /// Gets the element associated with the currently selected item. /// /// Thrown when no element matches the expected locator. /// Thrown when an element is no longer valid in the document DOM. - public virtual AppiumWebElement SelectedItem => this.TabsListView.SelectedItem; + public virtual WebElement SelectedItem => TabsListView.SelectedItem; /// Thrown when no element matches the expected locator. - private ListView TabsListView => this.FindElement(this.tabListViewLocator); + private ListView TabsListView => FindElement(_tabListViewLocator); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator TabView(WindowsElement element) + public static implicit operator TabView(WebElement element) { return new TabView(element); } - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator TabView(AppiumWebElement element) - { - return new TabView(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator TabView(RemoteWebElement element) - { - return new TabView(element as WindowsElement); - } - /// /// Adds a new tab to the tab view. /// @@ -103,8 +71,8 @@ public static implicit operator TabView(RemoteWebElement element) /// Thrown when an element is no longer valid in the document DOM. public virtual void CreateTab() { - this.VerifyElementShown(this.tabListViewLocator, TimeSpan.FromSeconds(2)); - this.AddTabButton.Click(); + VerifyElementShown(_tabListViewLocator, TimeSpan.FromSeconds(2)); + AddTabButton.Click(); } /// @@ -120,8 +88,8 @@ public virtual void CreateTab() /// Thrown when an element is no longer valid in the document DOM. public virtual void SelectTab(string name) { - this.VerifyElementShown(this.tabListViewLocator, TimeSpan.FromSeconds(2)); - AppiumWebElement item = this.Tabs.FirstOrDefault(element => element.VerifyNameOrAutomationIdEquals(name)); + VerifyElementShown(_tabListViewLocator, TimeSpan.FromSeconds(2)); + var item = Tabs.FirstOrDefault(element => element.VerifyNameOrAutomationIdEquals(name)); if (item == null) { @@ -144,8 +112,8 @@ public virtual void SelectTab(string name) /// Thrown when an element is not visible. public virtual void SelectTabByPartialName(string name) { - this.VerifyElementShown(this.tabListViewLocator, TimeSpan.FromSeconds(2)); - AppiumWebElement item = this.Tabs.FirstOrDefault(element => element.VerifyNameOrAutomationIdContains(name)); + VerifyElementShown(_tabListViewLocator, TimeSpan.FromSeconds(2)); + var item = Tabs.FirstOrDefault(element => element.VerifyNameOrAutomationIdContains(name)); if (item == null) { @@ -166,15 +134,15 @@ public virtual void SelectTabByPartialName(string name) /// Thrown when an element is not visible. public virtual void CloseTab(string name) { - this.VerifyElementShown(this.tabListViewLocator, TimeSpan.FromSeconds(2)); - AppiumWebElement item = this.Tabs.FirstOrDefault(element => element.VerifyNameOrAutomationIdEquals(name)); + VerifyElementShown(_tabListViewLocator, TimeSpan.FromSeconds(2)); + var item = Tabs.FirstOrDefault(element => element.VerifyNameOrAutomationIdEquals(name)); if (item == null) { throw new NoSuchElementException($"Unable to locate element by {name}"); } - Button closeButton = item.FindElement(WindowsByExtras.AutomationId("CloseButton")); + Button closeButton = item.FindElement(WindowsByExtras.AutomationId("CloseButton")) as WebElement; closeButton.Click(); } @@ -189,15 +157,15 @@ public virtual void CloseTab(string name) /// Thrown when an element is no longer valid in the document DOM. public virtual void CloseTabByPartialName(string name) { - this.VerifyElementShown(this.tabListViewLocator, TimeSpan.FromSeconds(2)); - AppiumWebElement item = this.Tabs.FirstOrDefault(element => element.VerifyNameOrAutomationIdContains(name)); + VerifyElementShown(_tabListViewLocator, TimeSpan.FromSeconds(2)); + var item = Tabs.FirstOrDefault(element => element.VerifyNameOrAutomationIdContains(name)); if (item == null) { throw new NoSuchElementException($"Unable to locate element by {name}"); } - Button closeButton = item.FindElement(WindowsByExtras.AutomationId("CloseButton")); + Button closeButton = item.FindElement(WindowsByExtras.AutomationId("CloseButton")) as WebElement; closeButton.Click(); } -} \ No newline at end of file +} diff --git a/src/Legerity.Windows/Elements/Core/AppBarButton.cs b/src/Legerity.Windows/Elements/Core/AppBarButton.cs index 6948777e..2c1d02f1 100644 --- a/src/Legerity.Windows/Elements/Core/AppBarButton.cs +++ b/src/Legerity.Windows/Elements/Core/AppBarButton.cs @@ -1,11 +1,7 @@ namespace Legerity.Windows.Elements.Core; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; - /// -/// Defines a wrapper for the core UWP AppBarButton control. +/// Defines a wrapper for the core UWP AppBarButton control. /// public class AppBarButton : Button { @@ -13,52 +9,24 @@ public class AppBarButton : Button /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public AppBarButton(WindowsElement element) + public AppBarButton(WebElement element) : base(element) { } /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator AppBarButton(WindowsElement element) + public static implicit operator AppBarButton(WebElement element) { return new AppBarButton(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator AppBarButton(AppiumWebElement element) - { - return new AppBarButton(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator AppBarButton(RemoteWebElement element) - { - return new AppBarButton(element as WindowsElement); - } -} \ No newline at end of file +} diff --git a/src/Legerity.Windows/Elements/Core/AppBarToggleButton.cs b/src/Legerity.Windows/Elements/Core/AppBarToggleButton.cs index 57ee0a6a..1eff2315 100644 --- a/src/Legerity.Windows/Elements/Core/AppBarToggleButton.cs +++ b/src/Legerity.Windows/Elements/Core/AppBarToggleButton.cs @@ -1,13 +1,9 @@ namespace Legerity.Windows.Elements.Core; -using Legerity.Windows.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; +using Extensions; /// -/// Defines a wrapper for the core UWP AppBarToggleButton control. +/// Defines a wrapper for the core UWP AppBarToggleButton control. /// public class AppBarToggleButton : AppBarButton { @@ -15,9 +11,9 @@ public class AppBarToggleButton : AppBarButton /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public AppBarToggleButton(WindowsElement element) + public AppBarToggleButton(WebElement element) : base(element) { } @@ -29,47 +25,19 @@ public AppBarToggleButton(WindowsElement element) public virtual bool IsOn => this.GetToggleState() == ToggleState.Checked; /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator AppBarToggleButton(WindowsElement element) + public static implicit operator AppBarToggleButton(WebElement element) { return new AppBarToggleButton(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator AppBarToggleButton(AppiumWebElement element) - { - return new AppBarToggleButton(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator AppBarToggleButton(RemoteWebElement element) - { - return new AppBarToggleButton(element as WindowsElement); - } - + /// /// Toggles the button on. /// @@ -78,12 +46,12 @@ public static implicit operator AppBarToggleButton(RemoteWebElement element) /// Thrown when an element is no longer valid in the document DOM. public virtual void ToggleOn() { - if (this.IsOn) + if (IsOn) { return; } - this.Click(); + Click(); } /// @@ -94,11 +62,11 @@ public virtual void ToggleOn() /// Thrown when an element is no longer valid in the document DOM. public virtual void ToggleOff() { - if (!this.IsOn) + if (!IsOn) { return; } - this.Click(); + Click(); } -} \ No newline at end of file +} diff --git a/src/Legerity.Windows/Elements/Core/AutoSuggestBox.cs b/src/Legerity.Windows/Elements/Core/AutoSuggestBox.cs index f8c473ea..754772cb 100644 --- a/src/Legerity.Windows/Elements/Core/AutoSuggestBox.cs +++ b/src/Legerity.Windows/Elements/Core/AutoSuggestBox.cs @@ -2,25 +2,21 @@ namespace Legerity.Windows.Elements.Core; using System; using Legerity.Exceptions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; /// -/// Defines a wrapper for the core UWP AutoSuggestBox control. +/// Defines a wrapper for the core UWP AutoSuggestBox control. /// public class AutoSuggestBox : WindowsElementWrapper { - private readonly By suggestionsPopupLocator = WindowsByExtras.AutomationId("SuggestionsPopup"); + private readonly By _suggestionsPopupLocator = WindowsByExtras.AutomationId("SuggestionsPopup"); /// /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public AutoSuggestBox(WindowsElement element) + public AutoSuggestBox(WebElement element) : base(element) { } @@ -29,68 +25,40 @@ public AutoSuggestBox(WindowsElement element) /// Gets the element associated with the suggestions popup. /// /// Thrown when no element matches the expected locator. - public virtual AppiumWebElement SuggestionsPopup => this.FindElement(this.suggestionsPopupLocator); + public virtual WebElement SuggestionsPopup => FindElement(_suggestionsPopupLocator); /// /// Gets the element associated with the suggestion list when the is shown. /// /// Thrown when no element matches the expected locator. - public virtual ListView SuggestionList => this.SuggestionsPopup.FindElement(WindowsByExtras.AutomationId("SuggestionsList")); + public virtual ListView SuggestionList => SuggestionsPopup.FindElement(WindowsByExtras.AutomationId("SuggestionsList")) as WebElement; /// /// Gets the element associated with the text box. /// /// Thrown when no element matches the expected locator. - public virtual TextBox TextBox => this.FindElement(WindowsByExtras.AutomationId("TextBox")); + public virtual TextBox TextBox => FindElement(WindowsByExtras.AutomationId("TextBox")); /// /// Gets the value of the auto-suggest box. /// /// Thrown when an element is no longer valid in the document DOM. - public virtual string Text => this.TextBox.Text; + public virtual string Text => TextBox.Text; /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator AutoSuggestBox(WindowsElement element) + public static implicit operator AutoSuggestBox(WebElement element) { return new AutoSuggestBox(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator AutoSuggestBox(AppiumWebElement element) - { - return new AutoSuggestBox(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator AutoSuggestBox(RemoteWebElement element) - { - return new AutoSuggestBox(element as WindowsElement); - } - + /// /// Selects a suggestion from the auto-suggest box. /// @@ -103,7 +71,7 @@ public static implicit operator AutoSuggestBox(RemoteWebElement element) /// Thrown when an element is no longer valid in the document DOM. public virtual void SelectSuggestion(string suggestion) { - this.SelectSuggestion(suggestion, suggestion); + SelectSuggestion(suggestion, suggestion); } /// @@ -120,11 +88,11 @@ public virtual void SelectSuggestion(string suggestion) /// Thrown when an element is no longer valid in the document DOM. public virtual void SelectSuggestion(string value, string suggestion, int popupWaitTimeout = 2000) { - this.SetText(value); + SetText(value); - this.VerifyElementShown(this.suggestionsPopupLocator, TimeSpan.FromMilliseconds(popupWaitTimeout)); + VerifyElementShown(_suggestionsPopupLocator, TimeSpan.FromMilliseconds(popupWaitTimeout)); - this.SuggestionList.ClickItem(suggestion); + SuggestionList.ClickItem(suggestion); } /// @@ -141,11 +109,11 @@ public virtual void SelectSuggestion(string value, string suggestion, int popupW /// Thrown when an element is no longer valid in the document DOM. public virtual void SelectSuggestionByPartialSuggestion(string value, string partialSuggestion, int popupWaitTimeout = 2000) { - this.SetText(value); + SetText(value); - this.VerifyElementShown(this.suggestionsPopupLocator, TimeSpan.FromMilliseconds(popupWaitTimeout)); + VerifyElementShown(_suggestionsPopupLocator, TimeSpan.FromMilliseconds(popupWaitTimeout)); - this.SuggestionList.ClickItemByPartialName(partialSuggestion); + SuggestionList.ClickItemByPartialName(partialSuggestion); } /// @@ -158,6 +126,6 @@ public virtual void SelectSuggestionByPartialSuggestion(string value, string par /// Thrown when no element matches the expected locator. public virtual void SetText(string value) { - this.TextBox.SetText(value); + TextBox.SetText(value); } -} \ No newline at end of file +} diff --git a/src/Legerity.Windows/Elements/Core/Button.cs b/src/Legerity.Windows/Elements/Core/Button.cs index 1b3bd748..dde1278b 100644 --- a/src/Legerity.Windows/Elements/Core/Button.cs +++ b/src/Legerity.Windows/Elements/Core/Button.cs @@ -1,11 +1,7 @@ namespace Legerity.Windows.Elements.Core; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; - /// -/// Defines a wrapper for the core UWP Button control. +/// Defines a wrapper for the core UWP Button control. /// public class Button : WindowsElementWrapper { @@ -13,52 +9,24 @@ public class Button : WindowsElementWrapper /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public Button(WindowsElement element) + public Button(WebElement element) : base(element) { } /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator Button(WindowsElement element) + public static implicit operator Button(WebElement element) { return new Button(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator Button(AppiumWebElement element) - { - return new Button(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator Button(RemoteWebElement element) - { - return new Button(element as WindowsElement); - } -} \ No newline at end of file +} diff --git a/src/Legerity.Windows/Elements/Core/CalendarDatePicker.cs b/src/Legerity.Windows/Elements/Core/CalendarDatePicker.cs index 81ab4714..23d32252 100644 --- a/src/Legerity.Windows/Elements/Core/CalendarDatePicker.cs +++ b/src/Legerity.Windows/Elements/Core/CalendarDatePicker.cs @@ -3,26 +3,22 @@ namespace Legerity.Windows.Elements.Core; using System; using Legerity.Exceptions; using Legerity.Extensions; -using Legerity.Windows.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; +using Extensions; /// -/// Defines a wrapper for the core UWP CalendarDatePicker control. +/// Defines a wrapper for the core UWP CalendarDatePicker control. /// public class CalendarDatePicker : WindowsElementWrapper { - private readonly By calendarPopupLocator = By.XPath(".//*[@ClassName='Popup'][@Name='Popup']"); + private readonly By _calendarPopupLocator = By.XPath(".//*[@ClassName='Popup'][@Name='Popup']"); /// /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public CalendarDatePicker(WindowsElement element) + public CalendarDatePicker(WebElement element) : base(element) { } @@ -31,7 +27,7 @@ public CalendarDatePicker(WindowsElement element) /// Gets the element associated with the calendar flyout. /// /// Thrown when no element matches the expected locator. - public virtual CalendarView CalendarViewFlyout => this.Driver.FindElement(this.calendarPopupLocator) + public virtual CalendarView CalendarViewFlyout => Driver.FindElement(_calendarPopupLocator) .FindElement(WindowsByExtras.AutomationId("CalendarView")); /// @@ -43,50 +39,22 @@ public CalendarDatePicker(WindowsElement element) /// /// Gets the value of the calendar date picker as a . /// - public virtual DateTime? SelectedDate => this.GetSelectedDate(); + public virtual DateTime? SelectedDate => GetSelectedDate(); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator CalendarDatePicker(WindowsElement element) + public static implicit operator CalendarDatePicker(WebElement element) { return new CalendarDatePicker(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator CalendarDatePicker(AppiumWebElement element) - { - return new CalendarDatePicker(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator CalendarDatePicker(RemoteWebElement element) - { - return new CalendarDatePicker(element as WindowsElement); - } - + /// /// Sets the selected date of the calendar view. /// @@ -98,17 +66,17 @@ public static implicit operator CalendarDatePicker(RemoteWebElement element) /// Thrown when no element matches the expected locator. public virtual void SetDate(DateTime date) { - this.Click(); + Click(); - this.VerifyDriverElementShown(this.calendarPopupLocator, TimeSpan.FromSeconds(2)); + VerifyDriverElementShown(_calendarPopupLocator, TimeSpan.FromSeconds(2)); - this.CalendarViewFlyout.SetDate(date); + CalendarViewFlyout.SetDate(date); } private DateTime? GetSelectedDate() { - string value = this.Value; + var value = Value; return string.IsNullOrEmpty(value) ? default : - DateTime.TryParse(value, out DateTime date) ? date : default(DateTime?); + DateTime.TryParse(value, out var date) ? date : default(DateTime?); } -} \ No newline at end of file +} diff --git a/src/Legerity.Windows/Elements/Core/CalendarView.cs b/src/Legerity.Windows/Elements/Core/CalendarView.cs index 8d030925..cb33f83c 100644 --- a/src/Legerity.Windows/Elements/Core/CalendarView.cs +++ b/src/Legerity.Windows/Elements/Core/CalendarView.cs @@ -6,18 +6,14 @@ namespace Legerity.Windows.Elements.Core; using System.Linq; using System.Threading; using Legerity.Extensions; -using Legerity.Windows.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; +using Extensions; /// -/// Defines a wrapper for the core UWP CalendarView control. +/// Defines a wrapper for the core UWP CalendarView control. /// public class CalendarView : WindowsElementWrapper { - private readonly Dictionary months = new() + private readonly Dictionary _months = new() { { "January", "01" }, { "February", "02" }, @@ -37,9 +33,9 @@ public class CalendarView : WindowsElementWrapper /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public CalendarView(WindowsElement element) + public CalendarView(WebElement element) : base(element) { } @@ -48,26 +44,26 @@ public CalendarView(WindowsElement element) /// Gets the element associated with the header button (change month, year). /// /// Thrown when no element matches the expected locator. - public virtual Button HeaderButton => this.FindElement(WindowsByExtras.AutomationId("HeaderButton")); + public virtual Button HeaderButton => FindElement(WindowsByExtras.AutomationId("HeaderButton")); /// /// Gets the element associated with the next month button. /// /// Thrown when no element matches the expected locator. - public virtual Button NextMonthButton => this.FindElement(WindowsByExtras.AutomationId("NextButton")); + public virtual Button NextMonthButton => FindElement(WindowsByExtras.AutomationId("NextButton")); /// /// Gets the element associated with the previous month button. /// /// Thrown when no element matches the expected locator. public virtual Button PreviousMonthButton => - this.FindElement(WindowsByExtras.AutomationId("PreviousButton")); + FindElement(WindowsByExtras.AutomationId("PreviousButton")); /// /// Gets the collection of days associated with the current month in the calendar view. /// - public virtual ReadOnlyCollection Days => - this.Element.FindElements(By.ClassName("CalendarViewDayItem")); + public virtual ReadOnlyCollection Days => + Element.FindElements(By.ClassName("CalendarViewDayItem")).Cast().ToList().AsReadOnly(); /// /// Gets the value of the calendar view. @@ -78,50 +74,22 @@ public CalendarView(WindowsElement element) /// /// Gets the value of the calendar view as a . /// - public virtual DateTime? SelectedDate => this.GetSelectedDate(); + public virtual DateTime? SelectedDate => GetSelectedDate(); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator CalendarView(WindowsElement element) + public static implicit operator CalendarView(WebElement element) { return new CalendarView(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator CalendarView(AppiumWebElement element) - { - return new CalendarView(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator CalendarView(RemoteWebElement element) - { - return new CalendarView(element as WindowsElement); - } - + /// /// Sets the selected date of the calendar view. /// @@ -132,29 +100,29 @@ public static implicit operator CalendarView(RemoteWebElement element) /// Thrown when no element matches the expected locator. public void SetDate(DateTime date) { - string expectedDay = date.ToString("%d"); - string expectedHeader = date.ToString("MMMM yyyy"); + var expectedDay = date.ToString("%d"); + var expectedHeader = date.ToString("MMMM yyyy"); - string currentHeader = this.HeaderButton.GetName(); - DateTime currentViewDate = this.GetCurrentViewDate(currentHeader); + var currentHeader = HeaderButton.GetName(); + var currentViewDate = GetCurrentViewDate(currentHeader); while (!expectedHeader.Equals(currentHeader, StringComparison.CurrentCultureIgnoreCase)) { if (currentViewDate.Date > date.Date) { - this.PreviousMonthButton.Click(); + PreviousMonthButton.Click(); } else { - this.NextMonthButton.Click(); + NextMonthButton.Click(); } Thread.Sleep(10); - currentHeader = this.HeaderButton.GetName(); + currentHeader = HeaderButton.GetName(); } - AppiumWebElement item = this.Days.FirstOrDefault( + var item = Days.FirstOrDefault( element => element.GetName().Equals(expectedDay, StringComparison.CurrentCultureIgnoreCase)); if (item == null) @@ -167,20 +135,20 @@ public void SetDate(DateTime date) private DateTime GetCurrentViewDate(string currentHeader) { - this.months.TryGetValue( + _months.TryGetValue( string.Join(string.Empty, currentHeader.Where(char.IsLetter)).Trim(), - out string month); + out var month); - string year = string.Join(string.Empty, currentHeader.Where(char.IsDigit)).Trim(); + var year = string.Join(string.Empty, currentHeader.Where(char.IsDigit)).Trim(); - string dateString = $"01/{month}/{year}"; + var dateString = $"01/{month}/{year}"; return DateTime.ParseExact(dateString, @"d/M/yyyy", System.Globalization.CultureInfo.InvariantCulture); } private DateTime? GetSelectedDate() { - string value = this.Value; + var value = Value; return string.IsNullOrEmpty(value) ? default : - DateTime.TryParse(value, out DateTime date) ? date : default(DateTime?); + DateTime.TryParse(value, out var date) ? date : default(DateTime?); } -} \ No newline at end of file +} diff --git a/src/Legerity.Windows/Elements/Core/CheckBox.cs b/src/Legerity.Windows/Elements/Core/CheckBox.cs index 3e086f6a..cbf11131 100644 --- a/src/Legerity.Windows/Elements/Core/CheckBox.cs +++ b/src/Legerity.Windows/Elements/Core/CheckBox.cs @@ -1,13 +1,9 @@ namespace Legerity.Windows.Elements.Core; -using Legerity.Windows.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; +using Extensions; /// -/// Defines a wrapper for the core UWP CheckBox control. +/// Defines a wrapper for the core UWP CheckBox control. /// public class CheckBox : WindowsElementWrapper { @@ -15,9 +11,9 @@ public class CheckBox : WindowsElementWrapper /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public CheckBox(WindowsElement element) + public CheckBox(WebElement element) : base(element) { } @@ -35,47 +31,19 @@ public CheckBox(WindowsElement element) public virtual bool IsIndeterminate => this.GetToggleState() == ToggleState.Indeterminate; /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator CheckBox(WindowsElement element) + public static implicit operator CheckBox(WebElement element) { return new CheckBox(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator CheckBox(AppiumWebElement element) - { - return new CheckBox(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator CheckBox(RemoteWebElement element) - { - return new CheckBox(element as WindowsElement); - } - + /// /// Checks the check box on. /// @@ -84,12 +52,12 @@ public static implicit operator CheckBox(RemoteWebElement element) /// Thrown when an element is no longer valid in the document DOM. public virtual void CheckOn() { - if (this.IsChecked) + if (IsChecked) { return; } - this.Click(); + Click(); } /// @@ -100,11 +68,11 @@ public virtual void CheckOn() /// Thrown when an element is no longer valid in the document DOM. public virtual void CheckOff() { - if (!this.IsChecked) + if (!IsChecked) { return; } - this.Click(); + Click(); } -} \ No newline at end of file +} diff --git a/src/Legerity.Windows/Elements/Core/ComboBox.cs b/src/Legerity.Windows/Elements/Core/ComboBox.cs index 5b7f2190..069256ab 100644 --- a/src/Legerity.Windows/Elements/Core/ComboBox.cs +++ b/src/Legerity.Windows/Elements/Core/ComboBox.cs @@ -2,30 +2,25 @@ namespace Legerity.Windows.Elements.Core; using System; using System.Collections.Generic; -using System.Collections.ObjectModel; using System.Globalization; using System.Linq; using Legerity.Exceptions; using Legerity.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; /// -/// Defines a wrapper for the core UWP ComboBox control. +/// Defines a wrapper for the core UWP ComboBox control. /// public class ComboBox : WindowsElementWrapper { - private readonly By comboBoxItemLocator = By.ClassName("ComboBoxItem"); + private readonly By _comboBoxItemLocator = By.ClassName("ComboBoxItem"); /// /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public ComboBox(WindowsElement element) + public ComboBox(WebElement element) : base(element) { } @@ -34,50 +29,22 @@ public ComboBox(WindowsElement element) /// Gets the currently selected item. /// /// Thrown when an element is no longer valid in the document DOM. - public virtual string SelectedItem => this.GetSelectedItem(); + public virtual string SelectedItem => GetSelectedItem(); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator ComboBox(WindowsElement element) + public static implicit operator ComboBox(WebElement element) { return new ComboBox(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator ComboBox(AppiumWebElement element) - { - return new ComboBox(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator ComboBox(RemoteWebElement element) - { - return new ComboBox(element as WindowsElement); - } - + /// /// Selects an item in the combo-box with the specified item name. /// @@ -91,9 +58,9 @@ public static implicit operator ComboBox(RemoteWebElement element) /// Thrown when no elements are shown for the expected locator. public virtual void SelectItem(string name) { - IEnumerable listElements = this.GetItemsToSelect(); + var listElements = GetItemsToSelect(); - AppiumWebElement item = listElements.FirstOrDefault( + var item = listElements.FirstOrDefault( element => element.GetName().Equals(name, StringComparison.CurrentCultureIgnoreCase)); if (item == null) @@ -117,9 +84,9 @@ public virtual void SelectItem(string name) /// Thrown when no elements are shown for the expected locator. public virtual void SelectItemByPartialName(string name) { - IEnumerable listElements = this.GetItemsToSelect(); + var listElements = GetItemsToSelect(); - AppiumWebElement item = listElements.FirstOrDefault( + var item = listElements.FirstOrDefault( element => element.GetName().Contains(name, CultureInfo.CurrentCulture, CompareOptions.IgnoreCase)); if (item == null) @@ -133,7 +100,7 @@ public virtual void SelectItemByPartialName(string name) /// Thrown when an element is no longer valid in the document DOM. private string GetSelectedItem() { - ReadOnlyCollection listElements = this.Element.FindElements(this.comboBoxItemLocator); + var listElements = Element.FindElements(_comboBoxItemLocator).Cast().ToList().AsReadOnly(); return listElements.Count == 1 ? listElements.FirstOrDefault().GetName() : null; } @@ -141,11 +108,11 @@ private string GetSelectedItem() /// Thrown when an element is not enabled. /// Thrown when an element is not visible. /// Thrown when an element is no longer valid in the document DOM. - private IEnumerable GetItemsToSelect() + private IEnumerable GetItemsToSelect() { - this.Click(); - this.VerifyElementsShown(this.comboBoxItemLocator, TimeSpan.FromSeconds(2)); - ReadOnlyCollection listElements = this.Element.FindElements(this.comboBoxItemLocator); + Click(); + VerifyElementsShown(_comboBoxItemLocator, TimeSpan.FromSeconds(2)); + var listElements = Element.FindElements(_comboBoxItemLocator).Cast().ToList().AsReadOnly(); return listElements; } -} \ No newline at end of file +} diff --git a/src/Legerity.Windows/Elements/Core/CommandBar.cs b/src/Legerity.Windows/Elements/Core/CommandBar.cs index a9e56657..5f1847f8 100644 --- a/src/Legerity.Windows/Elements/Core/CommandBar.cs +++ b/src/Legerity.Windows/Elements/Core/CommandBar.cs @@ -4,30 +4,26 @@ namespace Legerity.Windows.Elements.Core; using System.Collections.Generic; using System.Linq; using Legerity.Exceptions; -using Legerity.Windows.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; +using Extensions; /// -/// Defines a wrapper for the core UWP CommandBar control. +/// Defines a wrapper for the core UWP CommandBar control. /// public class CommandBar : WindowsElementWrapper { - private readonly By moreButtonLocator = WindowsByExtras.AutomationId("MoreButton"); + private readonly By _moreButtonLocator = WindowsByExtras.AutomationId("MoreButton"); - private readonly By overflowPopupLocator = WindowsByExtras.AutomationId("OverflowPopup"); + private readonly By _overflowPopupLocator = WindowsByExtras.AutomationId("OverflowPopup"); - private readonly By appBarButtonLocator = By.ClassName(nameof(AppBarButton)); + private readonly By _appBarButtonLocator = By.ClassName(nameof(AppBarButton)); /// /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public CommandBar(WindowsElement element) + public CommandBar(WebElement element) : base(element) { } @@ -36,14 +32,14 @@ public CommandBar(WindowsElement element) /// Gets the collection of primary buttons. /// public virtual IEnumerable PrimaryButtons => - this.Element.FindElements(this.appBarButtonLocator) - .Select(element => element); + Element.FindElements(_appBarButtonLocator) + .Select(element => element as WebElement); /// /// Gets the for opening the secondary button menu. /// /// Thrown when no element matches the expected locator. - public virtual AppBarButton SecondaryMenuButton => this.FindElement(this.moreButtonLocator); + public virtual AppBarButton SecondaryMenuButton => FindElement(_moreButtonLocator); /// /// Gets the collection of secondary buttons. @@ -53,51 +49,23 @@ public CommandBar(WindowsElement element) /// /// Thrown when no element matches the expected locator. public virtual IEnumerable SecondaryButtons => - this.Driver.FindElement(this.overflowPopupLocator).FindElements(this.appBarButtonLocator) - .Select(element => element); + Driver.FindElement(_overflowPopupLocator).FindElements(_appBarButtonLocator) + .Select(element => element); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator CommandBar(WindowsElement element) + public static implicit operator CommandBar(WebElement element) { return new CommandBar(element); } - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator CommandBar(AppiumWebElement element) - { - return new CommandBar(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator CommandBar(RemoteWebElement element) - { - return new CommandBar(element as WindowsElement); - } - /// /// Clicks a primary button in the command bar with the specified button name or Automation ID. /// @@ -110,7 +78,7 @@ public static implicit operator CommandBar(RemoteWebElement element) /// Thrown when an element is no longer valid in the document DOM. public virtual void ClickPrimaryButton(string name) { - AppBarButton item = this.PrimaryButtons.FirstOrDefault( + var item = PrimaryButtons.FirstOrDefault( element => element.Element.VerifyNameOrAutomationIdEquals(name)); if (item == null) @@ -133,7 +101,7 @@ public virtual void ClickPrimaryButton(string name) /// Thrown when an element is no longer valid in the document DOM. public virtual void ClickPrimaryButtonByPartialName(string partialName) { - AppBarButton item = this.PrimaryButtons.FirstOrDefault( + var item = PrimaryButtons.FirstOrDefault( element => element.Element.VerifyNameOrAutomationIdContains(partialName)); if (item == null) @@ -157,9 +125,9 @@ public virtual void ClickPrimaryButtonByPartialName(string partialName) /// Thrown when the more button is not shown. public virtual void ClickSecondaryButton(string name) { - this.OpenSecondaryButtonMenu(); + OpenSecondaryButtonMenu(); - AppBarButton secondaryButton = this.SecondaryButtons.FirstOrDefault( + var secondaryButton = SecondaryButtons.FirstOrDefault( button => button.Element.VerifyNameOrAutomationIdEquals(name)); if (secondaryButton == null) @@ -183,9 +151,9 @@ public virtual void ClickSecondaryButton(string name) /// Thrown when the more button is not shown. public virtual void ClickSecondaryButtonByPartialName(string partialName) { - this.OpenSecondaryButtonMenu(); + OpenSecondaryButtonMenu(); - AppBarButton secondaryButton = this.SecondaryButtons.FirstOrDefault( + var secondaryButton = SecondaryButtons.FirstOrDefault( button => button.Element.VerifyNameOrAutomationIdContains(partialName)); if (secondaryButton == null) @@ -206,8 +174,8 @@ public virtual void ClickSecondaryButtonByPartialName(string partialName) /// Thrown when no element matches the expected locator. public virtual void OpenSecondaryButtonMenu() { - this.VerifyElementShown(this.moreButtonLocator, TimeSpan.FromSeconds(2)); - this.SecondaryMenuButton.Click(); - this.VerifyDriverElementShown(this.overflowPopupLocator, TimeSpan.FromSeconds(2)); + VerifyElementShown(_moreButtonLocator, TimeSpan.FromSeconds(2)); + SecondaryMenuButton.Click(); + VerifyDriverElementShown(_overflowPopupLocator, TimeSpan.FromSeconds(2)); } -} \ No newline at end of file +} diff --git a/src/Legerity.Windows/Elements/Core/DatePicker.cs b/src/Legerity.Windows/Elements/Core/DatePicker.cs index 08edfd5f..7e4d9edd 100644 --- a/src/Legerity.Windows/Elements/Core/DatePicker.cs +++ b/src/Legerity.Windows/Elements/Core/DatePicker.cs @@ -2,14 +2,11 @@ namespace Legerity.Windows.Elements.Core; using System; using System.Text.RegularExpressions; +using Extensions; using Legerity.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; /// -/// Defines a wrapper for the core UWP DatePicker control. +/// Defines a wrapper for the core UWP DatePicker control. /// public class DatePicker : WindowsElementWrapper { @@ -17,9 +14,9 @@ public class DatePicker : WindowsElementWrapper /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public DatePicker(WindowsElement element) + public DatePicker(WebElement element) : base(element) { } @@ -29,55 +26,27 @@ public DatePicker(WindowsElement element) /// /// Thrown when no element matches the expected locator. /// Thrown when an element is no longer valid in the document DOM. - public virtual string Value => this.GetValue(); + public virtual string Value => GetValue(); /// /// Gets the value of the date picker as a . /// - public virtual DateTime? SelectedDate => this.GetSelectedDate(); + public virtual DateTime? SelectedDate => GetSelectedDate(); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator DatePicker(WindowsElement element) + public static implicit operator DatePicker(WebElement element) { return new DatePicker(element); } - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator DatePicker(AppiumWebElement element) - { - return new DatePicker(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator DatePicker(RemoteWebElement element) - { - return new DatePicker(element as WindowsElement); - } - /// /// Sets the date to the specified date. /// @@ -88,21 +57,21 @@ public static implicit operator DatePicker(RemoteWebElement element) /// Thrown when no element matches the expected locator. public virtual void SetDate(DateTime date) { - DateTime? selectedDate = this.SelectedDate; + var selectedDate = SelectedDate; if (selectedDate.HasValue && selectedDate.Value.Date == date.Date) { return; } - string selectedDay = selectedDate?.ToString("%d"); - string selectedMonth = selectedDate?.ToString("MMMM"); - string selectedYear = selectedDate?.ToString("yyyy"); + var selectedDay = selectedDate?.ToString("%d"); + var selectedMonth = selectedDate?.ToString("MMMM"); + var selectedYear = selectedDate?.ToString("yyyy"); // Taps the date picker to show the popup. - this.Click(); + Click(); // Finds the popup and changes the date. - WindowsElementWrapper popup = this.Driver.FindElement(WindowsByExtras.AutomationId("DatePickerFlyoutPresenter")); + WindowsElementWrapper popup = Driver.FindElement(WindowsByExtras.AutomationId("DatePickerFlyoutPresenter")); if (selectedDay != date.ToString("%d")) { @@ -126,16 +95,16 @@ public virtual void SetDate(DateTime date) /// Thrown when an element is no longer valid in the document DOM. private string GetValue() { - AppiumWebElement button = this.FindElement(WindowsByExtras.AutomationId("FlyoutButton")); - string name = button.GetName().RemoveUnicodeCharacters(); - Match match = Regex.Match(name, @"\w+\s\d{1,2},\s\d{4}"); + var button = FindElement(WindowsByExtras.AutomationId("FlyoutButton")); + var name = button.GetName().RemoveUnicodeCharacters(); + var match = Regex.Match(name, @"\w+\s\d{1,2},\s\d{4}"); return match.Success ? match.Value : null; } private DateTime? GetSelectedDate() { - string value = this.Value; + var value = Value; return string.IsNullOrEmpty(value) ? default : - DateTime.TryParse(value, out DateTime date) ? date : default(DateTime?); + DateTime.TryParse(value, out var date) ? date : default(DateTime?); } -} \ No newline at end of file +} diff --git a/src/Legerity.Windows/Elements/Core/FlipView.cs b/src/Legerity.Windows/Elements/Core/FlipView.cs index 115119de..3868ca56 100644 --- a/src/Legerity.Windows/Elements/Core/FlipView.cs +++ b/src/Legerity.Windows/Elements/Core/FlipView.cs @@ -5,14 +5,10 @@ namespace Legerity.Windows.Elements.Core; using System.Globalization; using System.Linq; using Legerity.Extensions; -using Legerity.Windows.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; +using Extensions; /// -/// Defines a wrapper for the core UWP FlipView control. +/// Defines a wrapper for the core UWP FlipView control. /// public class FlipView : WindowsElementWrapper { @@ -20,9 +16,9 @@ public class FlipView : WindowsElementWrapper /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public FlipView(WindowsElement element) + public FlipView(WebElement element) : base(element) { } @@ -30,72 +26,44 @@ public FlipView(WindowsElement element) /// /// Gets the collection of items associated with the flip view. /// - public virtual ReadOnlyCollection Items => this.Element.FindElements(By.ClassName("FlipViewItem")); + public virtual ReadOnlyCollection Items => Element.FindElements(By.ClassName("FlipViewItem")).Cast().ToList().AsReadOnly(); /// /// Gets the element associated with the next item button. /// /// Thrown when no element matches the expected locator. - public virtual Button NextButton => this.FindElement(WindowsByExtras.AutomationId("NextButtonHorizontal")); + public virtual Button NextButton => FindElement(WindowsByExtras.AutomationId("NextButtonHorizontal")); /// /// Gets the element associated with the previous item button. /// /// Thrown when no element matches the expected locator. - public virtual Button PreviousButton => this.FindElement(WindowsByExtras.AutomationId("PreviousButtonHorizontal")); + public virtual Button PreviousButton => FindElement(WindowsByExtras.AutomationId("PreviousButtonHorizontal")); /// /// Gets the currently selected item. /// - public virtual AppiumWebElement SelectedItem => this.Items.FirstOrDefault(i => i.IsSelected()); + public virtual WebElement SelectedItem => Items.FirstOrDefault(i => i.IsSelected()); /// /// Gets the currently selected item index. /// - public virtual int SelectedIndex => this.Items.IndexOf(this.SelectedItem); + public virtual int SelectedIndex => Items.IndexOf(SelectedItem); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator FlipView(WindowsElement element) + public static implicit operator FlipView(WebElement element) { return new FlipView(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator FlipView(AppiumWebElement element) - { - return new FlipView(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator FlipView(RemoteWebElement element) - { - return new FlipView(element as WindowsElement); - } - + /// /// Selects an item in the flip view by the specified name. /// @@ -107,9 +75,9 @@ public static implicit operator FlipView(RemoteWebElement element) /// Thrown when an element is not visible. public virtual void SelectItem(string name) { - int expectedItemIdx = this.Items.IndexOf(this.Items.FirstOrDefault(x => + var expectedItemIdx = Items.IndexOf(Items.FirstOrDefault(x => x.Text.Contains(name, CultureInfo.InvariantCulture, CompareOptions.IgnoreCase))); - this.SelectItemByIndex(expectedItemIdx); + SelectItemByIndex(expectedItemIdx); } /// @@ -121,19 +89,19 @@ public virtual void SelectItem(string name) /// Thrown when an element is no longer valid in the document DOM. public virtual void SelectItemByIndex(int index) { - int currentItemIdx = this.SelectedIndex; - int diff = index - currentItemIdx; - int shifts = Math.Abs(diff); + var currentItemIdx = SelectedIndex; + var diff = index - currentItemIdx; + var shifts = Math.Abs(diff); - for (int i = 0; i < shifts; i++) + for (var i = 0; i < shifts; i++) { if (diff > 0) { - this.SelectNext(); + SelectNext(); } else { - this.SelectPrevious(); + SelectPrevious(); } } } @@ -146,8 +114,8 @@ public virtual void SelectItemByIndex(int index) /// Thrown when an element is no longer valid in the document DOM. public virtual void SelectNext() { - this.Click(); - this.Element.SendKeys(Keys.ArrowRight); + Click(); + Element.SendKeys(Keys.ArrowRight); } /// @@ -158,7 +126,7 @@ public virtual void SelectNext() /// Thrown when an element is no longer valid in the document DOM. public virtual void SelectPrevious() { - this.Click(); - this.Element.SendKeys(Keys.ArrowLeft); + Click(); + Element.SendKeys(Keys.ArrowLeft); } -} \ No newline at end of file +} diff --git a/src/Legerity.Windows/Elements/Core/GridView.cs b/src/Legerity.Windows/Elements/Core/GridView.cs index 536d8fce..46b599a8 100644 --- a/src/Legerity.Windows/Elements/Core/GridView.cs +++ b/src/Legerity.Windows/Elements/Core/GridView.cs @@ -4,27 +4,22 @@ namespace Legerity.Windows.Elements.Core; using System.Collections.ObjectModel; using System.Linq; using Legerity.Exceptions; -using Legerity.Windows.Extensions; - -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; +using Extensions; /// -/// Defines a wrapper for the core UWP GridView control. +/// Defines a wrapper for the core UWP GridView control. /// public class GridView : WindowsElementWrapper { - private readonly By gridViewItemLocator = By.ClassName("GridViewItem"); + private readonly By _gridViewItemLocator = By.ClassName("GridViewItem"); /// /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public GridView(WindowsElement element) + public GridView(WebElement element) : base(element) { } @@ -32,61 +27,33 @@ public GridView(WindowsElement element) /// /// Gets the collection of items associated with the grid view. /// - public virtual ReadOnlyCollection Items => - this.Element.FindElements(this.gridViewItemLocator); + public virtual ReadOnlyCollection Items => + Element.FindElements(_gridViewItemLocator).Cast().ToList().AsReadOnly(); /// /// Gets the element associated with the currently selected item. /// - public virtual AppiumWebElement SelectedItem => this.Items.FirstOrDefault(i => i.IsSelected()); + public virtual WebElement SelectedItem => Items.FirstOrDefault(i => i.IsSelected()); /// /// Gets the currently selected item index. /// - public virtual int SelectedIndex => this.Items.IndexOf(this.SelectedItem); + public virtual int SelectedIndex => Items.IndexOf(SelectedItem); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator GridView(WindowsElement element) + public static implicit operator GridView(WebElement element) { return new GridView(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator GridView(AppiumWebElement element) - { - return new GridView(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator GridView(RemoteWebElement element) - { - return new GridView(element as WindowsElement); - } - + /// /// Clicks on an item in the list view with the specified item name. /// @@ -100,9 +67,9 @@ public static implicit operator GridView(RemoteWebElement element) /// Thrown when an element is not visible. public virtual void ClickItem(string name) { - this.VerifyElementsShown(this.gridViewItemLocator, TimeSpan.FromSeconds(2)); + VerifyElementsShown(_gridViewItemLocator, TimeSpan.FromSeconds(2)); - AppiumWebElement item = this.Items.FirstOrDefault(element => element.VerifyNameOrAutomationIdEquals(name)); + var item = Items.FirstOrDefault(element => element.VerifyNameOrAutomationIdEquals(name)); if (item == null) { @@ -125,10 +92,10 @@ public virtual void ClickItem(string name) /// Thrown when an element is no longer valid in the document DOM. public virtual void ClickItemByPartialName(string partialName) { - this.VerifyElementsShown(this.gridViewItemLocator, TimeSpan.FromSeconds(2)); + VerifyElementsShown(_gridViewItemLocator, TimeSpan.FromSeconds(2)); - AppiumWebElement item = - this.Items.FirstOrDefault(element => element.VerifyNameOrAutomationIdContains(partialName)); + var item = + Items.FirstOrDefault(element => element.VerifyNameOrAutomationIdContains(partialName)); if (item == null) { @@ -151,9 +118,9 @@ public virtual void ClickItemByPartialName(string partialName) /// Thrown when an element is no longer valid in the document DOM. public virtual void ClickItemByIndex(int index) { - this.VerifyElementsShown(this.gridViewItemLocator, TimeSpan.FromSeconds(2)); + VerifyElementsShown(_gridViewItemLocator, TimeSpan.FromSeconds(2)); - AppiumWebElement item = this.Items[index]; + var item = Items[index]; if (item == null) { @@ -162,4 +129,4 @@ public virtual void ClickItemByIndex(int index) item.Click(); } -} \ No newline at end of file +} diff --git a/src/Legerity.Windows/Elements/Core/Hub.cs b/src/Legerity.Windows/Elements/Core/Hub.cs index 1aaff34a..8f5c3824 100644 --- a/src/Legerity.Windows/Elements/Core/Hub.cs +++ b/src/Legerity.Windows/Elements/Core/Hub.cs @@ -1,13 +1,10 @@ namespace Legerity.Windows.Elements.Core; using System.Collections.ObjectModel; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; +using System.Linq; /// -/// Defines a wrapper for the core UWP Hub control. +/// Defines a wrapper for the core UWP Hub control. /// public class Hub : WindowsElementWrapper { @@ -15,9 +12,9 @@ public class Hub : WindowsElementWrapper /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public Hub(WindowsElement element) + public Hub(WebElement element) : base(element) { } @@ -25,47 +22,19 @@ public Hub(WindowsElement element) /// /// Gets the collection of items associated with the hub. /// - public virtual ReadOnlyCollection Items => this.Element.FindElements(By.ClassName("HubSection")); + public virtual ReadOnlyCollection Items => Element.FindElements(By.ClassName("HubSection")).Cast().ToList().AsReadOnly(); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator Hub(WindowsElement element) + public static implicit operator Hub(WebElement element) { return new Hub(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator Hub(AppiumWebElement element) - { - return new Hub(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator Hub(RemoteWebElement element) - { - return new Hub(element as WindowsElement); - } -} \ No newline at end of file +} diff --git a/src/Legerity.Windows/Elements/Core/HyperlinkButton.cs b/src/Legerity.Windows/Elements/Core/HyperlinkButton.cs index 74744673..f142023d 100644 --- a/src/Legerity.Windows/Elements/Core/HyperlinkButton.cs +++ b/src/Legerity.Windows/Elements/Core/HyperlinkButton.cs @@ -1,11 +1,7 @@ namespace Legerity.Windows.Elements.Core; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; - /// -/// Defines a wrapper for the core UWP HyperlinkButton control. +/// Defines a wrapper for the core UWP HyperlinkButton control. /// public class HyperlinkButton : Button { @@ -13,52 +9,24 @@ public class HyperlinkButton : Button /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public HyperlinkButton(WindowsElement element) + public HyperlinkButton(WebElement element) : base(element) { } /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator HyperlinkButton(WindowsElement element) + public static implicit operator HyperlinkButton(WebElement element) { return new HyperlinkButton(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator HyperlinkButton(AppiumWebElement element) - { - return new HyperlinkButton(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator HyperlinkButton(RemoteWebElement element) - { - return new HyperlinkButton(element as WindowsElement); - } -} \ No newline at end of file +} diff --git a/src/Legerity.Windows/Elements/Core/InkToolbar.BallpointPenFlyout.cs b/src/Legerity.Windows/Elements/Core/InkToolbar.BallpointPenFlyout.cs index ccd62a8e..c33142dd 100644 --- a/src/Legerity.Windows/Elements/Core/InkToolbar.BallpointPenFlyout.cs +++ b/src/Legerity.Windows/Elements/Core/InkToolbar.BallpointPenFlyout.cs @@ -1,9 +1,5 @@ namespace Legerity.Windows.Elements.Core; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; - /// /// Defines the ballpoint pen flyout components of the . /// @@ -15,56 +11,28 @@ public partial class InkToolbar public class InkToolbarBallpointPenFlyout : InkToolbarColorFlyoutBase { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public InkToolbarBallpointPenFlyout(WindowsElement element) + public InkToolbarBallpointPenFlyout(WebElement element) : base(element) { } /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator InkToolbarBallpointPenFlyout(WindowsElement element) + public static implicit operator InkToolbarBallpointPenFlyout(WebElement element) { return new InkToolbarBallpointPenFlyout(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator InkToolbarBallpointPenFlyout(AppiumWebElement element) - { - return new InkToolbarBallpointPenFlyout(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator InkToolbarBallpointPenFlyout(RemoteWebElement element) - { - return new InkToolbarBallpointPenFlyout(element as WindowsElement); - } } -} \ No newline at end of file +} diff --git a/src/Legerity.Windows/Elements/Core/InkToolbar.ColorFlyoutBase.cs b/src/Legerity.Windows/Elements/Core/InkToolbar.ColorFlyoutBase.cs index d5e23c66..7b47b0cb 100644 --- a/src/Legerity.Windows/Elements/Core/InkToolbar.ColorFlyoutBase.cs +++ b/src/Legerity.Windows/Elements/Core/InkToolbar.ColorFlyoutBase.cs @@ -4,10 +4,7 @@ namespace Legerity.Windows.Elements.Core; using System.Linq; using Legerity.Exceptions; using Legerity.Extensions; -using Legerity.Windows.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; +using Extensions; /// /// Defines the color flyout components of the . @@ -19,15 +16,15 @@ public partial class InkToolbar /// public abstract class InkToolbarColorFlyoutBase : WindowsElementWrapper { - private readonly By penColorPaletteLocator = WindowsByExtras.AutomationId("PenColorPalette"); + private readonly By _penColorPaletteLocator = WindowsByExtras.AutomationId("PenColorPalette"); /// /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - protected InkToolbarColorFlyoutBase(WindowsElement element) + protected InkToolbarColorFlyoutBase(WebElement element) : base(element) { } @@ -36,14 +33,14 @@ protected InkToolbarColorFlyoutBase(WindowsElement element) /// Gets the element associated with the color grid. /// /// Thrown when no element matches the expected locator. - public virtual GridView ColorGridView => this.Driver.FindElement(this.penColorPaletteLocator); + public virtual GridView ColorGridView => Driver.FindElement(_penColorPaletteLocator); /// /// Gets the element associated with the size of the ink. /// /// Thrown when no element matches the expected locator. public virtual Slider SizeSlider => - this.Driver.FindElement(WindowsByExtras.AutomationId("PenStrokeWidthSlider")); + Driver.FindElement(WindowsByExtras.AutomationId("PenStrokeWidthSlider")); /// /// Gets the currently selected color. @@ -51,12 +48,12 @@ protected InkToolbarColorFlyoutBase(WindowsElement element) /// Thrown when an element is no longer valid in the document DOM. /// Thrown when no element matches the expected locator. /// Thrown when an element is not shown for the expected locator. - public virtual string SelectedColor => this.GetSelectedColor().GetName(); + public virtual string SelectedColor => GetSelectedColor().GetName(); /// /// Gets the currently selected size. /// - public virtual double SelectedSize => this.SizeSlider.Value; + public virtual double SelectedSize => SizeSlider.Value; /// /// Sets the color of the ink. @@ -69,7 +66,7 @@ protected InkToolbarColorFlyoutBase(WindowsElement element) /// Thrown when no elements are shown for the expected locator. public virtual void SetColor(string color) { - this.ColorGridView.ClickItem(color); + ColorGridView.ClickItem(color); } /// @@ -83,17 +80,17 @@ public virtual void SetColor(string color) /// Thrown when no elements are shown for the expected locator. public virtual void SetColorByPartialName(string partialColor) { - this.ColorGridView.ClickItemByPartialName(partialColor); + ColorGridView.ClickItemByPartialName(partialColor); } /// Thrown when an element is not shown for the expected locator. /// Thrown when no element matches the expected locator. /// Thrown when an element is no longer valid in the document DOM. - private AppiumWebElement GetSelectedColor() + private WebElement GetSelectedColor() { - this.VerifyElementShown(this.penColorPaletteLocator, TimeSpan.FromSeconds(2)); + VerifyElementShown(_penColorPaletteLocator, TimeSpan.FromSeconds(2)); - return this.ColorGridView.Items.FirstOrDefault(i => i.IsSelected()); + return ColorGridView.Items.FirstOrDefault(i => i.IsSelected()); } } -} \ No newline at end of file +} diff --git a/src/Legerity.Windows/Elements/Core/InkToolbar.HighlighterFlyout.cs b/src/Legerity.Windows/Elements/Core/InkToolbar.HighlighterFlyout.cs index ca357ce9..dc02b97f 100644 --- a/src/Legerity.Windows/Elements/Core/InkToolbar.HighlighterFlyout.cs +++ b/src/Legerity.Windows/Elements/Core/InkToolbar.HighlighterFlyout.cs @@ -1,9 +1,5 @@ namespace Legerity.Windows.Elements.Core; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; - /// /// Defines the highlighter flyout components of the . /// @@ -15,56 +11,28 @@ public partial class InkToolbar public class InkToolbarHighlighterFlyout : InkToolbarColorFlyoutBase { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public InkToolbarHighlighterFlyout(WindowsElement element) + public InkToolbarHighlighterFlyout(WebElement element) : base(element) { } /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator InkToolbarHighlighterFlyout(WindowsElement element) + public static implicit operator InkToolbarHighlighterFlyout(WebElement element) { return new InkToolbarHighlighterFlyout(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator InkToolbarHighlighterFlyout(AppiumWebElement element) - { - return new InkToolbarHighlighterFlyout(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator InkToolbarHighlighterFlyout(RemoteWebElement element) - { - return new InkToolbarHighlighterFlyout(element as WindowsElement); - } } -} \ No newline at end of file +} diff --git a/src/Legerity.Windows/Elements/Core/InkToolbar.PencilFlyout.cs b/src/Legerity.Windows/Elements/Core/InkToolbar.PencilFlyout.cs index a3c25d24..c8bf5d8c 100644 --- a/src/Legerity.Windows/Elements/Core/InkToolbar.PencilFlyout.cs +++ b/src/Legerity.Windows/Elements/Core/InkToolbar.PencilFlyout.cs @@ -1,9 +1,5 @@ namespace Legerity.Windows.Elements.Core; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; - /// /// Defines the pencil flyout components of the . /// @@ -15,56 +11,28 @@ public partial class InkToolbar public class InkToolbarPencilFlyout : InkToolbarColorFlyoutBase { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public InkToolbarPencilFlyout(WindowsElement element) + public InkToolbarPencilFlyout(WebElement element) : base(element) { } /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator InkToolbarPencilFlyout(WindowsElement element) + public static implicit operator InkToolbarPencilFlyout(WebElement element) { return new InkToolbarPencilFlyout(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator InkToolbarPencilFlyout(AppiumWebElement element) - { - return new InkToolbarPencilFlyout(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator InkToolbarPencilFlyout(RemoteWebElement element) - { - return new InkToolbarPencilFlyout(element as WindowsElement); - } } -} \ No newline at end of file +} diff --git a/src/Legerity.Windows/Elements/Core/InkToolbar.cs b/src/Legerity.Windows/Elements/Core/InkToolbar.cs index 42f675fd..1ad67f64 100644 --- a/src/Legerity.Windows/Elements/Core/InkToolbar.cs +++ b/src/Legerity.Windows/Elements/Core/InkToolbar.cs @@ -3,29 +3,25 @@ namespace Legerity.Windows.Elements.Core; using System; using Extensions; using Legerity.Exceptions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; /// -/// Defines a wrapper for the core UWP InkToolbar control. +/// Defines a wrapper for the core UWP InkToolbar control. /// public partial class InkToolbar : WindowsElementWrapper { - private readonly By ballpointPenFlyoutLocator = By.Name("Ballpoint pen flyout"); + private readonly By _ballpointPenFlyoutLocator = By.Name("Ballpoint pen flyout"); - private readonly By pencilFlyoutLocator = By.Name("Pencil flyout"); + private readonly By _pencilFlyoutLocator = By.Name("Pencil flyout"); - private readonly By highlighterFlyoutLocator = By.Name("Highlighter flyout"); + private readonly By _highlighterFlyoutLocator = By.Name("Highlighter flyout"); /// /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public InkToolbar(WindowsElement element) + public InkToolbar(WebElement element) : base(element) { } @@ -35,49 +31,49 @@ public InkToolbar(WindowsElement element) /// /// Thrown when no element matches the expected locator. public virtual RadioButton BallpointPenButton => - this.FindElement(WindowsByExtras.AutomationId("InkToolbarBallpointPenButton")); + FindElement(WindowsByExtras.AutomationId("InkToolbarBallpointPenButton")); /// /// Gets the currently selected ballpoint pen color. /// /// Thrown when an element is no longer valid in the document DOM. /// Thrown when no element matches the expected locator. - public virtual string SelectedBallpointPenColor => this.BallpointPenButton.GetHelpText(); + public virtual string SelectedBallpointPenColor => BallpointPenButton.GetHelpText(); /// /// Gets the element associated with the pencil button. /// /// Thrown when no element matches the expected locator. public virtual RadioButton PencilButton => - this.FindElement(WindowsByExtras.AutomationId("InkToolbarPencilButton")); + FindElement(WindowsByExtras.AutomationId("InkToolbarPencilButton")); /// /// Gets the currently selected pencil color. /// /// Thrown when an element is no longer valid in the document DOM. /// Thrown when no element matches the expected locator. - public virtual string SelectedPencilColor => this.PencilButton.GetHelpText(); + public virtual string SelectedPencilColor => PencilButton.GetHelpText(); /// /// Gets the element associated with the highlighter button. /// /// Thrown when no element matches the expected locator. public virtual RadioButton HighlighterButton => - this.FindElement(WindowsByExtras.AutomationId("InkToolbarHighlighterButton")); + FindElement(WindowsByExtras.AutomationId("InkToolbarHighlighterButton")); /// /// Gets the currently selected highlighter color. /// /// Thrown when no element matches the expected locator. /// Thrown when an element is no longer valid in the document DOM. - public virtual string SelectedHighlighterColor => this.HighlighterButton.GetHelpText(); + public virtual string SelectedHighlighterColor => HighlighterButton.GetHelpText(); /// /// Gets the element associated with the ruler button. /// /// Thrown when no element matches the expected locator. public virtual ToggleButton RulerButton => - this.FindElement(WindowsByExtras.AutomationId("InkToolbarStencilButton")); + FindElement(WindowsByExtras.AutomationId("InkToolbarStencilButton")); /// /// Gets the element associated with the ballpoint pen flyout. @@ -87,7 +83,7 @@ public InkToolbar(WindowsElement element) /// /// Thrown when no element matches the expected locator. public virtual InkToolbarBallpointPenFlyout BallpointPenFlyout => - this.Driver.FindElement(this.ballpointPenFlyoutLocator); + Driver.FindElement(_ballpointPenFlyoutLocator); /// /// Gets the element associated with the pencil flyout. @@ -96,7 +92,7 @@ public InkToolbar(WindowsElement element) /// This is only available when the pencil button is selected. /// /// Thrown when no element matches the expected locator. - public virtual InkToolbarPencilFlyout PencilFlyout => this.Driver.FindElement(this.pencilFlyoutLocator); + public virtual InkToolbarPencilFlyout PencilFlyout => Driver.FindElement(_pencilFlyoutLocator); /// /// Gets the element associated with the highlighter flyout. @@ -106,50 +102,22 @@ public InkToolbar(WindowsElement element) /// /// Thrown when no element matches the expected locator. public virtual InkToolbarHighlighterFlyout HighlighterFlyout => - this.Driver.FindElement(this.highlighterFlyoutLocator); + Driver.FindElement(_highlighterFlyoutLocator); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator InkToolbar(WindowsElement element) + public static implicit operator InkToolbar(WebElement element) { return new InkToolbar(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator InkToolbar(AppiumWebElement element) - { - return new InkToolbar(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator InkToolbar(RemoteWebElement element) - { - return new InkToolbar(element as WindowsElement); - } - + /// /// Selects the ballpoint pen option. /// @@ -159,9 +127,9 @@ public static implicit operator InkToolbar(RemoteWebElement element) /// Thrown when an element is not visible. public virtual void SelectBallpointPen() { - if (!this.BallpointPenButton.IsSelected) + if (!BallpointPenButton.IsSelected) { - this.BallpointPenButton.Click(); + BallpointPenButton.Click(); } } @@ -175,10 +143,10 @@ public virtual void SelectBallpointPen() /// Thrown when an element is not shown for the expected locator. public virtual void OpenBallpointPenFlyout() { - this.SelectBallpointPen(); + SelectBallpointPen(); - this.BallpointPenButton.Click(); - this.VerifyDriverElementShown(this.ballpointPenFlyoutLocator, TimeSpan.FromSeconds(2)); + BallpointPenButton.Click(); + VerifyDriverElementShown(_ballpointPenFlyoutLocator, TimeSpan.FromSeconds(2)); } /// @@ -195,8 +163,8 @@ public virtual void OpenBallpointPenFlyout() /// Thrown when no elements are shown for the expected locator. public virtual void SetBallpointPenColor(string color) { - this.OpenBallpointPenFlyout(); - this.BallpointPenFlyout.SetColor(color); + OpenBallpointPenFlyout(); + BallpointPenFlyout.SetColor(color); } /// @@ -213,8 +181,8 @@ public virtual void SetBallpointPenColor(string color) /// Thrown when no elements are shown for the expected locator. public virtual void SetBallpointPenColorByPartialName(string color) { - this.OpenBallpointPenFlyout(); - this.BallpointPenFlyout.SetColorByPartialName(color); + OpenBallpointPenFlyout(); + BallpointPenFlyout.SetColorByPartialName(color); } /// @@ -226,9 +194,9 @@ public virtual void SetBallpointPenColorByPartialName(string color) /// Thrown when an element is no longer valid in the document DOM. public virtual void SelectPencil() { - if (!this.PencilButton.IsSelected) + if (!PencilButton.IsSelected) { - this.PencilButton.Click(); + PencilButton.Click(); } } @@ -242,10 +210,10 @@ public virtual void SelectPencil() /// Thrown when an element is not shown for the expected locator. public virtual void OpenPencilFlyout() { - this.SelectPencil(); + SelectPencil(); - this.PencilButton.Click(); - this.VerifyDriverElementShown(this.pencilFlyoutLocator, TimeSpan.FromSeconds(2)); + PencilButton.Click(); + VerifyDriverElementShown(_pencilFlyoutLocator, TimeSpan.FromSeconds(2)); } /// @@ -262,8 +230,8 @@ public virtual void OpenPencilFlyout() /// Thrown when no elements are shown for the expected locator. public virtual void SetPencilColor(string color) { - this.OpenPencilFlyout(); - this.PencilFlyout.SetColor(color); + OpenPencilFlyout(); + PencilFlyout.SetColor(color); } /// @@ -280,8 +248,8 @@ public virtual void SetPencilColor(string color) /// Thrown when no elements are shown for the expected locator. public virtual void SetPencilColorByPartialName(string color) { - this.OpenPencilFlyout(); - this.PencilFlyout.SetColorByPartialName(color); + OpenPencilFlyout(); + PencilFlyout.SetColorByPartialName(color); } /// @@ -293,9 +261,9 @@ public virtual void SetPencilColorByPartialName(string color) /// Thrown when an element is no longer valid in the document DOM. public virtual void SelectHighlighter() { - if (!this.HighlighterButton.IsSelected) + if (!HighlighterButton.IsSelected) { - this.HighlighterButton.Click(); + HighlighterButton.Click(); } } @@ -309,10 +277,10 @@ public virtual void SelectHighlighter() /// Thrown when an element is not shown for the expected locator. public virtual void OpenHighlighterFlyout() { - this.SelectHighlighter(); + SelectHighlighter(); - this.HighlighterButton.Click(); - this.VerifyDriverElementShown(this.highlighterFlyoutLocator, TimeSpan.FromSeconds(2)); + HighlighterButton.Click(); + VerifyDriverElementShown(_highlighterFlyoutLocator, TimeSpan.FromSeconds(2)); } /// @@ -329,8 +297,8 @@ public virtual void OpenHighlighterFlyout() /// Thrown when no elements are shown for the expected locator. public virtual void SetHighlighterColor(string color) { - this.OpenHighlighterFlyout(); - this.HighlighterFlyout.SetColor(color); + OpenHighlighterFlyout(); + HighlighterFlyout.SetColor(color); } /// @@ -347,7 +315,7 @@ public virtual void SetHighlighterColor(string color) /// Thrown when no elements are shown for the expected locator. public virtual void SetHighlighterColorByPartialName(string color) { - this.OpenHighlighterFlyout(); - this.HighlighterFlyout.SetColorByPartialName(color); + OpenHighlighterFlyout(); + HighlighterFlyout.SetColorByPartialName(color); } -} \ No newline at end of file +} diff --git a/src/Legerity.Windows/Elements/Core/ListBox.cs b/src/Legerity.Windows/Elements/Core/ListBox.cs index bf97b6c8..2a833084 100644 --- a/src/Legerity.Windows/Elements/Core/ListBox.cs +++ b/src/Legerity.Windows/Elements/Core/ListBox.cs @@ -4,27 +4,22 @@ namespace Legerity.Windows.Elements.Core; using System.Collections.ObjectModel; using System.Linq; using Legerity.Exceptions; -using Legerity.Windows.Extensions; - -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; +using Extensions; /// -/// Defines a wrapper for the core UWP ListBox control. +/// Defines a wrapper for the core UWP ListBox control. /// public class ListBox : WindowsElementWrapper { - private readonly By listBoxItemLocator = By.ClassName("ListBoxItem"); + private readonly By _listBoxItemLocator = By.ClassName("ListBoxItem"); /// /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public ListBox(WindowsElement element) + public ListBox(WebElement element) : base(element) { } @@ -32,56 +27,28 @@ public ListBox(WindowsElement element) /// /// Gets the collection of items associated with the list box. /// - public virtual ReadOnlyCollection Items => this.Element.FindElements(this.listBoxItemLocator); + public virtual ReadOnlyCollection Items => Element.FindElements(_listBoxItemLocator).Cast().ToList().AsReadOnly(); /// /// Gets the element associated with the currently selected item. /// /// Thrown when an element is no longer valid in the document DOM. - public virtual AppiumWebElement SelectedItem => this.Items.FirstOrDefault(i => i.IsSelected()); + public virtual WebElement SelectedItem => Items.FirstOrDefault(i => i.IsSelected()); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator ListBox(WindowsElement element) + public static implicit operator ListBox(WebElement element) { return new ListBox(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator ListBox(AppiumWebElement element) - { - return new ListBox(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator ListBox(RemoteWebElement element) - { - return new ListBox(element as WindowsElement); - } - + /// /// Clicks on an item in the list box with the specified item name. /// @@ -95,8 +62,8 @@ public static implicit operator ListBox(RemoteWebElement element) /// Thrown when an element is no longer valid in the document DOM. public virtual void ClickItem(string name) { - this.VerifyElementsShown(this.listBoxItemLocator, TimeSpan.FromSeconds(2)); - AppiumWebElement item = this.Items.FirstOrDefault(element => element.VerifyNameOrAutomationIdEquals(name)); + VerifyElementsShown(_listBoxItemLocator, TimeSpan.FromSeconds(2)); + var item = Items.FirstOrDefault(element => element.VerifyNameOrAutomationIdEquals(name)); if (item == null) { @@ -117,9 +84,9 @@ public virtual void ClickItem(string name) /// Thrown when an element is not visible. public virtual void ClickItemByPartialName(string partialName) { - this.VerifyElementsShown(this.listBoxItemLocator, TimeSpan.FromSeconds(2)); - AppiumWebElement item = - this.Items.FirstOrDefault(element => element.VerifyNameOrAutomationIdContains(partialName)); + VerifyElementsShown(_listBoxItemLocator, TimeSpan.FromSeconds(2)); + var item = + Items.FirstOrDefault(element => element.VerifyNameOrAutomationIdContains(partialName)); if (item == null) { @@ -128,4 +95,4 @@ public virtual void ClickItemByPartialName(string partialName) item.Click(); } -} \ No newline at end of file +} diff --git a/src/Legerity.Windows/Elements/Core/ListView.cs b/src/Legerity.Windows/Elements/Core/ListView.cs index 01d1f05a..9d8b5d82 100644 --- a/src/Legerity.Windows/Elements/Core/ListView.cs +++ b/src/Legerity.Windows/Elements/Core/ListView.cs @@ -4,27 +4,22 @@ namespace Legerity.Windows.Elements.Core; using System.Collections.ObjectModel; using System.Linq; using Legerity.Exceptions; -using Legerity.Windows.Extensions; - -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; +using Extensions; /// -/// Defines a wrapper for the core UWP ListView control. +/// Defines a wrapper for the core UWP ListView control. /// public class ListView : WindowsElementWrapper { - private readonly By listViewItemLocator = By.ClassName("ListViewItem"); + private readonly By _listViewItemLocator = By.ClassName("ListViewItem"); /// /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public ListView(WindowsElement element) + public ListView(WebElement element) : base(element) { } @@ -32,56 +27,28 @@ public ListView(WindowsElement element) /// /// Gets the collection of items associated with the list view. /// - public virtual ReadOnlyCollection Items => this.Element.FindElements(this.listViewItemLocator); + public virtual ReadOnlyCollection Items => Element.FindElements(_listViewItemLocator).Cast().ToList().AsReadOnly(); /// /// Gets the element associated with the currently selected item. /// /// Thrown when an element is no longer valid in the document DOM. - public virtual AppiumWebElement SelectedItem => this.Items.FirstOrDefault(i => i.IsSelected()); + public virtual WebElement SelectedItem => Items.FirstOrDefault(i => i.IsSelected()); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator ListView(WindowsElement element) + public static implicit operator ListView(WebElement element) { return new ListView(element); } - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator ListView(AppiumWebElement element) - { - return new ListView(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator ListView(RemoteWebElement element) - { - return new ListView(element as WindowsElement); - } - /// /// Clicks on an item in the list view with the specified item name. /// @@ -95,8 +62,8 @@ public static implicit operator ListView(RemoteWebElement element) /// Thrown when an element is no longer valid in the document DOM. public virtual void ClickItem(string name) { - this.VerifyElementsShown(this.listViewItemLocator, TimeSpan.FromSeconds(2)); - AppiumWebElement item = this.Items.FirstOrDefault(element => element.VerifyNameOrAutomationIdEquals(name)); + VerifyElementsShown(_listViewItemLocator, TimeSpan.FromSeconds(2)); + var item = Items.FirstOrDefault(element => element.VerifyNameOrAutomationIdEquals(name)); if (item == null) { @@ -117,9 +84,9 @@ public virtual void ClickItem(string name) /// Thrown when an element is no longer valid in the document DOM. public virtual void ClickItemByPartialName(string partialName) { - this.VerifyElementsShown(this.listViewItemLocator, TimeSpan.FromSeconds(2)); - AppiumWebElement item = - this.Items.FirstOrDefault(element => element.VerifyNameOrAutomationIdContains(partialName)); + VerifyElementsShown(_listViewItemLocator, TimeSpan.FromSeconds(2)); + var item = + Items.FirstOrDefault(element => element.VerifyNameOrAutomationIdContains(partialName)); if (item == null) { @@ -128,4 +95,4 @@ public virtual void ClickItemByPartialName(string partialName) item.Click(); } -} \ No newline at end of file +} diff --git a/src/Legerity.Windows/Elements/Core/MenuFlyoutItem.cs b/src/Legerity.Windows/Elements/Core/MenuFlyoutItem.cs index a14c5999..ecef09ed 100644 --- a/src/Legerity.Windows/Elements/Core/MenuFlyoutItem.cs +++ b/src/Legerity.Windows/Elements/Core/MenuFlyoutItem.cs @@ -1,11 +1,7 @@ namespace Legerity.Windows.Elements.Core; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; - /// -/// Defines a wrapper for the UWP MenuFlyoutItem control. +/// Defines a wrapper for the UWP MenuFlyoutItem control. /// public class MenuFlyoutItem : WindowsElementWrapper { @@ -13,52 +9,24 @@ public class MenuFlyoutItem : WindowsElementWrapper /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public MenuFlyoutItem(WindowsElement element) + public MenuFlyoutItem(WebElement element) : base(element) { } /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator MenuFlyoutItem(WindowsElement element) + public static implicit operator MenuFlyoutItem(WebElement element) { return new MenuFlyoutItem(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator MenuFlyoutItem(AppiumWebElement element) - { - return new MenuFlyoutItem(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator MenuFlyoutItem(RemoteWebElement element) - { - return new MenuFlyoutItem(element as WindowsElement); - } -} \ No newline at end of file +} diff --git a/src/Legerity.Windows/Elements/Core/MenuFlyoutSubItem.cs b/src/Legerity.Windows/Elements/Core/MenuFlyoutSubItem.cs index e12e008b..d0c5e2b4 100644 --- a/src/Legerity.Windows/Elements/Core/MenuFlyoutSubItem.cs +++ b/src/Legerity.Windows/Elements/Core/MenuFlyoutSubItem.cs @@ -5,13 +5,9 @@ namespace Legerity.Windows.Elements.Core; using System.Globalization; using System.Linq; using Legerity.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; /// -/// Defines a wrapper for the UWP MenuFlyoutSubItem control. +/// Defines a wrapper for the UWP MenuFlyoutSubItem control. /// public class MenuFlyoutSubItem : WindowsElementWrapper { @@ -19,9 +15,9 @@ public class MenuFlyoutSubItem : WindowsElementWrapper /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public MenuFlyoutSubItem(WindowsElement element) + public MenuFlyoutSubItem(WebElement element) : base(element) { } @@ -30,56 +26,28 @@ public MenuFlyoutSubItem(WindowsElement element) /// Gets the UI components associated with the child menu items. /// /// Thrown when no element matches the expected locator. - public virtual IEnumerable ChildMenuItems => this.GetChildMenuItems(); + public virtual IEnumerable ChildMenuItems => GetChildMenuItems(); /// /// Gets the UI components associated with the child menu sub-items. /// /// Thrown when no element matches the expected locator. - public virtual IEnumerable ChildMenuSubItems => this.GetChildMenuSubItems(); + public virtual IEnumerable ChildMenuSubItems => GetChildMenuSubItems(); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator MenuFlyoutSubItem(WindowsElement element) + public static implicit operator MenuFlyoutSubItem(WebElement element) { return new MenuFlyoutSubItem(element); } - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator MenuFlyoutSubItem(AppiumWebElement element) - { - return new MenuFlyoutSubItem(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator MenuFlyoutSubItem(RemoteWebElement element) - { - return new MenuFlyoutSubItem(element as WindowsElement); - } - /// /// Clicks on a child menu option with the specified item name. /// @@ -95,7 +63,7 @@ public static implicit operator MenuFlyoutSubItem(RemoteWebElement element) /// Thrown when an element is no longer valid in the document DOM. public virtual MenuFlyoutItem ClickChildOption(string name) { - MenuFlyoutItem item = this.ChildMenuItems.FirstOrDefault( + var item = ChildMenuItems.FirstOrDefault( element => element.GetName() .Equals(name, StringComparison.CurrentCultureIgnoreCase)); @@ -123,7 +91,7 @@ public virtual MenuFlyoutItem ClickChildOption(string name) /// Thrown when an element is no longer valid in the document DOM. public virtual MenuFlyoutItem ClickChildOptionByPartialName(string name) { - MenuFlyoutItem item = this.ChildMenuItems.FirstOrDefault( + var item = ChildMenuItems.FirstOrDefault( element => element.GetName() .Contains(name, CultureInfo.CurrentCulture, CompareOptions.IgnoreCase)); @@ -147,7 +115,7 @@ public virtual MenuFlyoutItem ClickChildOptionByPartialName(string name) /// Thrown when an element is no longer valid in the document DOM. public virtual MenuFlyoutSubItem ClickChildSubOption(string name) { - MenuFlyoutSubItem item = this.ChildMenuSubItems.FirstOrDefault( + var item = ChildMenuSubItems.FirstOrDefault( element => element.GetName() .Equals(name, StringComparison.CurrentCultureIgnoreCase)); @@ -171,7 +139,7 @@ public virtual MenuFlyoutSubItem ClickChildSubOption(string name) /// Thrown when an element is no longer valid in the document DOM. public virtual MenuFlyoutSubItem ClickChildSubOptionByPartialName(string name) { - MenuFlyoutSubItem item = this.ChildMenuSubItems.FirstOrDefault( + var item = ChildMenuSubItems.FirstOrDefault( element => element.GetName() .Contains(name, CultureInfo.CurrentCulture, CompareOptions.IgnoreCase)); @@ -187,16 +155,16 @@ public virtual MenuFlyoutSubItem ClickChildSubOptionByPartialName(string name) /// Thrown when no element matches the expected locator. private IEnumerable GetChildMenuItems() { - return this.Driver.FindElement(By.ClassName("MenuFlyout")) + return Driver.FindElement(By.ClassName("MenuFlyout")) .FindElements(By.ClassName(nameof(MenuFlyoutItem))).Select( - element => new MenuFlyoutItem(element as WindowsElement)); + element => new MenuFlyoutItem(element)); } /// Thrown when no element matches the expected locator. private IEnumerable GetChildMenuSubItems() { - return this.Driver.FindElement(By.ClassName("MenuFlyout")) + return Driver.FindElement(By.ClassName("MenuFlyout")) .FindElements(By.ClassName(nameof(MenuFlyoutSubItem))).Select( - element => new MenuFlyoutSubItem(element as WindowsElement)); + element => new MenuFlyoutSubItem(element)); } -} \ No newline at end of file +} diff --git a/src/Legerity.Windows/Elements/Core/PasswordBox.cs b/src/Legerity.Windows/Elements/Core/PasswordBox.cs index 1c2c56d2..fbece61c 100644 --- a/src/Legerity.Windows/Elements/Core/PasswordBox.cs +++ b/src/Legerity.Windows/Elements/Core/PasswordBox.cs @@ -1,13 +1,9 @@ namespace Legerity.Windows.Elements.Core; using Legerity.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; /// -/// Defines a wrapper for the core UWP PasswordBox control. +/// Defines a wrapper for the core UWP PasswordBox control. /// public class PasswordBox : TextBox { @@ -15,9 +11,9 @@ public class PasswordBox : TextBox /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public PasswordBox(WindowsElement element) + public PasswordBox(WebElement element) : base(element) { } @@ -26,7 +22,7 @@ public PasswordBox(WindowsElement element) /// Gets the element associated with the reveal password button. /// /// Thrown when no element matches the expected locator. - public virtual ToggleButton RevealButton => this.FindElement(WindowsByExtras.AutomationId("RevealButton")); + public virtual ToggleButton RevealButton => FindElement(WindowsByExtras.AutomationId("RevealButton")); /// /// Gets the password text value in the password box. @@ -35,57 +31,29 @@ public PasswordBox(WindowsElement element) /// To get the password text value, the password box must be revealed using the method. Otherwise, the text value will be hidden characters. /// /// Thrown when an element is no longer valid in the document DOM. - public virtual string Password => this.Text; + public virtual string Password => Text; /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator PasswordBox(WindowsElement element) + public static implicit operator PasswordBox(WebElement element) { return new PasswordBox(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator PasswordBox(AppiumWebElement element) - { - return new PasswordBox(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator PasswordBox(RemoteWebElement element) - { - return new PasswordBox(element as WindowsElement); - } - + /// /// Reveals the password text in the password box. /// /// Thrown when no element matches the expected locator. public virtual void RevealPassword() { - this.RevealButton.ClickAndHold(); + RevealButton.ClickAndHold(); } /// @@ -94,6 +62,6 @@ public virtual void RevealPassword() /// Thrown when no element matches the expected locator. public virtual void HidePassword() { - this.RevealButton.ReleaseHold(); + RevealButton.ReleaseHold(); } -} \ No newline at end of file +} diff --git a/src/Legerity.Windows/Elements/Core/Pivot.cs b/src/Legerity.Windows/Elements/Core/Pivot.cs index fe53237f..5d1d9f03 100644 --- a/src/Legerity.Windows/Elements/Core/Pivot.cs +++ b/src/Legerity.Windows/Elements/Core/Pivot.cs @@ -4,27 +4,22 @@ namespace Legerity.Windows.Elements.Core; using System.Collections.ObjectModel; using System.Linq; using Legerity.Exceptions; -using Legerity.Windows.Extensions; - -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; +using Extensions; /// -/// Defines a wrapper for the core UWP Pivot control. +/// Defines a wrapper for the core UWP Pivot control. /// public class Pivot : WindowsElementWrapper { - private readonly By pivotItemLocator = By.ClassName("PivotItem"); + private readonly By _pivotItemLocator = By.ClassName("PivotItem"); /// /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public Pivot(WindowsElement element) + public Pivot(WebElement element) : base(element) { } @@ -32,56 +27,28 @@ public Pivot(WindowsElement element) /// /// Gets the collection of items associated with the pivot. /// - public virtual ReadOnlyCollection Items => this.Element.FindElements(this.pivotItemLocator); + public virtual ReadOnlyCollection Items => Element.FindElements(_pivotItemLocator).Cast().ToList().AsReadOnly(); /// /// Gets the currently selected item. /// /// Thrown when an element is no longer valid in the document DOM. - public virtual AppiumWebElement SelectedItem => this.Items.FirstOrDefault(i => i.IsSelected()); + public virtual WebElement SelectedItem => Items.FirstOrDefault(i => i.IsSelected()); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator Pivot(WindowsElement element) + public static implicit operator Pivot(WebElement element) { return new Pivot(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator Pivot(AppiumWebElement element) - { - return new Pivot(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator Pivot(RemoteWebElement element) - { - return new Pivot(element as WindowsElement); - } - + /// /// Clicks on an item in the pivot with the specified item name. /// @@ -95,9 +62,9 @@ public static implicit operator Pivot(RemoteWebElement element) /// Thrown when an element is no longer valid in the document DOM. public virtual void ClickItem(string name) { - this.VerifyElementsShown(this.pivotItemLocator, TimeSpan.FromSeconds(2)); + VerifyElementsShown(_pivotItemLocator, TimeSpan.FromSeconds(2)); - AppiumWebElement item = this.Items.FirstOrDefault(element => element.VerifyNameOrAutomationIdEquals(name)); + var item = Items.FirstOrDefault(element => element.VerifyNameOrAutomationIdEquals(name)); if (item == null) { @@ -120,9 +87,9 @@ public virtual void ClickItem(string name) /// Thrown when an element is not visible. public virtual void ClickItemByPartialName(string name) { - this.VerifyElementsShown(this.pivotItemLocator, TimeSpan.FromSeconds(2)); + VerifyElementsShown(_pivotItemLocator, TimeSpan.FromSeconds(2)); - AppiumWebElement item = this.Items.FirstOrDefault(element => element.VerifyNameOrAutomationIdContains(name)); + var item = Items.FirstOrDefault(element => element.VerifyNameOrAutomationIdContains(name)); if (item == null) { @@ -131,4 +98,4 @@ public virtual void ClickItemByPartialName(string name) item.Click(); } -} \ No newline at end of file +} diff --git a/src/Legerity.Windows/Elements/Core/ProgressBar.cs b/src/Legerity.Windows/Elements/Core/ProgressBar.cs index d67f03f6..5ee1300b 100644 --- a/src/Legerity.Windows/Elements/Core/ProgressBar.cs +++ b/src/Legerity.Windows/Elements/Core/ProgressBar.cs @@ -1,14 +1,10 @@ namespace Legerity.Windows.Elements.Core; using System; -using Legerity.Windows.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; +using Extensions; /// -/// Defines a wrapper for the core UWP ProgressBar control. +/// Defines a wrapper for the core UWP ProgressBar control. /// public class ProgressBar : WindowsElementWrapper { @@ -16,9 +12,9 @@ public class ProgressBar : WindowsElementWrapper /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public ProgressBar(WindowsElement element) + public ProgressBar(WebElement element) : base(element) { } @@ -34,49 +30,21 @@ public ProgressBar(WindowsElement element) /// /// Thrown when an element is no longer valid in the document DOM. public bool IsIndeterminate => - this.GetAttribute("IsRangeValuePatternAvailable").Equals( + GetAttribute("IsRangeValuePatternAvailable").Equals( "False", StringComparison.CurrentCultureIgnoreCase); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator ProgressBar(WindowsElement element) + public static implicit operator ProgressBar(WebElement element) { return new ProgressBar(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator ProgressBar(AppiumWebElement element) - { - return new ProgressBar(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator ProgressBar(RemoteWebElement element) - { - return new ProgressBar(element as WindowsElement); - } -} \ No newline at end of file +} diff --git a/src/Legerity.Windows/Elements/Core/ProgressRing.cs b/src/Legerity.Windows/Elements/Core/ProgressRing.cs index 766437ef..0d1a225e 100644 --- a/src/Legerity.Windows/Elements/Core/ProgressRing.cs +++ b/src/Legerity.Windows/Elements/Core/ProgressRing.cs @@ -1,14 +1,10 @@ namespace Legerity.Windows.Elements.Core; -using Legerity.Windows.Extensions; +using Extensions; using System; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; /// -/// Defines a wrapper for the core UWP ProgressRing control. +/// Defines a wrapper for the core UWP ProgressRing control. /// public class ProgressRing : WindowsElementWrapper { @@ -16,9 +12,9 @@ public class ProgressRing : WindowsElementWrapper /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public ProgressRing(WindowsElement element) + public ProgressRing(WebElement element) : base(element) { } @@ -34,49 +30,21 @@ public ProgressRing(WindowsElement element) /// /// Thrown when an element is no longer valid in the document DOM. public bool IsIndeterminate => - this.GetAttribute("IsRangeValuePatternAvailable").Equals( + GetAttribute("IsRangeValuePatternAvailable").Equals( "False", StringComparison.CurrentCultureIgnoreCase); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator ProgressRing(WindowsElement element) + public static implicit operator ProgressRing(WebElement element) { return new ProgressRing(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator ProgressRing(AppiumWebElement element) - { - return new ProgressRing(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator ProgressRing(RemoteWebElement element) - { - return new ProgressRing(element as WindowsElement); - } -} \ No newline at end of file +} diff --git a/src/Legerity.Windows/Elements/Core/RadioButton.cs b/src/Legerity.Windows/Elements/Core/RadioButton.cs index 73dbb5ee..8eb40e26 100644 --- a/src/Legerity.Windows/Elements/Core/RadioButton.cs +++ b/src/Legerity.Windows/Elements/Core/RadioButton.cs @@ -1,13 +1,9 @@ namespace Legerity.Windows.Elements.Core; -using Legerity.Windows.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; +using Extensions; /// -/// Defines a wrapper for the core UWP RadioButton control. +/// Defines a wrapper for the core UWP RadioButton control. /// public class RadioButton : Button { @@ -15,9 +11,9 @@ public class RadioButton : Button /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public RadioButton(WindowsElement element) + public RadioButton(WebElement element) : base(element) { } @@ -29,44 +25,16 @@ public RadioButton(WindowsElement element) public virtual bool IsSelected => this.IsSelected(); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator RadioButton(WindowsElement element) + public static implicit operator RadioButton(WebElement element) { return new RadioButton(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator RadioButton(AppiumWebElement element) - { - return new RadioButton(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator RadioButton(RemoteWebElement element) - { - return new RadioButton(element as WindowsElement); - } -} \ No newline at end of file +} diff --git a/src/Legerity.Windows/Elements/Core/ScrollViewer.cs b/src/Legerity.Windows/Elements/Core/ScrollViewer.cs index 49c3f9c6..0cb25f6a 100644 --- a/src/Legerity.Windows/Elements/Core/ScrollViewer.cs +++ b/src/Legerity.Windows/Elements/Core/ScrollViewer.cs @@ -1,12 +1,7 @@ namespace Legerity.Windows.Elements.Core; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; - /// -/// Defines a wrapper for the Windows ScrollViewer control. +/// Defines a wrapper for the Windows ScrollViewer control. /// public class ScrollViewer : WindowsElementWrapper { @@ -14,55 +9,27 @@ public class ScrollViewer : WindowsElementWrapper /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public ScrollViewer(WindowsElement element) + public ScrollViewer(WebElement element) : base(element) { } /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator ScrollViewer(WindowsElement element) + public static implicit operator ScrollViewer(WebElement element) { return new ScrollViewer(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator ScrollViewer(AppiumWebElement element) - { - return new ScrollViewer(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator ScrollViewer(RemoteWebElement element) - { - return new ScrollViewer(element as WindowsElement); - } - + /// /// Scrolls the scroll viewer to the top. /// @@ -71,7 +38,7 @@ public static implicit operator ScrollViewer(RemoteWebElement element) /// Thrown when an element is no longer valid in the document DOM. public virtual void ScrollToTop() { - this.Element.SendKeys(Keys.Home); + Element.SendKeys(Keys.Home); } /// @@ -82,6 +49,6 @@ public virtual void ScrollToTop() /// Thrown when an element is no longer valid in the document DOM. public virtual void ScrollToBottom() { - this.Element.SendKeys(Keys.End); + Element.SendKeys(Keys.End); } -} \ No newline at end of file +} diff --git a/src/Legerity.Windows/Elements/Core/Slider.cs b/src/Legerity.Windows/Elements/Core/Slider.cs index 279ca448..56580e03 100644 --- a/src/Legerity.Windows/Elements/Core/Slider.cs +++ b/src/Legerity.Windows/Elements/Core/Slider.cs @@ -1,14 +1,10 @@ namespace Legerity.Windows.Elements.Core; using System; -using Legerity.Windows.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; +using Extensions; /// -/// Defines a wrapper for the core UWP Slider control. +/// Defines a wrapper for the core UWP Slider control. /// public class Slider : WindowsElementWrapper { @@ -16,9 +12,9 @@ public class Slider : WindowsElementWrapper /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public Slider(WindowsElement element) + public Slider(WebElement element) : base(element) { } @@ -54,47 +50,19 @@ public Slider(WindowsElement element) public virtual bool IsReadonly => this.IsRangeReadonly(); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator Slider(WindowsElement element) + public static implicit operator Slider(WebElement element) { return new Slider(element); } - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator Slider(AppiumWebElement element) - { - return new Slider(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator Slider(RemoteWebElement element) - { - return new Slider(element as WindowsElement); - } - /// /// Sets the value of the slider. /// @@ -109,10 +77,10 @@ public static implicit operator Slider(RemoteWebElement element) /// Thrown when an element is not visible. public virtual void SetValue(double value) { - double min = this.Minimum; - double max = this.Maximum; + var min = Minimum; + var max = Maximum; - if (value < this.Minimum) + if (value < Minimum) { throw new ArgumentOutOfRangeException( nameof(value), @@ -120,7 +88,7 @@ public virtual void SetValue(double value) $"Value must be greater than or equal to the minimum value {min}"); } - if (value > this.Maximum) + if (value > Maximum) { throw new ArgumentOutOfRangeException( nameof(value), @@ -128,13 +96,13 @@ public virtual void SetValue(double value) $"Value must be less than or equal to the maximum value {max}"); } - this.Click(); + Click(); - double currentValue = this.Value; + var currentValue = Value; while (Math.Abs(currentValue - value) > double.Epsilon) { - this.Element.SendKeys(currentValue < value ? Keys.ArrowRight : Keys.ArrowLeft); - currentValue = this.Value; + Element.SendKeys(currentValue < value ? Keys.ArrowRight : Keys.ArrowLeft); + currentValue = Value; } } -} \ No newline at end of file +} diff --git a/src/Legerity.Windows/Elements/Core/TextBlock.cs b/src/Legerity.Windows/Elements/Core/TextBlock.cs index b88333f1..30692975 100644 --- a/src/Legerity.Windows/Elements/Core/TextBlock.cs +++ b/src/Legerity.Windows/Elements/Core/TextBlock.cs @@ -1,12 +1,7 @@ namespace Legerity.Windows.Elements.Core; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; - /// -/// Defines a wrapper for the core UWP TextBlock control. +/// Defines a wrapper for the core UWP TextBlock control. /// public class TextBlock : WindowsElementWrapper { @@ -14,9 +9,9 @@ public class TextBlock : WindowsElementWrapper /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public TextBlock(WindowsElement element) + public TextBlock(WebElement element) : base(element) { } @@ -25,47 +20,19 @@ public TextBlock(WindowsElement element) /// Gets the text value of the text block. /// /// Thrown when an element is no longer valid in the document DOM. - public virtual string Text => this.Element.Text; + public virtual string Text => Element.Text; /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator TextBlock(WindowsElement element) + public static implicit operator TextBlock(WebElement element) { return new TextBlock(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator TextBlock(AppiumWebElement element) - { - return new TextBlock(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator TextBlock(RemoteWebElement element) - { - return new TextBlock(element as WindowsElement); - } -} \ No newline at end of file +} diff --git a/src/Legerity.Windows/Elements/Core/TextBox.cs b/src/Legerity.Windows/Elements/Core/TextBox.cs index 0eed2f88..866533f2 100644 --- a/src/Legerity.Windows/Elements/Core/TextBox.cs +++ b/src/Legerity.Windows/Elements/Core/TextBox.cs @@ -1,13 +1,9 @@ namespace Legerity.Windows.Elements.Core; -using Legerity.Windows.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; +using Extensions; /// -/// Defines a wrapper for the core UWP TextBox control. +/// Defines a wrapper for the core UWP TextBox control. /// public class TextBox : WindowsElementWrapper { @@ -15,9 +11,9 @@ public class TextBox : WindowsElementWrapper /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public TextBox(WindowsElement element) + public TextBox(WebElement element) : base(element) { } @@ -35,47 +31,19 @@ public TextBox(WindowsElement element) public virtual bool IsReadonly => this.IsReadonly(); /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator TextBox(WindowsElement element) + public static implicit operator TextBox(WebElement element) { return new TextBox(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator TextBox(AppiumWebElement element) - { - return new TextBox(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator TextBox(RemoteWebElement element) - { - return new TextBox(element as WindowsElement); - } - + /// /// Sets the text of the text box to the specified text. /// @@ -85,8 +53,8 @@ public static implicit operator TextBox(RemoteWebElement element) /// Thrown when an element is not visible. public virtual void SetText(string text) { - this.ClearText(); - this.AppendText(text); + ClearText(); + AppendText(text); } /// @@ -98,7 +66,7 @@ public virtual void SetText(string text) /// Thrown when an element is no longer valid in the document DOM. public virtual void AppendText(string text) { - this.Element.SendKeys(text); + Element.SendKeys(text); } /// @@ -107,6 +75,6 @@ public virtual void AppendText(string text) /// Thrown when an element is no longer valid in the document DOM. public virtual void ClearText() { - this.Element.Clear(); + Element.Clear(); } -} \ No newline at end of file +} diff --git a/src/Legerity.Windows/Elements/Core/TimePicker.cs b/src/Legerity.Windows/Elements/Core/TimePicker.cs index 9dd14089..614cdb95 100644 --- a/src/Legerity.Windows/Elements/Core/TimePicker.cs +++ b/src/Legerity.Windows/Elements/Core/TimePicker.cs @@ -1,13 +1,10 @@ namespace Legerity.Windows.Elements.Core; using System; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; +using Extensions; /// -/// Defines a wrapper for the core UWP TimePicker control. +/// Defines a wrapper for the core UWP TimePicker control. /// public class TimePicker : WindowsElementWrapper { @@ -15,55 +12,27 @@ public class TimePicker : WindowsElementWrapper /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public TimePicker(WindowsElement element) + public TimePicker(WebElement element) : base(element) { } /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator TimePicker(WindowsElement element) + public static implicit operator TimePicker(WebElement element) { return new TimePicker(element); } - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator TimePicker(AppiumWebElement element) - { - return new TimePicker(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator TimePicker(RemoteWebElement element) - { - return new TimePicker(element as WindowsElement); - } - /// /// Sets the time to the specified time. /// @@ -77,12 +46,12 @@ public static implicit operator TimePicker(RemoteWebElement element) public virtual void SetTime(TimeSpan time) { // Taps the time picker to show the popup. - this.Click(); + Click(); // Finds the popup and changes the time. - WindowsElement popup = this.Driver.FindElement(WindowsByExtras.AutomationId("TimePickerFlyoutPresenter")); + var popup = Driver.FindElement(WindowsByExtras.AutomationId("TimePickerFlyoutPresenter")); popup.FindElement(WindowsByExtras.AutomationId("HourLoopingSelector")).FindElementByName(time.ToString("%h")).Click(); popup.FindElement(WindowsByExtras.AutomationId("MinuteLoopingSelector")).FindElementByName(time.ToString("mm")).Click(); popup.FindElement(WindowsByExtras.AutomationId("AcceptButton")).Click(); } -} \ No newline at end of file +} diff --git a/src/Legerity.Windows/Elements/Core/ToggleButton.cs b/src/Legerity.Windows/Elements/Core/ToggleButton.cs index 269e27a1..b4cc1c00 100644 --- a/src/Legerity.Windows/Elements/Core/ToggleButton.cs +++ b/src/Legerity.Windows/Elements/Core/ToggleButton.cs @@ -1,13 +1,9 @@ namespace Legerity.Windows.Elements.Core; -using Legerity.Windows.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; +using Extensions; /// -/// Defines a wrapper for the core UWP ToggleButton control. +/// Defines a wrapper for the core UWP ToggleButton control. /// public class ToggleButton : Button { @@ -15,9 +11,9 @@ public class ToggleButton : Button /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public ToggleButton(WindowsElement element) + public ToggleButton(WebElement element) : base(element) { } @@ -29,47 +25,19 @@ public ToggleButton(WindowsElement element) public virtual bool IsOn => this.GetToggleState() == ToggleState.Checked; /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator ToggleButton(WindowsElement element) + public static implicit operator ToggleButton(WebElement element) { return new ToggleButton(element); } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator ToggleButton(AppiumWebElement element) - { - return new ToggleButton(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator ToggleButton(RemoteWebElement element) - { - return new ToggleButton(element as WindowsElement); - } - + /// /// Toggles the button on. /// @@ -78,12 +46,12 @@ public static implicit operator ToggleButton(RemoteWebElement element) /// Thrown when an element is no longer valid in the document DOM. public virtual void ToggleOn() { - if (this.IsOn) + if (IsOn) { return; } - this.Click(); + Click(); } /// @@ -94,11 +62,11 @@ public virtual void ToggleOn() /// Thrown when an element is no longer valid in the document DOM. public virtual void ToggleOff() { - if (!this.IsOn) + if (!IsOn) { return; } - this.Click(); + Click(); } -} \ No newline at end of file +} diff --git a/src/Legerity.Windows/Elements/Core/ToggleState.cs b/src/Legerity.Windows/Elements/Core/ToggleState.cs index 76395d52..6010e772 100644 --- a/src/Legerity.Windows/Elements/Core/ToggleState.cs +++ b/src/Legerity.Windows/Elements/Core/ToggleState.cs @@ -19,4 +19,4 @@ public enum ToggleState /// The toggle is indeterminate. /// Indeterminate = 2, -} \ No newline at end of file +} diff --git a/src/Legerity.Windows/Elements/Core/ToggleSwitch.cs b/src/Legerity.Windows/Elements/Core/ToggleSwitch.cs index 04dd72b7..4b9a2417 100644 --- a/src/Legerity.Windows/Elements/Core/ToggleSwitch.cs +++ b/src/Legerity.Windows/Elements/Core/ToggleSwitch.cs @@ -1,13 +1,9 @@ namespace Legerity.Windows.Elements.Core; -using Legerity.Windows.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; +using Extensions; /// -/// Defines a wrapper for the core UWP ToggleSwitch control. +/// Defines a wrapper for the core UWP ToggleSwitch control. /// public class ToggleSwitch : WindowsElementWrapper { @@ -15,9 +11,9 @@ public class ToggleSwitch : WindowsElementWrapper /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public ToggleSwitch(WindowsElement element) + public ToggleSwitch(WebElement element) : base(element) { } @@ -29,47 +25,19 @@ public ToggleSwitch(WindowsElement element) public virtual bool IsOn => this.GetToggleState() == ToggleState.Checked; /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator ToggleSwitch(WindowsElement element) + public static implicit operator ToggleSwitch(WebElement element) { return new ToggleSwitch(element); } - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator ToggleSwitch(AppiumWebElement element) - { - return new ToggleSwitch(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator ToggleSwitch(RemoteWebElement element) - { - return new ToggleSwitch(element as WindowsElement); - } - /// /// Toggles the switch on. /// @@ -78,12 +46,12 @@ public static implicit operator ToggleSwitch(RemoteWebElement element) /// Thrown when an element is no longer valid in the document DOM. public virtual void ToggleOn() { - if (this.IsOn) + if (IsOn) { return; } - this.Click(); + Click(); } /// @@ -94,11 +62,11 @@ public virtual void ToggleOn() /// Thrown when an element is no longer valid in the document DOM. public virtual void ToggleOff() { - if (!this.IsOn) + if (!IsOn) { return; } - this.Click(); + Click(); } -} \ No newline at end of file +} diff --git a/src/Legerity.Windows/Elements/WindowsElementWrapper.cs b/src/Legerity.Windows/Elements/WindowsElementWrapper.cs index 2d60aa21..54d2be2b 100644 --- a/src/Legerity.Windows/Elements/WindowsElementWrapper.cs +++ b/src/Legerity.Windows/Elements/WindowsElementWrapper.cs @@ -3,24 +3,18 @@ namespace Legerity.Windows.Elements; using System; using Legerity.Exceptions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; -using OpenQA.Selenium.Support.UI; - /// -/// Defines an element wrapper for a . +/// Defines an element wrapper for a Windows . /// -public class WindowsElementWrapper : ElementWrapper +public class WindowsElementWrapper : ElementWrapper { /// /// Initializes a new instance of the class. /// /// - /// The reference. + /// The reference. /// - public WindowsElementWrapper(WindowsElement element) + public WindowsElementWrapper(WebElement element) : base(element) { } @@ -28,50 +22,22 @@ public WindowsElementWrapper(WindowsElement element) /// /// Gets the instance of the Appium driver for the Windows application. /// - public WindowsDriver Driver => this.ElementDriver as WindowsDriver; + public WindowsDriver Driver => ElementDriver as WindowsDriver; /// - /// Allows conversion of a to the without direct casting. + /// Allows conversion of a to the without direct casting. /// /// - /// The . + /// The . /// /// /// The . /// - public static implicit operator WindowsElementWrapper(WindowsElement element) + public static implicit operator WindowsElementWrapper(WebElement element) { return new WindowsElementWrapper(element); } - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator WindowsElementWrapper(AppiumWebElement element) - { - return new WindowsElementWrapper(element as WindowsElement); - } - - /// - /// Allows conversion of a to the without direct casting. - /// - /// - /// The . - /// - /// - /// The . - /// - public static implicit operator WindowsElementWrapper(RemoteWebElement element) - { - return new WindowsElementWrapper(element as WindowsElement); - } - /// /// Determines whether the specified element is shown with the specified timeout. /// @@ -87,7 +53,7 @@ protected void VerifyDriverElementShown(By locator, TimeSpan? timeout) { try { - if (this.Driver.FindElement(locator) == null) + if (Driver.FindElement(locator) == null) { throw new ElementNotShownException(locator.ToString()); } @@ -99,7 +65,7 @@ protected void VerifyDriverElementShown(By locator, TimeSpan? timeout) } else { - var wait = new WebDriverWait(this.Driver, timeout.Value); + var wait = new WebDriverWait(Driver, timeout.Value); wait.Until(driver => driver.FindElement(locator) != null); } } @@ -118,15 +84,15 @@ protected void VerifyDriverElementsShown(By locator, TimeSpan? timeout) { if (timeout == null) { - if (this.Driver.FindElements(locator).Count == 0) + if (Driver.FindElements(locator).Count == 0) { throw new ElementsNotShownException(locator.ToString()); } } else { - var wait = new WebDriverWait(this.Driver, timeout.Value); + var wait = new WebDriverWait(Driver, timeout.Value); wait.Until(driver => driver.FindElements(locator).Count != 0); } } -} \ No newline at end of file +} diff --git a/src/Legerity.Windows/Extensions/AttributeExtensions.cs b/src/Legerity.Windows/Extensions/AttributeExtensions.cs index 165406e9..788c390e 100644 --- a/src/Legerity.Windows/Extensions/AttributeExtensions.cs +++ b/src/Legerity.Windows/Extensions/AttributeExtensions.cs @@ -1,9 +1,7 @@ namespace Legerity.Windows.Extensions; using System; -using Legerity.Windows.Elements.Core; -using OpenQA.Selenium; -using OpenQA.Selenium.Remote; +using Elements.Core; /// /// Defines a collection of extensions for retrieving element attributes. @@ -25,7 +23,7 @@ public static string GetAutomationId(this IWebElement element) /// Retrieves the AutomationId attribute from the specified element. /// /// - /// The type of . + /// The type of . /// /// The to retrieve an AutomationId from. /// The AutomationId of the element. @@ -51,7 +49,7 @@ public static string GetHelpText(this IWebElement element) /// Retrieves the HelpText attribute from the specified element. /// /// - /// The type of . + /// The type of . /// /// The to retrieve the HelpText from. /// The HelpText of the element. @@ -77,7 +75,7 @@ public static string GetValue(this IWebElement element) /// Retrieves the Value.Value attribute from the specified element. /// /// - /// The type of . + /// The type of . /// /// The to retrieve a value from. /// The value of the element. @@ -103,7 +101,7 @@ public static bool IsReadonly(this IWebElement element) /// Retrieves the Value.IsReadonly attribute from the specified element. /// /// - /// The type of . + /// The type of . /// /// The to retrieve the readonly state from. /// A value indicating whether the item is readonly. @@ -134,7 +132,7 @@ public static ToggleState GetToggleState(this IWebElement element) /// Retrieves the Toggle.ToggleState attribute from the specified element. /// /// - /// The type of . + /// The type of . /// /// The to retrieve a toggle state from. /// The of the element. @@ -161,7 +159,7 @@ public static bool IsSelected(this IWebElement element) /// Retrieves the SelectionItem.IsSelected attribute from the specified element. /// /// - /// The type of . + /// The type of . /// /// The to retrieve the selected state from. /// A value indicating whether the item is selected. @@ -187,7 +185,7 @@ public static double GetRangeValue(this IWebElement element) /// Retrieves the RangeValue.Value attribute from the specified element. /// /// - /// The type of . + /// The type of . /// /// The to retrieve the range value from. /// The range value of the element. @@ -213,7 +211,7 @@ public static double GetRangeMaximum(this IWebElement element) /// Retrieves the RangeValue.Maximum attribute from the specified element. /// /// - /// The type of . + /// The type of . /// /// The to retrieve the range max value from. /// The range max value of the element. @@ -239,7 +237,7 @@ public static double GetRangeMinimum(this IWebElement element) /// Retrieves the RangeValue.Minimum attribute from the specified element. /// /// - /// The type of . + /// The type of . /// /// The to retrieve the range min value from. /// The range min value of the element. @@ -265,7 +263,7 @@ public static double GetRangeSmallChange(this IWebElement element) /// Retrieves the RangeValue.SmallChange attribute from the specified element. /// /// - /// The type of . + /// The type of . /// /// The to retrieve the range step value from. /// The range step value of the element. @@ -291,7 +289,7 @@ public static bool IsRangeReadonly(this IWebElement element) /// Retrieves the RangeValue.IsReadOnly attribute from the specified element. /// /// - /// The type of . + /// The type of . /// /// The to retrieve the readonly state from. /// A value indicating whether the item is readonly. @@ -301,4 +299,4 @@ public static bool IsRangeReadonly(this IElementWrapper elem { return IsRangeReadonly(element.Element); } -} \ No newline at end of file +} diff --git a/src/Legerity.Windows/Extensions/ElementExtensions.cs b/src/Legerity.Windows/Extensions/ElementExtensions.cs new file mode 100644 index 00000000..53fe7d71 --- /dev/null +++ b/src/Legerity.Windows/Extensions/ElementExtensions.cs @@ -0,0 +1,18 @@ +namespace Legerity.Windows.Extensions; + +using System.Collections.Generic; +using System.Linq; + +public static class ElementExtensions +{ + /// Thrown when no element matches the expected locator. + public static WebElement FindElementByName(this IWebElement element, string name) + { + return element.FindElement(By.Name(name)) as WebElement; + } + + public static IEnumerable FindElementsByClassName(this IWebElement element, string className) + { + return element.FindElements(By.ClassName(className)).Cast(); + } +} diff --git a/src/Legerity.Windows/Extensions/LegerityTestClassExtensions.cs b/src/Legerity.Windows/Extensions/LegerityTestClassExtensions.cs index cdebcd6a..e75c5cd4 100644 --- a/src/Legerity.Windows/Extensions/LegerityTestClassExtensions.cs +++ b/src/Legerity.Windows/Extensions/LegerityTestClassExtensions.cs @@ -2,8 +2,6 @@ namespace Legerity.Windows.Extensions; using System; using Legerity.Exceptions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium.Windows; /// /// Defines a collection of extensions for instances. @@ -32,13 +30,13 @@ public static class LegerityTestClassExtensions /// - The WinAppDriver could not be found when running with true. /// - The WinAppDriver failed to load when running with true. /// - public static WindowsDriver StartWindowsApp( + public static WindowsDriver StartWindowsApp( this LegerityTestClass testClass, Func waitUntil = default, TimeSpan? waitUntilTimeout = default, int waitUntilRetries = 0) { - return testClass.StartApp(waitUntil, waitUntilTimeout, waitUntilRetries) as WindowsDriver; + return testClass.StartApp(waitUntil, waitUntilTimeout, waitUntilRetries) as WindowsDriver; } /// @@ -68,7 +66,7 @@ public static WindowsDriver StartWindowsApp( /// - The WinAppDriver failed to load when running with true. /// /// Thrown when the wait until condition is not met in the allocated timeout period if provided. - public static WindowsDriver StartWindowsApp( + public static WindowsDriver StartWindowsApp( this LegerityTestClass testClass, WindowsAppManagerOptions options, Func waitUntil = default, @@ -76,6 +74,6 @@ public static WindowsDriver StartWindowsApp( int waitUntilRetries = 0) { return testClass.StartApp(options, waitUntil, waitUntilTimeout, waitUntilRetries) as - WindowsDriver; + WindowsDriver; } -} \ No newline at end of file +} diff --git a/src/Legerity.Windows/Extensions/WindowsElementExtensions.cs b/src/Legerity.Windows/Extensions/WindowsElementExtensions.cs index 39809d77..c1e9442a 100644 --- a/src/Legerity.Windows/Extensions/WindowsElementExtensions.cs +++ b/src/Legerity.Windows/Extensions/WindowsElementExtensions.cs @@ -3,30 +3,23 @@ namespace Legerity.Windows.Extensions; using System; using System.Globalization; using Legerity.Extensions; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; /// -/// Defines a collection of extensions for objects. +/// Defines a collection of extensions for objects. /// public static class WindowsElementExtensions { /// /// Finds an element within the with the given . /// - /// - /// The type of . For this method, this would likely be . - /// - /// The to search. + /// The to search. /// The automation ID associated with the element to locate. - /// The located . + /// The located . /// Thrown when no element matches the expected locator. /// Thrown when the is null. - public static TElement FindElementByAutomationId( - this WindowsDriver driver, + public static WebElement FindElementByAutomationId( + this WindowsDriver driver, string automationId) - where TElement : IWebElement { return driver.FindElement(WindowsByExtras.AutomationId(automationId)); } @@ -36,12 +29,12 @@ public static TElement FindElementByAutomationId( /// /// The element to search. /// The automation ID associated with the element to locate. - /// The located . + /// The located . /// Thrown when no element matches the expected locator. /// Thrown when the is null. - public static AppiumWebElement FindElementByAutomationId(this WindowsElement element, string automationId) + public static WebElement FindElementByAutomationId(this WebElement element, string automationId) { - return element.FindElement(WindowsByExtras.AutomationId(automationId)); + return element.FindElement(WindowsByExtras.AutomationId(automationId)) as WebElement; } /// @@ -57,41 +50,17 @@ public static AppiumWebElement FindElementByAutomationId(this WindowsElement ele /// True if the element's name or AutomationId matches; otherwise, false. /// /// Thrown when an element is no longer valid in the document DOM. - public static bool VerifyNameOrAutomationIdEquals(this AppiumWebElement element, string compare) + public static bool VerifyNameOrAutomationIdEquals(this WebElement element, string compare) { - string name = element.GetName(); - string automationId = element.GetAutomationId(); + var name = element.GetName(); + var automationId = element.GetAutomationId(); return string.Equals(compare, name, StringComparison.CurrentCultureIgnoreCase) || string.Equals( compare, automationId, StringComparison.CurrentCultureIgnoreCase); } - - /// - /// Verifies the elements name or AutomationId based on the given compare. - /// - /// - /// The element to verify. - /// - /// - /// The value to verify is the name or AutomationId. - /// - /// - /// True if the element's name or AutomationId matches; otherwise, false. - /// - /// Thrown when an element is no longer valid in the document DOM. - public static bool VerifyNameOrAutomationIdEquals(this WindowsElement element, string compare) - { - string name = element.GetName(); - string automationId = element.GetAutomationId(); - - return string.Equals(compare, name, StringComparison.CurrentCultureIgnoreCase) || string.Equals( - compare, - automationId, - StringComparison.CurrentCultureIgnoreCase); - } - + /// /// Verifies the elements name or AutomationId based on the given partial compare. /// @@ -103,28 +72,12 @@ public static bool VerifyNameOrAutomationIdEquals(this WindowsElement element, s /// True if the element's name or AutomationId matches; otherwise, false. /// /// Thrown when an element is no longer valid in the document DOM. - public static bool VerifyNameOrAutomationIdContains(this AppiumWebElement element, string partialCompare) - { - string name = element.GetName(); - string automationId = element.GetAutomationId(); - - return name.Contains(partialCompare, CultureInfo.CurrentCulture, CompareOptions.IgnoreCase) || - automationId.Contains(partialCompare, CultureInfo.CurrentCulture, CompareOptions.IgnoreCase); - } - - /// - /// Verifies the elements name or AutomationId based on the given partial compare. - /// - /// The element to verify. - /// The partial value to verify is the name or AutomationId. - /// True if the element's name or AutomationId partially matches; otherwise, false. - /// Thrown when an element is no longer valid in the document DOM. - public static bool VerifyNameOrAutomationIdContains(this WindowsElement element, string partialCompare) + public static bool VerifyNameOrAutomationIdContains(this WebElement element, string partialCompare) { - string name = element.GetName(); - string automationId = element.GetAutomationId(); + var name = element.GetName(); + var automationId = element.GetAutomationId(); return name.Contains(partialCompare, CultureInfo.CurrentCulture, CompareOptions.IgnoreCase) || automationId.Contains(partialCompare, CultureInfo.CurrentCulture, CompareOptions.IgnoreCase); } -} \ No newline at end of file +} diff --git a/src/Legerity.Windows/Extensions/WindowsElementWrapperExtensions.cs b/src/Legerity.Windows/Extensions/WindowsElementWrapperExtensions.cs index 5c592255..3d3244c0 100644 --- a/src/Legerity.Windows/Extensions/WindowsElementWrapperExtensions.cs +++ b/src/Legerity.Windows/Extensions/WindowsElementWrapperExtensions.cs @@ -1,9 +1,7 @@ namespace Legerity.Windows.Extensions; using System; -using Legerity.Windows.Elements; -using OpenQA.Selenium; -using OpenQA.Selenium.Support.UI; +using Elements; /// /// Defines a collection of extensions for objects. @@ -86,4 +84,4 @@ public static TResult WaitUntil( return WaitUntil(element, condition, timeout, retries - 1); } } -} \ No newline at end of file +} diff --git a/src/Legerity.Windows/GlobalUsings.cs b/src/Legerity.Windows/GlobalUsings.cs new file mode 100644 index 00000000..9f175fce --- /dev/null +++ b/src/Legerity.Windows/GlobalUsings.cs @@ -0,0 +1,6 @@ +// Global using directives + +global using OpenQA.Selenium; +global using OpenQA.Selenium.Appium; +global using OpenQA.Selenium.Appium.Windows; +global using OpenQA.Selenium.Support.UI; diff --git a/src/Legerity.Windows/Legerity.Windows.csproj b/src/Legerity.Windows/Legerity.Windows.csproj index 003bec6b..7f5de98d 100644 --- a/src/Legerity.Windows/Legerity.Windows.csproj +++ b/src/Legerity.Windows/Legerity.Windows.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + net6.0;net7.0;net8.0 true Legerity for Windows - Framework for UI testing with Selenium/Appium @@ -42,7 +42,7 @@ - + diff --git a/src/Legerity.Windows/WindowsByExtras.cs b/src/Legerity.Windows/WindowsByExtras.cs index 32005689..5e52bdf8 100644 --- a/src/Legerity.Windows/WindowsByExtras.cs +++ b/src/Legerity.Windows/WindowsByExtras.cs @@ -1,7 +1,6 @@ namespace Legerity.Windows; using System; -using OpenQA.Selenium; /// /// Defines a collection of extra locator constraints for . @@ -27,4 +26,4 @@ public static By AutomationId(string automationId) return By.XPath($".//*[@AutomationId='{automationId}']"); } -} \ No newline at end of file +} diff --git a/src/Legerity.sln.DotSettings b/src/Legerity.sln.DotSettings new file mode 100644 index 00000000..472a1858 --- /dev/null +++ b/src/Legerity.sln.DotSettings @@ -0,0 +1,4 @@ + + True + True + True \ No newline at end of file diff --git a/src/Legerity/Legerity.csproj b/src/Legerity/Legerity.csproj index b16af06e..df23df5e 100644 --- a/src/Legerity/Legerity.csproj +++ b/src/Legerity/Legerity.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + net6.0;net7.0;net8.0 true Legerity - Framework for UI testing with Selenium/Appium @@ -16,7 +16,7 @@ - + diff --git a/tests/Legerity.Core.Tests/GlobalUsings.cs b/tests/Legerity.Core.Tests/GlobalUsings.cs index 2ac570eb..45803334 100644 --- a/tests/Legerity.Core.Tests/GlobalUsings.cs +++ b/tests/Legerity.Core.Tests/GlobalUsings.cs @@ -1,6 +1,3 @@ // Global using directives -global using Legerity; -global using Legerity.Pages; -global using Legerity.Web; -global using NUnit.Framework; \ No newline at end of file +global using NUnit.Framework; diff --git a/tests/Legerity.Core.Tests/Legerity.Core.Tests.csproj b/tests/Legerity.Core.Tests/Legerity.Core.Tests.csproj index a1534071..162214d8 100644 --- a/tests/Legerity.Core.Tests/Legerity.Core.Tests.csproj +++ b/tests/Legerity.Core.Tests/Legerity.Core.Tests.csproj @@ -1,16 +1,18 @@ - net6.0 + net6.0;net7.0;net8.0 false - + - + + + diff --git a/tests/Legerity.Core.Tests/Pages/W3SchoolsPage.cs b/tests/Legerity.Core.Tests/Pages/W3SchoolsPage.cs index a90c2a66..e7bbac7f 100644 --- a/tests/Legerity.Core.Tests/Pages/W3SchoolsPage.cs +++ b/tests/Legerity.Core.Tests/Pages/W3SchoolsPage.cs @@ -1,38 +1,39 @@ -namespace Legerity.Core.Tests.Pages; - +using Legerity.Core.Tests.Tests; using Legerity.Extensions; +using Legerity.Pages; using Legerity.Web.Elements.Core; using OpenQA.Selenium; -using OpenQA.Selenium.Remote; -using Tests; + +namespace Legerity.Core.Tests.Pages; + internal class W3SchoolsPage : BasePage { - private readonly By contentFrameLocator = By.Id("iframeResult"); - private readonly By acceptCookiesButtonLocator = By.Id("accept-choices"); + private readonly By _contentFrameLocator = By.Id("iframeResult"); + private readonly By _acceptCookiesButtonLocator = By.Id("accept-choices"); - public W3SchoolsPage(RemoteWebDriver app) + public W3SchoolsPage(WebDriver app) : base(app, BaseTestClass.ImplicitWait) { } - protected override By Trait => this.contentFrameLocator; + protected override By Trait => _contentFrameLocator; - public Button AcceptCookiesButton => this.FindElement(this.acceptCookiesButtonLocator); + public Button AcceptCookiesButton => FindElement(_acceptCookiesButtonLocator); - public RemoteWebElement ContentFrame => this.FindElement(this.contentFrameLocator); + public WebElement ContentFrame => FindElement(_contentFrameLocator); public T AcceptCookies() where T : W3SchoolsPage { - this.WaitUntil(page => page.AcceptCookiesButton.IsVisible, this.WaitTimeout); - this.AcceptCookiesButton.Click(); + this.WaitUntil(page => page.AcceptCookiesButton.IsVisible, WaitTimeout); + AcceptCookiesButton.Click(); return (T)this; } public T SwitchToContentFrame() where T : W3SchoolsPage { - this.WaitUntil(page => page.ContentFrame.Displayed, this.WaitTimeout); - this.App.SwitchTo().Frame(this.ContentFrame); + this.WaitUntil(page => page.ContentFrame.Displayed, WaitTimeout); + App.SwitchTo().Frame(ContentFrame); return (T)this; } -} \ No newline at end of file +} diff --git a/tests/Legerity.Core.Tests/Tests/BaseTestClass.cs b/tests/Legerity.Core.Tests/Tests/BaseTestClass.cs index d527ad11..9b4e3c21 100644 --- a/tests/Legerity.Core.Tests/Tests/BaseTestClass.cs +++ b/tests/Legerity.Core.Tests/Tests/BaseTestClass.cs @@ -1,3 +1,4 @@ +using System; using System.Diagnostics.CodeAnalysis; [assembly: LevelOfParallelism(5)] @@ -5,9 +6,6 @@ namespace Legerity.Core.Tests.Tests; -using System; -using Legerity; - /// /// Defines the base test class for setting up and running UI tests. /// @@ -57,6 +55,6 @@ public virtual void Cleanup() public virtual void FinalCleanup() { // Ensures that any running app driver instances being tracked are stopped. - this.StopApps(); + StopApps(); } -} \ No newline at end of file +} diff --git a/tests/Legerity.Core.Tests/Tests/ByAllTests.cs b/tests/Legerity.Core.Tests/Tests/ByAllTests.cs index 3a430d93..b4ac9931 100644 --- a/tests/Legerity.Core.Tests/Tests/ByAllTests.cs +++ b/tests/Legerity.Core.Tests/Tests/ByAllTests.cs @@ -1,14 +1,13 @@ -namespace Legerity.Core.Tests.Tests; - using System; -using System.Collections.ObjectModel; using System.IO; +using Legerity.Core.Tests.Pages; +using Legerity.Web; using OpenQA.Selenium; using OpenQA.Selenium.Chrome; -using OpenQA.Selenium.Remote; -using Pages; using Shouldly; +namespace Legerity.Core.Tests.Tests; + [TestFixture] [Parallelizable(ParallelScope.All)] internal class ByAllTests : BaseTestClass @@ -26,14 +25,14 @@ public void ShouldFindElementByAll() DriverOptions = new ChromeOptions() }; - RemoteWebDriver app = this.StartApp(options); + var app = StartApp(options); - W3SchoolsPage page = new W3SchoolsPage(app) + var page = new W3SchoolsPage(app) .AcceptCookies() .SwitchToContentFrame(); // Act - RemoteWebElement element = page.FindElement(new ByAll(By.TagName("p"), ByExtras.PartialText("Please select"))); + var element = page.FindElement(new ByAll(By.TagName("p"), ByExtras.PartialText("Please select"))); // Assert element.ShouldNotBeNull(); @@ -53,14 +52,14 @@ public void ShouldFindElementsByAll() DriverOptions = new ChromeOptions() }; - RemoteWebDriver app = this.StartApp(options); + var app = StartApp(options); - W3SchoolsPage page = new W3SchoolsPage(app) + var page = new W3SchoolsPage(app) .AcceptCookies() .SwitchToContentFrame(); // Act - ReadOnlyCollection elements = + var elements = page.FindElements(new ByAll(By.TagName("p"), ByExtras.PartialText("Please select"))); // Assert @@ -81,9 +80,9 @@ public void ShouldThrowNoSuchElementExceptionIfFindElementReturnsNoResult() DriverOptions = new ChromeOptions() }; - RemoteWebDriver app = this.StartApp(options); + var app = StartApp(options); - W3SchoolsPage page = new W3SchoolsPage(app) + var page = new W3SchoolsPage(app) .AcceptCookies() .SwitchToContentFrame(); @@ -105,18 +104,18 @@ public void ShouldReturnEmptyCollectionIfFindElementsReturnsNoResult() DriverOptions = new ChromeOptions() }; - RemoteWebDriver app = this.StartApp(options); + var app = StartApp(options); - W3SchoolsPage page = new W3SchoolsPage(app) + var page = new W3SchoolsPage(app) .AcceptCookies() .SwitchToContentFrame(); // Act - ReadOnlyCollection elements = + var elements = page.FindElements(new ByAll(By.TagName("p"), ByExtras.PartialText("This text does not exist"))); // Assert elements.ShouldNotBeNull(); elements.Count.ShouldBe(0); } -} \ No newline at end of file +} diff --git a/tests/Legerity.Core.Tests/Tests/ByNestedTests.cs b/tests/Legerity.Core.Tests/Tests/ByNestedTests.cs index 86056c67..a133ff82 100644 --- a/tests/Legerity.Core.Tests/Tests/ByNestedTests.cs +++ b/tests/Legerity.Core.Tests/Tests/ByNestedTests.cs @@ -1,14 +1,13 @@ -namespace Legerity.Core.Tests.Tests; - using System; -using System.Collections.ObjectModel; using System.IO; using Legerity.Core.Tests.Pages; +using Legerity.Web; +using Legerity.Web.Extensions; using OpenQA.Selenium; using OpenQA.Selenium.Chrome; -using OpenQA.Selenium.Remote; using Shouldly; -using Web.Extensions; + +namespace Legerity.Core.Tests.Tests; [TestFixture] [Parallelizable(ParallelScope.All)] @@ -27,14 +26,14 @@ public void ShouldFindElementByNested() DriverOptions = new ChromeOptions() }; - RemoteWebDriver app = this.StartApp(options); + var app = StartApp(options); - W3SchoolsPage page = new W3SchoolsPage(app) + var page = new W3SchoolsPage(app) .AcceptCookies() .SwitchToContentFrame(); // Act - RemoteWebElement element = page.FindElement(new ByNested(By.TagName("form"), By.TagName("input"))); + var element = page.FindElement(new ByNested(By.TagName("form"), By.TagName("input"))); // Assert element.ShouldNotBeNull(); @@ -54,14 +53,14 @@ public void ShouldFindElementsByNested() DriverOptions = new ChromeOptions() }; - RemoteWebDriver app = this.StartApp(options); + var app = StartApp(options); - W3SchoolsPage page = new W3SchoolsPage(app) + var page = new W3SchoolsPage(app) .AcceptCookies() .SwitchToContentFrame(); // Act - ReadOnlyCollection elements = + var elements = page.FindElements(new ByNested(By.TagName("form"), WebByExtras.InputType("radio"))); // Assert @@ -81,9 +80,9 @@ public void ShouldThrowNoSuchElementExceptionIfFindElementReturnsNoResult() DriverOptions = new ChromeOptions() }; - RemoteWebDriver app = this.StartApp(options); + var app = StartApp(options); - W3SchoolsPage page = new W3SchoolsPage(app) + var page = new W3SchoolsPage(app) .AcceptCookies() .SwitchToContentFrame(); @@ -105,18 +104,18 @@ public void ShouldReturnEmptyCollectionIfFindElementsReturnsNoResult() DriverOptions = new ChromeOptions() }; - RemoteWebDriver app = this.StartApp(options); + var app = StartApp(options); - W3SchoolsPage page = new W3SchoolsPage(app) + var page = new W3SchoolsPage(app) .AcceptCookies() .SwitchToContentFrame(); // Act - ReadOnlyCollection elements = + var elements = page.FindElements(new ByNested(By.TagName("form"), By.TagName("div"))); // Assert elements.ShouldNotBeNull(); elements.Count.ShouldBe(0); } -} \ No newline at end of file +} diff --git a/tests/Legerity.Core.Tests/Tests/WaitUntilElementIsNotVisibleTests.cs b/tests/Legerity.Core.Tests/Tests/WaitUntilElementIsNotVisibleTests.cs index d535ec84..32621b83 100644 --- a/tests/Legerity.Core.Tests/Tests/WaitUntilElementIsNotVisibleTests.cs +++ b/tests/Legerity.Core.Tests/Tests/WaitUntilElementIsNotVisibleTests.cs @@ -1,14 +1,14 @@ -namespace Legerity.Core.Tests.Tests; - using System; using System.IO; -using Extensions; -using Helpers; +using Legerity.Core.Tests.Pages; +using Legerity.Extensions; +using Legerity.Helpers; +using Legerity.Web; +using Legerity.Web.Elements.Core; using OpenQA.Selenium; using OpenQA.Selenium.Chrome; -using OpenQA.Selenium.Remote; -using Pages; -using Web.Elements.Core; + +namespace Legerity.Core.Tests.Tests; [TestFixture] [Parallelizable(ParallelScope.All)] @@ -27,7 +27,7 @@ public void ShouldWaitUntilElementIsNotVisible() DriverOptions = new ChromeOptions() }; - RemoteWebDriver app = this.StartApp(options); + var app = StartApp(options); new W3SchoolsPage(app) .AcceptCookies() @@ -50,16 +50,16 @@ public void ShouldWaitUntilElementIsNotVisibleInElement() DriverOptions = new ChromeOptions() }; - RemoteWebDriver app = this.StartApp(options); + var app = StartApp(options); - W3SchoolsPage page = new W3SchoolsPage(app) + var page = new W3SchoolsPage(app) .AcceptCookies() .SwitchToContentFrame(); - RemoteWebElement element = page.FindElement(By.TagName("form")); + var element = page.FindElement(By.TagName("form")); // Act & Assert - element.WaitUntil(WaitUntilConditions.ElementIsNotVisibleInElement(By.TagName("select")), + element.WaitUntil(WaitUntilConditions.ElementIsNotVisibleInElement(By.TagName("select")), ImplicitWait); } @@ -76,16 +76,16 @@ public void ShouldWaitUntilElementIsNotVisibleInElementWrapper() DriverOptions = new ChromeOptions() }; - RemoteWebDriver app = this.StartApp(options); + var app = StartApp(options); - W3SchoolsPage page = new W3SchoolsPage(app) + var page = new W3SchoolsPage(app) .AcceptCookies() .SwitchToContentFrame(); Form form = page.FindElement(By.TagName("form")); // Act & Assert - form.WaitUntil(WaitUntilConditions.ElementIsNotVisibleInElementWrapper(By.TagName("select")), + form.WaitUntil(WaitUntilConditions.ElementIsNotVisibleInElementWrapper(By.TagName("select")), ImplicitWait); } @@ -102,13 +102,13 @@ public void ShouldWaitUntilElementIsNotVisibleInPageObject() DriverOptions = new ChromeOptions() }; - RemoteWebDriver app = this.StartApp(options); + var app = StartApp(options); - W3SchoolsPage page = new W3SchoolsPage(app) + var page = new W3SchoolsPage(app) .AcceptCookies() .SwitchToContentFrame(); // Act & Assert page.WaitUntil(WaitUntilConditions.ElementIsNotVisibleInPage(By.TagName("select")), ImplicitWait); } -} \ No newline at end of file +} diff --git a/tests/Legerity.Core.Tests/Tests/WaitUntilElementIsVisibleTests.cs b/tests/Legerity.Core.Tests/Tests/WaitUntilElementIsVisibleTests.cs index fb2cca47..6d55f941 100644 --- a/tests/Legerity.Core.Tests/Tests/WaitUntilElementIsVisibleTests.cs +++ b/tests/Legerity.Core.Tests/Tests/WaitUntilElementIsVisibleTests.cs @@ -1,14 +1,14 @@ -namespace Legerity.Core.Tests.Tests; - using System; using System.IO; -using Extensions; -using Helpers; +using Legerity.Core.Tests.Pages; +using Legerity.Extensions; +using Legerity.Helpers; +using Legerity.Web; +using Legerity.Web.Elements.Core; using OpenQA.Selenium; using OpenQA.Selenium.Chrome; -using OpenQA.Selenium.Remote; -using Pages; -using Web.Elements.Core; + +namespace Legerity.Core.Tests.Tests; [TestFixture] [Parallelizable(ParallelScope.All)] @@ -27,7 +27,7 @@ public void ShouldWaitUntilElementIsVisible() DriverOptions = new ChromeOptions() }; - RemoteWebDriver app = this.StartApp(options); + var app = StartApp(options); new W3SchoolsPage(app) .AcceptCookies() @@ -50,16 +50,16 @@ public void ShouldWaitUntilElementIsVisibleInElement() DriverOptions = new ChromeOptions() }; - RemoteWebDriver app = this.StartApp(options); + var app = StartApp(options); - W3SchoolsPage page = new W3SchoolsPage(app) + var page = new W3SchoolsPage(app) .AcceptCookies() .SwitchToContentFrame(); - RemoteWebElement element = page.FindElement(By.TagName("form")); + var element = page.FindElement(By.TagName("form")); // Act & Assert - element.WaitUntil(WaitUntilConditions.ElementIsVisibleInElement(By.TagName("input")), + element.WaitUntil(WaitUntilConditions.ElementIsVisibleInElement(By.TagName("input")), ImplicitWait); } @@ -76,16 +76,16 @@ public void ShouldWaitUntilElementIsVisibleInElementWrapper() DriverOptions = new ChromeOptions() }; - RemoteWebDriver app = this.StartApp(options); + var app = StartApp(options); - W3SchoolsPage page = new W3SchoolsPage(app) + var page = new W3SchoolsPage(app) .AcceptCookies() .SwitchToContentFrame(); Form form = page.FindElement(By.TagName("form")); // Act & Assert - form.WaitUntil(WaitUntilConditions.ElementIsVisibleInElementWrapper(By.TagName("input")), + form.WaitUntil(WaitUntilConditions.ElementIsVisibleInElementWrapper(By.TagName("input")), ImplicitWait); } @@ -102,13 +102,13 @@ public void ShouldWaitUntilElementIsVisibleInPageObject() DriverOptions = new ChromeOptions() }; - RemoteWebDriver app = this.StartApp(options); + var app = StartApp(options); - W3SchoolsPage page = new W3SchoolsPage(app) + var page = new W3SchoolsPage(app) .AcceptCookies() .SwitchToContentFrame(); // Act & Assert page.WaitUntil(WaitUntilConditions.ElementIsVisibleInPage(By.TagName("input")), ImplicitWait); } -} \ No newline at end of file +} diff --git a/tests/Legerity.Core.Tests/Tests/WebAppManagerOptionsTests.cs b/tests/Legerity.Core.Tests/Tests/WebAppManagerOptionsTests.cs index 825cec95..804bb16f 100644 --- a/tests/Legerity.Core.Tests/Tests/WebAppManagerOptionsTests.cs +++ b/tests/Legerity.Core.Tests/Tests/WebAppManagerOptionsTests.cs @@ -1,34 +1,35 @@ -namespace Legerity.Core.Tests.Tests; - using System; using System.Drawing; using System.IO; -using OpenQA.Selenium.Chrome; -using OpenQA.Selenium.Remote; +using Legerity.Web; using Shouldly; +namespace Legerity.Core.Tests.Tests; + [TestFixture] [Parallelizable(ParallelScope.All)] internal class WebAppManagerOptionsTests : BaseTestClass { - [Test] - public void ShouldLaunchBrowserAtDesiredSize() + [TestCase(WebAppDriverType.Chrome)] + [TestCase(WebAppDriverType.Firefox)] + [TestCase(WebAppDriverType.Opera)] + public void ShouldLaunchBrowserAtDesiredSize(WebAppDriverType driverType) { // Arrange var options = new WebAppManagerOptions( - WebAppDriverType.Chrome, + driverType, Path.Combine(Environment.CurrentDirectory)) { DesiredSize = new Size(1280, 800), Url = "https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_input_type_radio", - ImplicitWait = ImplicitWait, - DriverOptions = new ChromeOptions() + ImplicitWait = ImplicitWait }; - + // Act - RemoteWebDriver app = this.StartApp(options); + var app = StartApp(options); // Assert - app.Manage().Window.Size.ShouldBe(options.DesiredSize); + var size = app.Manage().Window.Size; + size.ShouldBe(options.DesiredSize); } -} \ No newline at end of file +} diff --git a/tests/Legerity.Telerik.Uwp.Tests/GlobalUsings.cs b/tests/Legerity.Telerik.Uwp.Tests/GlobalUsings.cs index 4ee19433..45803334 100644 --- a/tests/Legerity.Telerik.Uwp.Tests/GlobalUsings.cs +++ b/tests/Legerity.Telerik.Uwp.Tests/GlobalUsings.cs @@ -1,6 +1,3 @@ // Global using directives -global using Legerity; -global using Legerity.Pages; -global using Legerity.Windows; -global using NUnit.Framework; \ No newline at end of file +global using NUnit.Framework; diff --git a/tests/Legerity.Telerik.Uwp.Tests/Legerity.Telerik.Uwp.Tests.csproj b/tests/Legerity.Telerik.Uwp.Tests/Legerity.Telerik.Uwp.Tests.csproj index 1e486107..63451261 100644 --- a/tests/Legerity.Telerik.Uwp.Tests/Legerity.Telerik.Uwp.Tests.csproj +++ b/tests/Legerity.Telerik.Uwp.Tests/Legerity.Telerik.Uwp.Tests.csproj @@ -1,12 +1,12 @@ - net6.0 + net6.0;net7.0;net8.0 false - + diff --git a/tests/Legerity.Telerik.Uwp.Tests/Pages/BaseNavigationPage.cs b/tests/Legerity.Telerik.Uwp.Tests/Pages/BaseNavigationPage.cs index b1c802e3..11c49720 100644 --- a/tests/Legerity.Telerik.Uwp.Tests/Pages/BaseNavigationPage.cs +++ b/tests/Legerity.Telerik.Uwp.Tests/Pages/BaseNavigationPage.cs @@ -1,31 +1,31 @@ -namespace Legerity.Telerik.Uwp.Tests.Pages; - using System; +using Legerity.Pages; using Legerity.Windows.Elements.Core; using OpenQA.Selenium; -using OpenQA.Selenium.Remote; + +namespace Legerity.Telerik.Uwp.Tests.Pages; internal class BaseNavigationPage : BasePage { - private readonly By searchBoxLocator = By.Name("Search"); + private readonly By _searchBoxLocator = By.Name("Search"); - public BaseNavigationPage(RemoteWebDriver app) + public BaseNavigationPage(WebDriver app) : base(app) { } - public TextBox SearchBox => this.FindElement(this.searchBoxLocator); + public TextBox SearchBox => FindElement(_searchBoxLocator); - protected override By Trait => this.searchBoxLocator; + protected override By Trait => _searchBoxLocator; public TPage NavigateTo(string controlName, string sampleName) where TPage : BasePage { - this.SearchBox.SetText(controlName); + SearchBox.SetText(controlName); - RemoteWebElement item = this.FindElement(By.XPath($".//*[@ClassName='ListViewItem'][@Name='{sampleName}']")); + var item = FindElement(By.XPath($".//*[@ClassName='ListViewItem'][@Name='{sampleName}']")); item.Click(); - return Activator.CreateInstance(typeof(TPage), this.App) as TPage; + return Activator.CreateInstance(typeof(TPage), App) as TPage; } -} \ No newline at end of file +} diff --git a/tests/Legerity.Telerik.Uwp.Tests/Pages/HomePage.cs b/tests/Legerity.Telerik.Uwp.Tests/Pages/HomePage.cs index d92248f1..ed819ab4 100644 --- a/tests/Legerity.Telerik.Uwp.Tests/Pages/HomePage.cs +++ b/tests/Legerity.Telerik.Uwp.Tests/Pages/HomePage.cs @@ -1,10 +1,10 @@ -namespace Legerity.Telerik.Uwp.Tests.Pages; +using OpenQA.Selenium; -using OpenQA.Selenium.Remote; +namespace Legerity.Telerik.Uwp.Tests.Pages; internal class HomePage : BaseNavigationPage { - public HomePage(RemoteWebDriver app) : base(app) + public HomePage(WebDriver app) : base(app) { } -} \ No newline at end of file +} diff --git a/tests/Legerity.Telerik.Uwp.Tests/Tests/BaseTestClass.cs b/tests/Legerity.Telerik.Uwp.Tests/Tests/BaseTestClass.cs index 85dfa1b2..f29b7719 100644 --- a/tests/Legerity.Telerik.Uwp.Tests/Tests/BaseTestClass.cs +++ b/tests/Legerity.Telerik.Uwp.Tests/Tests/BaseTestClass.cs @@ -1,14 +1,12 @@ +using System; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; +using Legerity.Windows; [assembly: ExcludeFromCodeCoverage] namespace Legerity.Telerik.Uwp.Tests.Tests; -using System; -using System.Collections.Generic; -using Legerity; -using Legerity.Windows; - /// /// Defines the base test class for setting up and running UI tests. /// @@ -75,6 +73,6 @@ public virtual void Cleanup() public virtual void FinalCleanup() { // Ensures that any running app driver instances being tracked are stopped. - this.StopApps(); + StopApps(); } -} \ No newline at end of file +} diff --git a/tests/Legerity.WCT.Tests/GlobalUsings.cs b/tests/Legerity.WCT.Tests/GlobalUsings.cs index 4ee19433..45803334 100644 --- a/tests/Legerity.WCT.Tests/GlobalUsings.cs +++ b/tests/Legerity.WCT.Tests/GlobalUsings.cs @@ -1,6 +1,3 @@ // Global using directives -global using Legerity; -global using Legerity.Pages; -global using Legerity.Windows; -global using NUnit.Framework; \ No newline at end of file +global using NUnit.Framework; diff --git a/tests/Legerity.WCT.Tests/Legerity.WCT.Tests.csproj b/tests/Legerity.WCT.Tests/Legerity.WCT.Tests.csproj index dcd3103e..7b78018a 100644 --- a/tests/Legerity.WCT.Tests/Legerity.WCT.Tests.csproj +++ b/tests/Legerity.WCT.Tests/Legerity.WCT.Tests.csproj @@ -1,12 +1,12 @@ - net6.0 + net6.0;net7.0;net8.0 false - + diff --git a/tests/Legerity.WCT.Tests/Pages/BaseNavigationPage.cs b/tests/Legerity.WCT.Tests/Pages/BaseNavigationPage.cs index bd0da57b..04db60a9 100644 --- a/tests/Legerity.WCT.Tests/Pages/BaseNavigationPage.cs +++ b/tests/Legerity.WCT.Tests/Pages/BaseNavigationPage.cs @@ -1,42 +1,42 @@ -namespace Legerity.WCT.Tests.Pages; - using System; using System.Linq; -using Extensions; +using Legerity.Extensions; +using Legerity.Pages; +using Legerity.Windows; using Legerity.Windows.Elements.Core; using Legerity.Windows.Elements.WinUI; using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Remote; + +namespace Legerity.WCT.Tests.Pages; internal class BaseNavigationPage : BasePage { - private readonly By navigationViewLocator = WindowsByExtras.AutomationId("NavView"); + private readonly By _navigationViewLocator = WindowsByExtras.AutomationId("NavView"); - public BaseNavigationPage(RemoteWebDriver app) + public BaseNavigationPage(WebDriver app) : base(app) { } - public NavigationView NavigationView => this.FindElement(this.navigationViewLocator); + public NavigationView NavigationView => FindElement(_navigationViewLocator); - public AutoSuggestBox SampleSearchBox => this.NavigationView.FindElement(WindowsByExtras.AutomationId("SearchBox")); + public AutoSuggestBox SampleSearchBox => NavigationView.FindElement(WindowsByExtras.AutomationId("SearchBox")); - public GridView SamplePicker => this.FindElement(WindowsByExtras.AutomationId("SamplePickerGridView")); + public GridView SamplePicker => FindElement(WindowsByExtras.AutomationId("SamplePickerGridView")); - protected override By Trait => this.navigationViewLocator; + protected override By Trait => _navigationViewLocator; public TPage NavigateTo(string sampleName) where TPage : BasePage { - this.SampleSearchBox.SetText(sampleName); + SampleSearchBox.SetText(sampleName); - this.WaitUntil(p => p.SamplePicker.Items.Any(), this.WaitTimeout); + this.WaitUntil(p => p.SamplePicker.Items.Any(), WaitTimeout); - AppiumWebElement item = this.SamplePicker.Items.FirstOrDefault(i => + var item = SamplePicker.Items.FirstOrDefault(i => i.FindElement(By.XPath($".//*[@ClassName='TextBlock'][@Name='{sampleName}']")) != null); item.Click(); - return Activator.CreateInstance(typeof(TPage), this.App) as TPage; + return Activator.CreateInstance(typeof(TPage), App) as TPage; } -} \ No newline at end of file +} diff --git a/tests/Legerity.WCT.Tests/Pages/HomePage.cs b/tests/Legerity.WCT.Tests/Pages/HomePage.cs index 0f9d51db..02baee58 100644 --- a/tests/Legerity.WCT.Tests/Pages/HomePage.cs +++ b/tests/Legerity.WCT.Tests/Pages/HomePage.cs @@ -1,10 +1,10 @@ -namespace Legerity.WCT.Tests.Pages; +using OpenQA.Selenium; -using OpenQA.Selenium.Remote; +namespace Legerity.WCT.Tests.Pages; internal class HomePage : BaseNavigationPage { - public HomePage(RemoteWebDriver app) : base(app) + public HomePage(WebDriver app) : base(app) { } -} \ No newline at end of file +} diff --git a/tests/Legerity.WCT.Tests/Tests/BaseTestClass.cs b/tests/Legerity.WCT.Tests/Tests/BaseTestClass.cs index c5d9e34c..24ef1b2e 100644 --- a/tests/Legerity.WCT.Tests/Tests/BaseTestClass.cs +++ b/tests/Legerity.WCT.Tests/Tests/BaseTestClass.cs @@ -1,14 +1,12 @@ +using System; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; +using Legerity.Windows; [assembly: ExcludeFromCodeCoverage] namespace Legerity.WCT.Tests.Tests; -using System; -using System.Collections.Generic; -using Legerity; -using Legerity.Windows; - /// /// Defines the base test class for setting up and running UI tests. /// @@ -75,6 +73,6 @@ public virtual void Cleanup() public virtual void FinalCleanup() { // Ensures that any running app driver instances being tracked are stopped. - this.StopApps(); + StopApps(); } -} \ No newline at end of file +} diff --git a/tests/Legerity.Web.Tests/GlobalUsings.cs b/tests/Legerity.Web.Tests/GlobalUsings.cs index 2ac570eb..45803334 100644 --- a/tests/Legerity.Web.Tests/GlobalUsings.cs +++ b/tests/Legerity.Web.Tests/GlobalUsings.cs @@ -1,6 +1,3 @@ // Global using directives -global using Legerity; -global using Legerity.Pages; -global using Legerity.Web; -global using NUnit.Framework; \ No newline at end of file +global using NUnit.Framework; diff --git a/tests/Legerity.Web.Tests/Legerity.Web.Tests.csproj b/tests/Legerity.Web.Tests/Legerity.Web.Tests.csproj index a1534071..c8c6d293 100644 --- a/tests/Legerity.Web.Tests/Legerity.Web.Tests.csproj +++ b/tests/Legerity.Web.Tests/Legerity.Web.Tests.csproj @@ -1,16 +1,19 @@ - net6.0 + net6.0;net7.0;net8.0 false - + - + + + + diff --git a/tests/Legerity.Web.Tests/Pages/ButtonPage.cs b/tests/Legerity.Web.Tests/Pages/ButtonPage.cs index 2755c5ac..4ffe130c 100644 --- a/tests/Legerity.Web.Tests/Pages/ButtonPage.cs +++ b/tests/Legerity.Web.Tests/Pages/ButtonPage.cs @@ -1,23 +1,22 @@ -namespace Legerity.Web.Tests.Pages; - -using Elements.Core; +using Legerity.Web.Elements.Core; using OpenQA.Selenium; -using OpenQA.Selenium.Remote; + +namespace Legerity.Web.Tests.Pages; internal class ButtonPage : W3SchoolsBasePage { - private readonly By buttonLocator = By.TagName("button"); + private readonly By _buttonLocator = By.TagName("button"); - public ButtonPage(RemoteWebDriver app) + public ButtonPage(WebDriver app) : base(app) { } - public Button Button => this.FindElement(this.buttonLocator); + public Button Button => FindElement(_buttonLocator); public ButtonPage ClickButton() { - this.Button.Click(); + Button.Click(); return this; } -} \ No newline at end of file +} diff --git a/tests/Legerity.Web.Tests/Pages/CheckBoxPage.cs b/tests/Legerity.Web.Tests/Pages/CheckBoxPage.cs index ece350ad..83755c63 100644 --- a/tests/Legerity.Web.Tests/Pages/CheckBoxPage.cs +++ b/tests/Legerity.Web.Tests/Pages/CheckBoxPage.cs @@ -1,28 +1,27 @@ -namespace Legerity.Web.Tests.Pages; - -using Elements.Core; +using Legerity.Web.Elements.Core; using OpenQA.Selenium; -using OpenQA.Selenium.Remote; + +namespace Legerity.Web.Tests.Pages; internal class CheckBoxPage : W3SchoolsBasePage { - private readonly By bikeCheckBoxLocator = By.Id("vehicle1"); + private readonly By _bikeCheckBoxLocator = By.Id("vehicle1"); - public CheckBoxPage(RemoteWebDriver app) : base(app) + public CheckBoxPage(WebDriver app) : base(app) { } - public CheckBox BikeCheckBox => this.FindElement(this.bikeCheckBoxLocator); + public CheckBox BikeCheckBox => FindElement(_bikeCheckBoxLocator); public CheckBoxPage CheckBikeOn() { - this.BikeCheckBox.CheckOn(); + BikeCheckBox.CheckOn(); return this; } public CheckBoxPage CheckBikeOff() { - this.BikeCheckBox.CheckOff(); + BikeCheckBox.CheckOff(); return this; } -} \ No newline at end of file +} diff --git a/tests/Legerity.Web.Tests/Pages/DateInputPage.cs b/tests/Legerity.Web.Tests/Pages/DateInputPage.cs index 4d579f8c..20c3eb99 100644 --- a/tests/Legerity.Web.Tests/Pages/DateInputPage.cs +++ b/tests/Legerity.Web.Tests/Pages/DateInputPage.cs @@ -1,21 +1,20 @@ -namespace Legerity.Web.Tests.Pages; - using System; -using Elements.Core; +using Legerity.Web.Elements.Core; using OpenQA.Selenium; -using OpenQA.Selenium.Remote; + +namespace Legerity.Web.Tests.Pages; internal class DateInputPage : W3SchoolsBasePage { - public DateInputPage(RemoteWebDriver app) : base(app) + public DateInputPage(WebDriver app) : base(app) { } - public DateInput DateInput => this.FindElement(By.Id("birthday")); + public DateInput DateInput => FindElement(By.Id("birthday")); public DateInputPage SetBirthdayDate(DateTime date) { - this.DateInput.SetDate(date); + DateInput.SetDate(date); return this; } -} \ No newline at end of file +} diff --git a/tests/Legerity.Web.Tests/Pages/FileInputPage.cs b/tests/Legerity.Web.Tests/Pages/FileInputPage.cs index 32c4e4ef..aa5c7881 100644 --- a/tests/Legerity.Web.Tests/Pages/FileInputPage.cs +++ b/tests/Legerity.Web.Tests/Pages/FileInputPage.cs @@ -1,28 +1,27 @@ -namespace Legerity.Web.Tests.Pages; - -using Elements.Core; +using Legerity.Web.Elements.Core; using OpenQA.Selenium; -using OpenQA.Selenium.Remote; + +namespace Legerity.Web.Tests.Pages; internal class FileInputPage : W3SchoolsBasePage { - private readonly By fileInputLocator = By.Id("myfile"); + private readonly By _fileInputLocator = By.Id("myfile"); - public FileInputPage(RemoteWebDriver app) : base(app) + public FileInputPage(WebDriver app) : base(app) { } - public FileInput FileInput => this.FindElement(this.fileInputLocator); + public FileInput FileInput => FindElement(_fileInputLocator); public FileInputPage SetFileInputFilePath(string filePath) { - this.FileInput.SetAbsoluteFilePath(filePath); + FileInput.SetAbsoluteFilePath(filePath); return this; } public FileInputPage ClearFileInput() { - this.FileInput.ClearFile(); + FileInput.ClearFile(); return this; } -} \ No newline at end of file +} diff --git a/tests/Legerity.Web.Tests/Pages/ImagePage.cs b/tests/Legerity.Web.Tests/Pages/ImagePage.cs index d46b8c16..4c144e87 100644 --- a/tests/Legerity.Web.Tests/Pages/ImagePage.cs +++ b/tests/Legerity.Web.Tests/Pages/ImagePage.cs @@ -1,16 +1,15 @@ -namespace Legerity.Web.Tests.Pages; - -using Elements.Core; +using Legerity.Web.Elements.Core; using OpenQA.Selenium; -using OpenQA.Selenium.Remote; + +namespace Legerity.Web.Tests.Pages; internal class ImagePage : W3SchoolsBasePage { - private readonly By imageLocator = By.TagName("img"); + private readonly By _imageLocator = By.TagName("img"); - public ImagePage(RemoteWebDriver app) : base(app) + public ImagePage(WebDriver app) : base(app) { } - public Image Image => this.FindElement(this.imageLocator); -} \ No newline at end of file + public Image Image => FindElement(_imageLocator); +} diff --git a/tests/Legerity.Web.Tests/Pages/ListPage.cs b/tests/Legerity.Web.Tests/Pages/ListPage.cs index d946beb8..41d528be 100644 --- a/tests/Legerity.Web.Tests/Pages/ListPage.cs +++ b/tests/Legerity.Web.Tests/Pages/ListPage.cs @@ -1,17 +1,16 @@ -namespace Legerity.Web.Tests.Pages; - -using Elements.Core; using System.Linq; +using Legerity.Web.Elements.Core; using OpenQA.Selenium; -using OpenQA.Selenium.Remote; + +namespace Legerity.Web.Tests.Pages; internal class ListPage : W3SchoolsBasePage { - private readonly By orderedListLocator = By.TagName("ol"); + private readonly By _orderedListLocator = By.TagName("ol"); - public ListPage(RemoteWebDriver app) : base(app) + public ListPage(WebDriver app) : base(app) { } - public List OrderedList => this.FindElements(this.orderedListLocator).FirstOrDefault(); -} \ No newline at end of file + public List OrderedList => FindElements(_orderedListLocator).FirstOrDefault(); +} diff --git a/tests/Legerity.Web.Tests/Pages/NumberInputPage.cs b/tests/Legerity.Web.Tests/Pages/NumberInputPage.cs index 9fd8e6c3..0de6955a 100644 --- a/tests/Legerity.Web.Tests/Pages/NumberInputPage.cs +++ b/tests/Legerity.Web.Tests/Pages/NumberInputPage.cs @@ -1,34 +1,33 @@ -namespace Legerity.Web.Tests.Pages; - -using Elements.Core; +using Legerity.Web.Elements.Core; using OpenQA.Selenium; -using OpenQA.Selenium.Remote; + +namespace Legerity.Web.Tests.Pages; internal class NumberInputPage : W3SchoolsBasePage { - private readonly By quantityNumberInputLocator = By.Id("quantity"); + private readonly By _quantityNumberInputLocator = By.Id("quantity"); - public NumberInputPage(RemoteWebDriver app) : base(app) + public NumberInputPage(WebDriver app) : base(app) { } - public NumberInput QuantityNumberInput => this.FindElement(this.quantityNumberInputLocator); + public NumberInput QuantityNumberInput => FindElement(_quantityNumberInputLocator); public NumberInputPage SetQuantity(int quantity) { - this.QuantityNumberInput.SetValue(quantity); + QuantityNumberInput.SetValue(quantity); return this; } public NumberInputPage IncrementQuantity() { - this.QuantityNumberInput.Increment(); + QuantityNumberInput.Increment(); return this; } public NumberInputPage DecrementQuantity() { - this.QuantityNumberInput.Decrement(); + QuantityNumberInput.Decrement(); return this; } -} \ No newline at end of file +} diff --git a/tests/Legerity.Web.Tests/Pages/OptionPage.cs b/tests/Legerity.Web.Tests/Pages/OptionPage.cs index aee1a40a..d5fde05f 100644 --- a/tests/Legerity.Web.Tests/Pages/OptionPage.cs +++ b/tests/Legerity.Web.Tests/Pages/OptionPage.cs @@ -1,30 +1,29 @@ -namespace Legerity.Web.Tests.Pages; - using System.Collections.Generic; using System.Linq; -using Elements.Core; +using Legerity.Web.Elements.Core; using OpenQA.Selenium; -using OpenQA.Selenium.Remote; + +namespace Legerity.Web.Tests.Pages; internal class OptionPage : W3SchoolsBasePage { - private readonly By carOptionLocator = By.TagName("option"); + private readonly By _carOptionLocator = By.TagName("option"); - public OptionPage(RemoteWebDriver app) : base(app) + public OptionPage(WebDriver app) : base(app) { } - public IEnumerable