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

Playwright refactoring + api project #134

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

andrey-brovko
Copy link
Collaborator

No description provided.


if (!IsAbsoluteUrl(url))
{
url = ConfigManager.GetConfig<Config>().ApiHost + url;
Copy link
Collaborator

Choose a reason for hiding this comment

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

It makes sense to rewrite IsAbsoluteUrl to something like GetAbsoluteUrl since it's use throughout the code. Additionally, you can return Uri from this method that will be well-formed and wouldn't require using string concatenation

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

}

[When("user sends a \"(.*)\" request to \"(.*)\" url with the json:")]
public HttpResponseMessage UserSendsHttpRequestWithParameters(string httpMethod, string url, string jsonToSend)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm sure it's a bad idea to write json as string inside the .feature file, it makes file bigger, less readable and harder to format, because not Visual Studio, nor Rider can successfully format both .feature file and json inside it at once.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If JSON is not very long it looks fine for me. I've added a step and an example using a file as a JSON source.

[Then("response attachment filename is \"(.*)\"")]
public void ThenResponseAttachmentFilenameIs(string filename)
{
if (_apiContext.Response is null) throw new NullReferenceException("Http response is empty.");
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think that exception type should be nullref here, it looks more like a HttpResponseException

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In this case, NullReferenceException throws if an object is null so I think it is fine. The root cause of the issue is that the request wasn't sent so it more test consistency issue.

Copy link
Collaborator

Choose a reason for hiding this comment

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

In C# NullReferenceException is generally thrown when user tries to access null instead of valid value. Here no one tries to access it, so logically it seems right to use other kind, maybe not NullReferenceException, but definitely not NullReferenceException

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed.

[Given("response attachment is saved as \"(.*)\"")]
public void GivenResponseAttachmentIsSavedAs(string filePath)
{
if (_apiContext.Response is null) throw new NullReferenceException("Http response is empty.");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Replied.

var fullPath = Path.GetFullPath(Path.Join(Directory.GetCurrentDirectory(), filePath))
.NormalizePathAccordingOs();

var directoryPath = Path.GetDirectoryName(fullPath);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we really need this variable?
Why not use fullPath instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Looks like yes. The logic is to check whether a directory exists and create if not.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It is not clear here what could be written in filePath - full path or relative path? Because of that further manipulations with this value are hard to understand

Copy link
Collaborator

Choose a reason for hiding this comment

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

Btw,
image

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

FailJTokensAssertion(actualJTokens, expectedJTokens, "Elements count mismatch.");
}

if (!IsJTokenListsSimilar(expectedJTokens, actualJTokens))
Copy link
Collaborator

Choose a reason for hiding this comment

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

This method name can be misinterpreted
IsJTokenListItemsAreTheSame might be better

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done


private List<JToken> GetActualJTokensFromResponse(string jsonPath)
{
if (_apiContext.Response is null) throw new NullReferenceException("Http response is empty.");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as mentioned

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Replied.

{
if (!expected.Trim().StartsWith("["))
{
expected = expected.Insert(0, "[");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Interpolation here will look better and easier to read
expected = $"[{expected}"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

Behavioral.Automation.API/Bindings/SaveToContextSteps.cs Outdated Show resolved Hide resolved
@@ -14,7 +14,7 @@ public class ClickBinding
/// <example>When user clicks on "Test" button</example>
[Given(@"user clicked on ""(.+?)""")]
[When(@"user clicks on ""(.+?)""")]
public async Task ClickOnElement(IWebElementWrapper element)
public async Task ClickOnElement(WebElementWrapper element)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why change interface to concrete implementation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The framework is intended to be simple and light. So without the abstract layer, it will be more straightforward.

Copy link
Collaborator

Choose a reason for hiding this comment

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

And how do you intend to override default wrappers that you have in new projects in case of compatibility issues?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

To create a new one or edit existing ones. Since we don't have a NuGet package the solution will be simple cloned and customized.

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