Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Bug fix/40328 Timeout default value #3759

Merged
merged 3 commits into from
Jun 24, 2024

Conversation

GokulBothe
Copy link
Collaborator

@GokulBothe GokulBothe commented Jun 12, 2024

Thank you for your contribution.
Before submitting this PR, please make sure:

  • PR description and commit message should describe the changes done in this PR
  • Verify the PR is pointing to correct branch i.e. Release or Beta branch if the code fix is for specific release , else point it to master
  • Latest Code from master or specific release branch is merged to your branch
  • No unwanted\commented\junk code is included
  • No new warning upon build solution
  • Code Summary\Comments are added to my code which explains what my code is doing
  • Existing unit test cases are passed
  • New Unit tests are added for your development
  • Sanity Tests are successfully executed for New and Existing Functionality
  • Verify that changes are compatible with all relevant browsers and platforms.
  • After creating pull request there should not be any conflicts
  • Resolve all Codacy comments
  • Builds and checks are passed before PR is sent for review
  • Resolve code review comments
  • Update the Help Library document to match any feature changes

Summary by CodeRabbit

  • New Features

    • Enhanced timeout information tooltip for improved user guidance.
  • Bug Fixes

    • Improved input validation on the timeout text box to prevent incorrect entries.
    • Timeout text box will now reset to null instead of "0" for clearer state management.
  • Chores

    • Updated version numbers to reflect the latest release.

Copy link
Contributor

coderabbitai bot commented Jun 12, 2024

Walkthrough

This update enhances various components of the project. Key improvements include better timeout handling and validation in the ActionEditPage.xaml, more accurate retrieval of the maximum timeout in SeleniumDriver.cs, and version updates in GingerCoreCommon.csproj.

Changes

File Path(s) Change Summary
Ginger/.../ActionEditPage.xaml Updated xTimeoutTextBox with input validation and enhanced tooltips.
Ginger/.../ActionEditPage.xaml.cs Modified txtTimeout_TextChanged logic and added xTimeoutTextBox_PreviewTextInput method for text input validation.
GingerCoreCommon/GingerCoreCommon.csproj Updated version numbers from 24.2.0.0 to 24.3.1.0.
Ginger/.../SeleniumDriver.cs NewSmartSyncGetMaxTimeout now returns ImplicitWait cast to an integer instead of a fixed value of 300.

Poem

In the world of code, where changes brew,
Timeout texts now shine anew.
With versions fresh and logic tight,
Selenium syncs to greater heights.
The rabbit hops with joyful cheer,
For Ginger's updates are finally here! 🌟🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 07ddffb and 20f1a95.

Files selected for processing (4)
  • Ginger/Ginger/Actions/ActionEditPage.xaml (1 hunks)
  • Ginger/Ginger/Actions/ActionEditPage.xaml.cs (2 hunks)
  • Ginger/GingerCoreCommon/GingerCoreCommon.csproj (1 hunks)
  • Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs (1 hunks)
Files skipped from review due to trivial changes (2)
  • Ginger/GingerCoreCommon/GingerCoreCommon.csproj
  • Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs
Additional comments not posted (1)
Ginger/Ginger/Actions/ActionEditPage.xaml (1)

154-154: The changes to xTimeoutTextBox including the updated ToolTip and the addition of PreviewTextInput event handler are well-implemented and enhance user experience by providing clearer instructions and preventing invalid input.

Comment on lines +2263 to +2288
private void xTimeoutTextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
{

bool isEmptyString = string.IsNullOrEmpty(e.Text);
if (isEmptyString)
{
//allow
e.Handled = false;
return;
}

string currentText = xTimeoutTextBox.Text != null ? xTimeoutTextBox.Text : string.Empty;
bool isValidInteger = int.TryParse(currentText + e.Text, out _);
if (isValidInteger)
{
//allow
e.Handled = false;
return;
}
else
{
//don't allow
e.Handled = true;
}

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure input validation for timeout text box is robust.

The input validation logic for the timeout text box currently allows only integer values, which is good. However, the implementation can be simplified and made more robust by using regular expressions or leveraging existing WPF features for input restrictions. Here's a simplified version using a behavior:

// Add this class in a suitable place
public class NumericInputBehavior : Behavior<TextBox>
{
    protected override void OnAttached()
    {
        base.OnAttached();
        AssociatedObject.PreviewTextInput += OnPreviewTextInput;
        DataObject.AddPastingHandler(AssociatedObject, OnPaste);
    }

    protected override void OnDetaching()
    {
        base.OnDetaching();
        AssociatedObject.PreviewTextInput -= OnPreviewTextInput;
        DataObject.RemovePastingHandler(AssociatedObject, OnPaste);
    }

    private void OnPreviewTextInput(object sender, TextCompositionEventArgs e)
    {
        e.Handled = !IsTextAllowed(e.Text);
    }

    private void OnPaste(object sender, DataObjectPastingEventArgs e)
    {
        if (e.DataObject.GetDataPresent(typeof(string)))
        {
            string text = (string)e.DataObject.GetData(typeof(string));
            if (!IsTextAllowed(text))
            {
                e.CancelCommand();
            }
        }
        else
        {
            e.CancelCommand();
        }
    }

    private bool IsTextAllowed(string text)
    {
        return Regex.IsMatch(text, "[^0-9]+");
    }
}

// Usage in XAML:
<TextBox Text="{Binding Timeout, UpdateSourceTrigger=PropertyChanged}">
    <i:Interaction.Behaviors>
        <local:NumericInputBehavior />
    </i:Interaction.Behaviors>
</TextBox>

This approach not only simplifies the code but also handles copy-paste scenarios where non-numeric values might be pasted into the text box.

@@ -1668,7 +1668,7 @@
{
if (xTimeoutTextBox.Text == String.Empty || xTimeoutTextBox.Text == null)
{
xTimeoutTextBox.Text = "0";
xTimeoutTextBox.Text = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider handling empty string input more robustly.

The current implementation sets the text to null when it's empty. This might lead to unexpected behavior or errors if other parts of the code expect a string. Consider setting it to an empty string "" instead of null for better safety and consistency.

- xTimeoutTextBox.Text = null;
+ xTimeoutTextBox.Text = "";
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
xTimeoutTextBox.Text = null;
xTimeoutTextBox.Text = "";

Copy link
Contributor

@Maheshkale447 Maheshkale447 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also check suggestion by CodeRabbit

@@ -1668,7 +1668,7 @@ private void txtTimeout_TextChanged(object sender, TextChangedEventArgs e)
{
if (xTimeoutTextBox.Text == String.Empty || xTimeoutTextBox.Text == null)
{
xTimeoutTextBox.Text = "0";
xTimeoutTextBox.Text = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set it to empty instead of null

return;
}

string currentText = xTimeoutTextBox.Text != null ? xTimeoutTextBox.Text : string.Empty;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allow setting timeout to empty

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it's allowing-
Basically this code is checking-
Allows input if the input text is empty.
Allows input if the resulting text (current text + new input) forms a valid integer.
Disallows any input that does not result in a valid integer.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Outside diff range and nitpick comments (1)
Ginger/Ginger/Actions/ActionEditPage.xaml (1)

154-154: Enhance tooltip clarity and detail.

The tooltip for xTimeoutTextBox has been expanded to provide detailed information about the timeout setting. Ensure that this tooltip is concise yet informative, possibly breaking it down into simpler terms or using bullet points for better readability.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 20f1a95 and 21b5dda.

Files selected for processing (2)
  • Ginger/Ginger/Actions/ActionEditPage.xaml (1 hunks)
  • Ginger/Ginger/Actions/ActionEditPage.xaml.cs (2 hunks)
Additional comments not posted (1)
Ginger/Ginger/Actions/ActionEditPage.xaml.cs (1)

1654-1654: Consider revising the handling of empty input in txtTimeout_TextChanged.

The current implementation sets xTimeoutTextBox.Text to null when it is empty, which could lead to unexpected behavior or errors if other parts of the code expect a string. Consider setting it to an empty string "" instead of null for better safety and consistency. This aligns with previous feedback provided in the PR.

- xTimeoutTextBox.Text = null;
+ xTimeoutTextBox.Text = "";

Likely invalid or redundant comment.

Comment on lines +2245 to +2271

private void xTimeoutTextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
{

bool isEmptyString = string.IsNullOrEmpty(e.Text);
if (isEmptyString)
{
//allow
e.Handled = false;
return;
}

string currentText = xTimeoutTextBox.Text != null ? xTimeoutTextBox.Text : string.Empty;
bool isValidInteger = int.TryParse(currentText + e.Text, out _);
if (isValidInteger)
{
//allow
e.Handled = false;
return;
}
else
{
//don't allow
e.Handled = true;
}

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplify input validation logic in xTimeoutTextBox_PreviewTextInput method.

The method xTimeoutTextBox_PreviewTextInput has a complex flow for validating integer input which can be simplified. Consider using int.TryParse directly on the concatenated string and handle the event based on the result. This removes the need for separate checks and makes the code more concise and readable.

private void xTimeoutTextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
    string combinedText = xTimeoutTextBox.Text + e.Text;
    e.Handled = !int.TryParse(combinedText, out _); // Directly set handled based on the parse result
}

@@ -151,7 +151,7 @@
<Label Content="Wait:" Style="{StaticResource $LabelStyle}" />
<Actions:UCValueExpression x:Name="xWaitVeUC" ToolTip="Action will wait this seconds long before start to run" HorizontalAlignment="Stretch" Width="80" />
<Label Content="Timeout:" Style="{StaticResource $LabelStyle}" Margin="10,0,0,0"/>
<TextBox x:Name="xTimeoutTextBox" TextChanged="txtTimeout_TextChanged" ToolTip="Timeout field is in seconds. Default is 30 minutes (1800 seconds). Use 0 for no timeout, allowing actions to run indefinitely. If an action exceeds the specified timeout duration, it will be stopped and marked as failed." Style="{StaticResource @TextBoxStyle}" Width="50" TextAlignment="Center" HorizontalAlignment="Left" />
<TextBox x:Name="xTimeoutTextBox" TextChanged="txtTimeout_TextChanged" PreviewTextInput="xTimeoutTextBox_PreviewTextInput" ToolTip="Timeout field is in seconds. Default is 30 minutes (1800 seconds). Use 0 for no timeout, allowing actions to run indefinitely. If an action exceeds the specified timeout duration, it will be stopped and marked as failed." Style="{StaticResource @TextBoxStyle}" Width="50" TextAlignment="Center" HorizontalAlignment="Left" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review the use of TextChanged event for setting default values.

The TextChanged event handler clears the xTimeoutTextBox text unconditionally. Consider implementing a more robust method for handling default values or empty inputs to avoid potential issues with user interactions.

- <TextBox x:Name="xTimeoutTextBox" TextChanged="txtTimeout_TextChanged" PreviewTextInput="xTimeoutTextBox_PreviewTextInput" ...
+ <TextBox x:Name="xTimeoutTextBox" LostFocus="xTimeoutTextBox_LostFocus" PreviewTextInput="xTimeoutTextBox_PreviewTextInput" ...
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<TextBox x:Name="xTimeoutTextBox" TextChanged="txtTimeout_TextChanged" PreviewTextInput="xTimeoutTextBox_PreviewTextInput" ToolTip="Timeout field is in seconds. Default is 30 minutes (1800 seconds). Use 0 for no timeout, allowing actions to run indefinitely. If an action exceeds the specified timeout duration, it will be stopped and marked as failed." Style="{StaticResource @TextBoxStyle}" Width="50" TextAlignment="Center" HorizontalAlignment="Left" />
<TextBox x:Name="xTimeoutTextBox" LostFocus="xTimeoutTextBox_LostFocus" PreviewTextInput="xTimeoutTextBox_PreviewTextInput" ToolTip="Timeout field is in seconds. Default is 30 minutes (1800 seconds). Use 0 for no timeout, allowing actions to run indefinitely. If an action exceeds the specified timeout duration, it will be stopped and marked as failed." Style="{StaticResource @TextBoxStyle}" Width="50" TextAlignment="Center" HorizontalAlignment="Left" />

@Maheshkale447 Maheshkale447 merged commit 99dc935 into master Jun 24, 2024
4 of 6 checks passed
@Maheshkale447 Maheshkale447 deleted the BugFix/40328_Timeout_DefaultValue branch June 24, 2024 09:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants