Hi,
I am having trouble understanding how Assert() works. Essentially, the below VB subroutine attempts to find out if an HTML table is displaying a particular table cell after entering a search string into an interactive search field (the search occurs automatically without needing to press a [Go] button). If the table cell is not present then the routine presses a screen button [Add]. If it is present then the routine clears the search field ready for a new search.
When I execute this it fails on the first loop through, on the line:
If (Assert.IsTrue(NoMatchingTableCell.IsVisible) = True) Then
Clearly I have not understood how the Assert statement works. Please would someone help by reviewing the above VB subroutine and advise where I have gone wrong, or suggest a better alternative.
Many thanks,
Nigel Edwards, Transition Computing.
I am having trouble understanding how Assert() works. Essentially, the below VB subroutine attempts to find out if an HTML table is displaying a particular table cell after entering a search string into an interactive search field (the search occurs automatically without needing to press a [Go] button). If the table cell is not present then the routine presses a screen button [Add]. If it is present then the routine clears the search field ready for a new search.
Public
Sub
sa_SetupLookups_SetLookupTextItems()
Dim
row
As
Integer
Dim
col
As
Integer
Dim
minCol
As
Integer
= 3
'First column for lookupText values, column C
Dim
maxCol
As
Integer
= 11
'Last column for lookupText values, column K
Dim
input
As
String
=
"C:\Users\edwardni\Documents\Test Studio Projects\Accelerate\Data\AccelerateData.xlsx"
Dim
app
As
New
Microsoft.Office.Interop.Excel.Application()
'Dim inputBook As Microsoft.Office.Interop.Excel.Workbook = app.Workbooks.Open(input, 0, False, 5, "", "", False, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", True, False, 0, True, False, False) 'This is write
'Object UpdateLinks, Object ReadOnly, Object Format, Object Password, Object WriteResPassword, Object IgnoreReadOnlyRecommended, Object Origin, Object Delimiter, Object Editable, Object Notify, Object Converter, Object AddToMru, Object Local, Object CorruptLoad)
Dim
inputBook
As
Microsoft.Office.Interop.Excel.Workbook = app.Workbooks.Open(input, 0,
True
, 5,
""
,
""
,
False
, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows,
""
,
True
,
False
, 0,
True
,
False
,
False
)
'This is read-only
Dim
inputSheet
As
Microsoft.Office.Interop.Excel.Worksheet =
DirectCast
((inputBook.Worksheets.Item(
"Lookups"
)), Microsoft.Office.Interop.Excel.Worksheet)
Dim
theLookupCode
As
Object
= GetExtractedValue(
"CodeText"
)
Dim
lookupCode
As
String
= theLookupCode.ToString().Trim()
Dim
lookupText
As
String
Dim
NoMatchingTableCell
As
HtmlTableCell = Pages.LookupEdit.NoMatchingTableCell
Select
Case
lookupCode
Case
"City"
row = 2
Case
"CompanyType"
row = 3
Case
"ContactType"
row = 4
Case
"DataSourceType"
row = 5
Case
"DataType"
row = 6
Case
"IndustryType"
row = 7
Case
"SalutationType"
row = 8
Case
"Screen"
row = 9
Case
"Size"
row = 10
Case
"CategoryType"
row = 11
Case
"PriorityType"
row = 12
Case
"ProjectClientsType"
row = 13
Case
"SeverityType"
row = 14
Case
"StatusType"
row = 15
Case
Else
row = 999
End
Select
If
(row <> 999)
Then
For
col = minCol to maxCol
lookupText = TryCast(
DirectCast
(inputSheet.Cells(row, col), Microsoft.Office.Interop.Excel.Range).Text,
String
)
Log.WriteLine(
"DEBUG LINE theLookupCode: "
+ theLookupCode.ToString())
Log.WriteLine(
"DEBUG LINE lookupCode: "
+ lookupCode.ToString())
Log.WriteLine(
"DEBUG LINE row: "
+ row.ToString())
Log.WriteLine(
"DEBUG LINE col: "
+ col.ToString())
Log.WriteLine(
"DEBUG LINE lookupText: "
+ lookupText.ToString())
If
(lookupText =
"."
)
Then
Exit
For
Else
'Search table to see if lookupText already exists
Pages.LookupEdit.Text.ScrollToVisible(ArtOfTest.WebAii.Core.ScrollToVisibleType.ElementTopAtWindowTop)
ActiveBrowser.Window.SetFocus
Pages.LookupEdit.Text.MouseClick
Manager.Desktop.KeyBoard.TypeText(
""
, 50, 100)
'Clear search field of any pre-existing text
System.Threading.Thread.Sleep(1000)
'Give table time to repopulate
Pages.LookupEdit.Text.MouseClick
Manager.Desktop.KeyBoard.TypeText(lookupText, 50, 100)
'Enter value held in lookupText (e.g. London) in 'Text'
System.Threading.Thread.Sleep(1000)
'Give table time to complete the search
NoMatchingTableCell.Wait.ForExists(10000)
If
(Assert.IsTrue(NoMatchingTableCell.IsVisible) =
True
)
Then
'lookupText already exists, so empty the search field ready for the next
Pages.LookupEdit.Text.ScrollToVisible(ArtOfTest.WebAii.Core.ScrollToVisibleType.ElementTopAtWindowTop)
ActiveBrowser.Window.SetFocus
Pages.LookupEdit.Text.MouseClick
Manager.Desktop.KeyBoard.TypeText(
""
, 50, 100)
System.Threading.Thread.Sleep(1000)
Else
Pages.LookupEdit.AddSpan.Click(false)
Pages.AddNewLookupItem.HtmlTag.BaseElement.Wait.ForCondition(
Function
(a_0, a_1) ArtOfTest.Common.CompareUtils.StringCompare(a_0.InnerText,
"Add New Lookup Item"
, ArtOfTest.Common.StringCompareType.StartsWith), false,
Nothing
, 10000)
Pages.AddNewLookupItem.CultureBasedTextTextText.ScrollToVisible(ArtOfTest.WebAii.Core.ScrollToVisibleType.ElementTopAtWindowTop)
ActiveBrowser.Window.SetFocus
Pages.AddNewLookupItem.CultureBasedTextTextText.MouseClick
Manager.Desktop.KeyBoard.TypeText(lookupText, 50, 100)
'Add the new lookupText
Pages.AddNewLookupItem.ItemIsActiveCheckBox.Check(true, true)
'Check 'ItemIsActiveCheckBox' to be 'True'
Pages.AddNewLookupItem.Submit.Click(false)
'Click 'Submit' (Save button)
End
If
End
If
Next
col
End
If
'All required text entries for the supplied lookupCode have been made, so exit back to the main Lookups screen
Pages.LookupEdit.BackToListSpan.Click(false)
'Free up resources:
row =
Nothing
col =
Nothing
minCol =
Nothing
maxCol =
Nothing
input =
Nothing
app =
Nothing
inputBook =
Nothing
inputSheet =
Nothing
lookupText =
Nothing
theLookupCode =
Nothing
lookupCode =
Nothing
NoMatchingTableCell =
Nothing
'Close Excel, preventing any Save prompt, & free up the process
inputBook.Saved =
True
app.Quit()
app =
Nothing
End
Sub
When I execute this it fails on the first loop through, on the line:
If (Assert.IsTrue(NoMatchingTableCell.IsVisible) = True) Then
Clearly I have not understood how the Assert statement works. Please would someone help by reviewing the above VB subroutine and advise where I have gone wrong, or suggest a better alternative.
Many thanks,
Nigel Edwards, Transition Computing.