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

Fix After Merge Bugs related to #746 #747 & #735 #751

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 19 additions & 34 deletions Microsoft.Dynamics365.UIAutomation.Api.UCI/WebClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private LoginResult Login(IWebDriver driver, Uri uri, SecureString username, Sec
if (!online)
return LoginResult.Success;

driver.ClickWhenAvailable(By.Id("use_another_account_link"));
driver.ClickIfVisible(By.Id("use_another_account_link"));

bool waitingForOtc = false;
bool success = EnterUserName(driver, username);
Expand All @@ -146,8 +146,7 @@ private LoginResult Login(IWebDriver driver, Uri uri, SecureString username, Sec

if (!waitingForOtc)
{
ThinkTime(1000);
driver.ClickWhenAvailable(By.Id("aadTile"));
driver.ClickIfVisible(By.Id("aadTile"));
ThinkTime(1000);

//If expecting redirect then wait for redirect to trigger
Expand Down Expand Up @@ -1282,41 +1281,28 @@ internal BrowserCommandResult<bool> OpenRecord(int index, int thinkTime = Consta
{
this.Browser.ThinkTime(thinkTime);

return this.Execute(GetOptions($"Open Grid Record"), driver =>
return Execute(GetOptions("Open Grid Record"), driver =>
{
var currentindex = 0;
//var control = driver.WaitUntilAvailable(By.XPath(AppElements.Xpath[AppReference.Grid.Container]));
IWebElement control = driver.WaitUntilAvailable(By.XPath(AppElements.Xpath[AppReference.Grid.Container]));

var rows = driver.FindElements(By.ClassName("wj-row"));
var xpathToFind = checkRecord
? $"//div[@data-id='cell-{index}-1']"
: $"//div[contains(@data-id, 'cell-{index}')]//a";
control.ClickWhenAvailable(By.XPath(xpathToFind), "An error occur trying to open the record at position {index}");

//TODO: The grid only has a small subset of records. Need to load them all
foreach (var row in rows)
{
if (!string.IsNullOrEmpty(row.GetAttribute("data-lp-id")))
{
if (currentindex == index)
{
var tag = "div";
if (checkRecord)
{
row.FindElement(By.TagName(tag)).Click();
}
else
{
driver.DoubleClick(row.FindElement(By.TagName(tag)));
}

break;
}

currentindex++;
}
}

//driver.WaitUntilVisible(By.XPath(AppElements.Xpath[AppReference.Entity.Form]));
// Logic equivalent to fix #746 (by @rswafford)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please @rswafford check this again

//var xpathToFind = $"//div[@data-id='cell-{index}-1']";
//control.WaitUntilClickable(By.XPath(xpathToFind),
// e =>
// {
// e.Click();
// if (!checkRecord)
// driver.DoubleClick(e);
// },
// $"An error occur trying to open the record at position {index}"
// );

driver.WaitForTransaction();

return true;
});
}
Expand Down Expand Up @@ -3267,7 +3253,6 @@ internal BrowserCommandResult<bool> OpenAndClickPopoutMenu(By menuName, By menuI
driver.ClickWhenAvailable(menuName);
try
{
driver.WaitUntilAvailable(menuItemName);
driver.ClickWhenAvailable(menuItemName);
}
catch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,25 @@ public static void Click(this IWebElement element, bool ignoreStaleElementExcept
throw;
}
}


public static IWebElement ClickIfVisible(this ISearchContext driver, By by, TimeSpan? timeout = null)
=> WaitUntilClickable(driver, by, timeout ?? TimeSpan.FromSeconds(1), e => e.Click());

public static IWebElement ClickWhenAvailable(this ISearchContext driver, By by, TimeSpan? timeout = null, string errorMessage = null)
=> WaitUntilClickable(driver, by, timeout, e => e.Click(), errorMessage ?? "Unable to click element.");
public static IWebElement ClickWhenAvailable(this ISearchContext driver, By by, string errorMessage)
=> WaitUntilClickable(driver, by, null, e => e.Click(), errorMessage ?? "Unable to click element.");

public static IWebDriver ClickAndWait(this IWebDriver driver, By by, TimeSpan timeout)
public static IWebElement ClickAndWait(this IWebDriver driver, By by, TimeSpan timeout)
{
var element = driver.FindElement(by);
if (element == null)
return null;

if (element != null)
{
element.Click();
System.Threading.Thread.Sleep((int) timeout.TotalMilliseconds);
}
element.Click();
System.Threading.Thread.Sleep((int) timeout.TotalMilliseconds);

return driver;
return element;
}

public static void Hover(this IWebElement element, IWebDriver driver, bool ignoreStaleElementException = true)
Expand All @@ -75,7 +77,7 @@ public static void DoubleClick(this IWebDriver driver, IWebElement element, bool
try
{
Actions actions = new Actions(driver);
actions.DoubleClick(element).Perform();
actions.DoubleClick(element).Build().Perform();
}
catch (StaleElementReferenceException)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public void UCITestCreateOpportunity()

xrmApp.Entity.Save();
}

}

[TestMethod]
Expand Down
1 change: 1 addition & 0 deletions Microsoft.Dynamics365.UIAutomation.Sample/app.build.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<add key="OnlineUsername" value="__OnlineUsername__" xdt:Transform="Replace" xdt:Locator="Match(key)" />
<add key="OnlinePassword" value="__OnlinePassword__" xdt:Transform="Replace" xdt:Locator="Match(key)" />
<add key="OnlineCrmUrl" value="__OnlineCrmUrl__" xdt:Transform="Replace" xdt:Locator="Match(key)" />
<add key="MfaSecrectKey" value="__MfaSecrectKey__" xdt:Transform="Replace" xdt:Locator="Match(key)" />
<add key="DriversPath" value="__DriversPath__" xdt:Transform="Replace" xdt:Locator="Match(key)" />
<add key="UsePrivateMode" value="true" xdt:Transform="Replace" xdt:Locator="Match(key)" />
</appSettings>
Expand Down