Skip to content

Conversation

@SvNov
Copy link
Collaborator

@SvNov SvNov commented Aug 27, 2019

No description provided.

@SvNov SvNov requested a review from mikeformus August 27, 2019 09:54
@mikeformus
Copy link
Owner

@SvNov fix spaces and tabs/whitespace characters - no more that one empty line or one tabs/whitespace between elements

@mikeformus
Copy link
Owner

@SvNov Don't name variables as obj... or str... C# is strongly typed language and you can always lookup type of the variable.

{
class CreateSavedSearchPageTest : BaseTest
{
private LoginPage objLoginPage;
Copy link
Owner

Choose a reason for hiding this comment

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

this method can be simplified if you use parameterized selector:
create method that returns selector for list view item by its name:

private By ListViewItem(string itemName) => By.Xpath($"//span[contains(@class,'lvName-span')][@title='{itemName}']");

then here:

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(15));
wait.Until(x => driver.FindElement(ListViewItem(criteria));
)

you can either make this method void - it will throw exception if item is not found - or wrap it into try catch and return true/false (and make assert statement in test)

objSearchResultsPage = new SearchResultsPage(driver, waiter);

// performs simple search
objSearchResultsPage.Search("4819-5337-4080");
Copy link
Owner

Choose a reason for hiding this comment

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

test data (strings, ids names etc) needs to be moved out into test class fields with meaningful name. Therefore we can quickly see what hard coded test data test depends on.

objCreateSavedSearchPage = new CreateSavedSearchPage(driver, waiter);
objCreateSavedSearchPage.ClickOnContainerOptionsButton();

//var docName = objSearchResultsPage.GetSearchResultDocumentName("4819-5337-4080");
Copy link
Owner

Choose a reason for hiding this comment

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

remove all commented code

private readonly By locator = By.Id("containerOptionsButton");
private readonly By okButton = By.Name("okButton");

public IWebElement ContainerOptionsButton =>
Copy link
Owner

Choose a reason for hiding this comment

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

you either define Selectors (By) and then find elements in your methods. Or you define web elements (IWebElement) adn use those in your methods but not both - it's unnecessary complication.

{
var search = waiter.Until(SeleniumExtras.WaitHelpers
.ExpectedConditions
.ElementToBeClickable(By.Id("nd-hsCriteria-input")));
Copy link
Owner

Choose a reason for hiding this comment

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

hardcoded selector

{
var documentRow = waiter.Until(SeleniumExtras.WaitHelpers
.ExpectedConditions
.ElementIsVisible(By.ClassName("id_"+ searchText)));
Copy link
Owner

Choose a reason for hiding this comment

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

hardcoded selector - change it to parameterized selector:

private By ListViewItem(string itemName) => By.Xpath($"//span[contains(@class,'lvName-span')][@title='{itemName}']");

then here:

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(15));
wait.Until(x => driver.FindElement(ListViewItem(criteria));
)

executeSearch.Click();
}

public string GetSearchResultDocumentName(string searchText)
Copy link
Owner

Choose a reason for hiding this comment

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

method signature doesn't make sense - you are getting document name by giving this method document name?
change it public bool IsListViewItemDisplayed(string documentName)


}

public void ClickOnContainerOptionsButton()
Copy link
Owner

Choose a reason for hiding this comment

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

change this method to accept string with option name that you need to click


objCreateSavedSearchPage.ClickSaveSearchSubMenu();
objCreateSavedSearchPage.ClickOnOkButton();
objCreateSavedSearchPage.WaitSaveSearchPage();
Copy link
Owner

Choose a reason for hiding this comment

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

this has to be Assert.IsTrue(UI.SearchResultsPage.IsListViewItemDisplayed(savedSearchName);

@mikeformus
Copy link
Owner

@SvNov Create separate UI class that accepts WebDriver in its constructor and holds references to all Page objects in the following way (so they are lazy-loaded):

private HomePage _homePage;
public HomePage HomePage => _homePage ?? (_homePage = new HomePage(driver));

Create UI as a property in BaseTest.
It will allow you to access PageObjects in tests in the following way:
UI.LoginPage.LoginToWebsite(userName, passWord); without the need to create each page object in every test

@mikeformus
Copy link
Owner

another change to add (from our Skype conversation):
я попрошу вас заюзати ще один патерн при написанні пейдж обджекта, про який я одразу не подумав, але є дуже корисним
коли пишете методи пейдж обджекта, які клікають по юай чи забивають текст - то

  1. якщо метод навігує на нову сторінку - то він повертає ту сторінку.
    Приклад:
    Замість цього:
    public void ClickSearchButton()
    {
    driver.FindElement(goBtn).Click();
    }
    пишемо так:
    public SearchResultsPage ClickSearchButton()
    {
    driver.FindElement(goBtn).Click();
    return new SearchResultsPage(driver);
    }

  2. якщо після виконання методу ми лишаємось на тій самій сторінці - то повертаємо самого себе
    замість
    public void SetUserName(string uName)
    {
    driver.FindElement(userName).SendKeys(uName);
    }
    пишемо:
    public LoginPage SetUserName(string uName)
    {
    driver.FindElement(userName).SendKeys(uName);
    return this;
    }
    це спрощує навігацю по аплікусі оскільки метод сам тобі каже куди він навігне і методи якої наступної сторінки можна викликати
    тест при уьомі міняєтсья на таке
    UI.LoginPage.LoginToWebsite(userName, passWord)
    .PerformSearch(SearchCriteria);
    Assert.IsTrue(ui.SearchResultsPage.Value.CheckForFoundItem(docName));
    не завжди є сенс використовувати то повністю в тестовому сценарії
    але писати методи таким чином, щоб можна було сторювати такий ланцюжок екшинів - є

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.

3 participants