-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License
- */
-
-using System;
-using System.Collections.Generic;
-using NUnitLite.TUnit;
-using NUnit.Framework.TUnit;
-using NUnit.Framework.Interfaces;
-using System.Reflection;
-using ManualTemplate;
-using Xamarin.Forms;
-using Tizen.Applications;
-
-namespace NUnit.Framework
-{
- public class TestPage
- {
- private static TestPage instance;
- private static Object lockObject = new object();
-
- private NavigationPage _navigationPage;
- private ContentPage _tcContentPage;
- private Page _tcUIPage;
- private Label _summaryLabel, _tcResultText, _descriptionTitle;
- private ListView _tcDescriptions;
- private Button _runBtn, _passBtn, _failBtn, _blockBtn;
- private Button _mainBtn, _prevBtn, _nextBtn;
- private StackLayout _mainLayout, _tcUILayout;
-
- private int _tcIndex = 0;
- private List<string> _tcIDList;
- private List<ItemData> _listItem;
- private List<TestcaseInfo> _tcInfoList;
- private List<TestcaseDescription> _currentTCInfo;
- private TRunner _tunitRunner;
- private TSettings _tsettings;
- private NavigationButton _pressButton = NavigationButton.NA;
- private ToastMessage _toastMessage;
-
- private const string STEP_ATTRIBUTE_NAME = "NUnit.Framework.StepAttribute";
- private const string PRECONDITION_ATTRIBUTE_NAME = "NUnit.Framework.PreconditionAttribute";
- private const string POSTCONDITION_ATTRIBUTE_NAME = "NUnit.Framework.PostconditionAttribute";
-
- public event EventHandler<string> TestcaseDone;
-
- private void OnTestcaseDone(string e)
- {
- EventHandler<string> handler = TestcaseDone;
- if (handler != null)
- {
- handler(this, e);
- }
- }
-
- public NavigationPage getNavigationPage()
- {
- return _navigationPage;
- }
-
- public static TestPage GetInstance()
- {
- lock (lockObject)
- {
- if (instance == null)
- {
- instance = new TestPage();
- }
- }
- return instance;
- }
-
- private TestPage()
- {
- }
-
- public void Initialize(TRunner tunitRunner, List<string> testcaseIDList, List<ItemData> listItem)
- {
- _toastMessage = new ToastMessage();
- RunType.Value = RunType.MANUAL;
- _tunitRunner = tunitRunner;
- _tunitRunner.SingleTestDone += OnSingleTestDone;
- _tcInfoList = new List<TestcaseInfo>();
- _tcIDList = testcaseIDList;
- _tsettings = TSettings.GetInstance();
- _tsettings.IsManual = true;
+/*\r
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License\r
+ */\r
+\r
+using System;\r
+using System.Collections.Generic;\r
+using NUnitLite.TUnit;\r
+using NUnit.Framework.TUnit;\r
+using NUnit.Framework.Interfaces;\r
+using System.Reflection;\r
+using ManualTemplate;\r
+using Xamarin.Forms;\r
+using Tizen.Applications;\r
+\r
+namespace NUnit.Framework\r
+{\r
+ public class TestPage\r
+ {\r
+ private static TestPage instance;\r
+ private static Object lockObject = new object();\r
+\r
+ private NavigationPage _navigationPage;\r
+ private ContentPage _tcContentPage;\r
+ private Page _tcUIPage;\r
+ private Label _summaryLabel, _tcResultText, _descriptionTitle;\r
+ private ListView _tcDescriptions;\r
+ private Button _runBtn, _passBtn, _failBtn, _blockBtn;\r
+ private Button _mainBtn, _prevBtn, _nextBtn;\r
+ private StackLayout _mainLayout, _tcUILayout;\r
+\r
+ private int _tcIndex = 0;\r
+ private List<string> _tcIDList;\r
+ private List<ItemData> _listItem;\r
+ private List<TestcaseInfo> _tcInfoList;\r
+ private List<TestcaseDescription> _currentTCInfo;\r
+ private TRunner _tunitRunner;\r
+ private TSettings _tsettings;\r
+ private NavigationButton _pressButton = NavigationButton.NA;\r
+ private ToastMessage _toastMessage;\r
+\r
+ private const string STEP_ATTRIBUTE_NAME = "NUnit.Framework.StepAttribute";\r
+ private const string PRECONDITION_ATTRIBUTE_NAME = "NUnit.Framework.PreconditionAttribute";\r
+ private const string POSTCONDITION_ATTRIBUTE_NAME = "NUnit.Framework.PostconditionAttribute";\r
+\r
+ public event EventHandler<string> TestcaseDone;\r
+\r
+ private void OnTestcaseDone(string e)\r
+ {\r
+ EventHandler<string> handler = TestcaseDone;\r
+ if (handler != null)\r
+ {\r
+ handler(this, e);\r
+ }\r
+ }\r
+\r
+ public NavigationPage getNavigationPage()\r
+ {\r
+ return _navigationPage;\r
+ }\r
+\r
+ public static TestPage GetInstance()\r
+ {\r
+ lock (lockObject)\r
+ {\r
+ if (instance == null)\r
+ {\r
+ instance = new TestPage();\r
+ }\r
+ }\r
+ return instance;\r
+ }\r
+\r
+ private TestPage()\r
+ {\r
+ }\r
+\r
+ public void Initialize(TRunner tunitRunner, List<string> testcaseIDList, List<ItemData> listItem)\r
+ {\r
+ _toastMessage = new ToastMessage();\r
+ RunType.Value = RunType.MANUAL;\r
+ _tunitRunner = tunitRunner;\r
+ _tunitRunner.SingleTestDone += OnSingleTestDone;\r
+ _tcInfoList = new List<TestcaseInfo>();\r
+ _tcIDList = testcaseIDList;\r
+ _tsettings = TSettings.GetInstance();\r
+ _tsettings.IsManual = true;\r
_listItem = listItem;\r
- MakeTCInfoList();
- _summaryLabel = new Label()
- {
- Text = "",
- HorizontalOptions = LayoutOptions.CenterAndExpand,
- MinimumHeightRequest = 60,
- TextColor = Color.White
- };
- SetResultNumber(0, 0, 0);
- MakeTestPage();
- }
-
- private void OnSingleTestDone(object sender, SingleTestDoneEventArgs e)
- {
- // check old result
- if (_listItem[_tcIndex].Result.Contains(StrResult.FAIL))
- {
- ResultNumber.Fail = ResultNumber.Fail - 1;
- }
- else if (_listItem[_tcIndex].Result.Contains(StrResult.PASS))
- {
- ResultNumber.Pass = ResultNumber.Pass - 1;
- }
- else if (_listItem[_tcIndex].Result.Contains(StrResult.BLOCK))
- ResultNumber.Block = ResultNumber.Block - 1;
-
- // Update new result
- _listItem[_tcIndex].Result = e.Result;
- if (e.Result.Contains(StrResult.PASS))
- {
- ResultNumber.Pass += 1;
- }
- else if (e.Result.Contains(StrResult.FAIL))
- {
- ResultNumber.Fail += 1;
- }
- else if (e.Result.Contains(StrResult.BLOCK))
- {
- ResultNumber.Block += 1;
- }
-
- UpdateLayout();
- }
-
- private void UpdateLayout()
- {
- SetResultNumber(ResultNumber.Pass, ResultNumber.Fail, ResultNumber.Block);
- _tcResultText.Text = _listItem[_tcIndex].Result;
- SetColor(_tcResultText.Text);
- if (_tcUILayout != null)
- {
- _tcUILayout.Children.Clear();
- }
- if (_pressButton == NavigationButton.Next)
- {
- Next();
- }
- else if (_pressButton == NavigationButton.Previous)
- {
- Previous();
- }
- else if (_pressButton == NavigationButton.Home)
- {
- _navigationPage.PopAsync();
- }
- OnTestcaseDone(null);
- _passBtn.IsEnabled = false;
- _failBtn.IsEnabled = false;
- _blockBtn.IsEnabled = false;
- _runBtn.IsEnabled = true;
- _mainBtn.IsEnabled = true;
- _prevBtn.IsEnabled = true;
- _nextBtn.IsEnabled = true;
- }
-
- private void SetResultNumber(int pass, int fail, int block)
- {
- ResultNumber.NotRun = ResultNumber.Total - pass - fail - block;
- _summaryLabel.Text = "Total : " + ResultNumber.Total + ", Pass : " + pass + ", Fail : " + fail + ", Block : " + block + ", Not Run : " + ResultNumber.NotRun;
- }
-
- private void MakeTestPage()
- {
- _mainLayout = new StackLayout()
- {
- Orientation = StackOrientation.Vertical,
- IsVisible = true,
- HorizontalOptions = LayoutOptions.FillAndExpand,
- VerticalOptions = LayoutOptions.FillAndExpand,
- Spacing = 10,
- Padding = new Thickness(10),
- };
- _descriptionTitle = new Label()
- {
- Text = "DESCRIPTION:",
- HorizontalOptions = LayoutOptions.FillAndExpand,
- VerticalOptions = LayoutOptions.Start,
- HeightRequest = 50,
- TextColor = Color.White
- };
- // layout
- StackLayout functionLayout = new StackLayout()
- {
- Orientation = StackOrientation.Horizontal,
- IsVisible = true,
- HorizontalOptions = LayoutOptions.FillAndExpand,
- Spacing = 10,
- VerticalOptions = LayoutOptions.End,
- };
-
- _mainBtn = new Button()
- {
- HorizontalOptions = LayoutOptions.Start,
- Text = "Home",
- HeightRequest = 80,
- };
-
- _mainBtn.Clicked += (sender, e) =>
- {
- _pressButton = NavigationButton.Home;
- if (!ManualTest.IsConfirmed())
- {
- _tsettings.TCResult = StrResult.NOTRUN;
- ManualTest.Confirm();
- }
- else
- {
- _navigationPage.PopAsync();
- }
- };
-
- _prevBtn = new Button()
- {
- HorizontalOptions = LayoutOptions.Start,
- Text = "<<",
- HeightRequest = 80,
- };
-
- _prevBtn.Clicked += (sender, e) =>
- {
- PreviousTestcase();
- };
-
- _nextBtn = new Button()
- {
- Text = ">>",
- HorizontalOptions = LayoutOptions.Start,
- HeightRequest = 80,
- };
-
- _nextBtn.Clicked += (sender, e) =>
- {
- NextTestcase();
- };
-
- _tcResultText = new Label()
- {
- HorizontalOptions = LayoutOptions.Start,
- VerticalOptions = LayoutOptions.FillAndExpand,
- HorizontalTextAlignment = TextAlignment.Center,
- VerticalTextAlignment = TextAlignment.Center,
- HeightRequest = 80,
- };
- functionLayout.Children.Add(_mainBtn);
- functionLayout.Children.Add(_tcResultText);
- functionLayout.Children.Add(_prevBtn);
- functionLayout.Children.Add(_nextBtn);
- // Show description
- ShowDescription();
-
- var navigationLayout = new StackLayout()
- {
- Orientation = StackOrientation.Horizontal,
- IsVisible = true,
- HorizontalOptions = LayoutOptions.FillAndExpand,
- Spacing = 10,
- VerticalOptions = LayoutOptions.End,
- };
-
- _passBtn = new Button()
- {
- HorizontalOptions = LayoutOptions.Start,
- Text = "Pass",
- HeightRequest = 80,
- IsEnabled = false,
- };
-
- _passBtn.Clicked += (sender, e) =>
- {
- if (!ManualTest.IsConfirmed())
- {
- _tsettings.TCResult = StrResult.PASS;
- ManualTest.Confirm();
- }
- };
-
- _failBtn = new Button()
- {
- HorizontalOptions = LayoutOptions.Start,
- Text = "Fail",
- HeightRequest = 80,
- IsEnabled = false,
- };
-
- _failBtn.Clicked += (sender, e) =>
- {
- if (!ManualTest.IsConfirmed())
- {
- _tsettings.TCResult = StrResult.FAIL;
- ManualTest.Confirm();
- }
- };
-
- _blockBtn = new Button()
- {
- HorizontalOptions = LayoutOptions.Start,
- Text = "Block",
- HeightRequest = 80,
- IsEnabled = false,
- };
-
- _blockBtn.Clicked += (sender, e) =>
- {
- if (!ManualTest.IsConfirmed())
- {
- _tsettings.TCResult = StrResult.BLOCK;
- ManualTest.Confirm();
- }
- };
-
- _runBtn = new Button()
- {
- HorizontalOptions = LayoutOptions.Start,
- Text = "Run",
- HeightRequest = 80,
- };
-
- _runBtn.Clicked += (sender, e) =>
- {
- LockUIButton();
- _pressButton = NavigationButton.NA;
- _tsettings.Testcase_ID = _tcIDList[_tcIndex];
- _tsettings.TCResult = "";
- _tunitRunner.Execute();
- };
-
- navigationLayout.Children.Add(_passBtn);
- navigationLayout.Children.Add(_failBtn);
- navigationLayout.Children.Add(_blockBtn);
- navigationLayout.Children.Add(_runBtn);
-
- _tcUILayout = new StackLayout()
- {
- Orientation = StackOrientation.Vertical,
- HorizontalOptions = LayoutOptions.FillAndExpand,
- HeightRequest = 200
- };
-
- _mainLayout.Children.Add(_summaryLabel);
- _mainLayout.Children.Add(_descriptionTitle);
- _mainLayout.Children.Add(_tcDescriptions);
- _mainLayout.Children.Add(_tcUILayout);
- _mainLayout.Children.Add(navigationLayout);
- _mainLayout.Children.Add(functionLayout);
- _tcContentPage = new ContentPage()
- {
- Content = _mainLayout
- };
- NavigationPage.SetHasNavigationBar(_tcContentPage, false);
- }
-
- public void LockUIButton()
- {
- if (ManualTest.IsWearable())
- {
- WearableTemplate.TestPage.GetInstance().LockUIButton();
- }
- else
- {
- _runBtn.IsEnabled = false;
- _passBtn.IsEnabled = false;
- _failBtn.IsEnabled = false;
- _blockBtn.IsEnabled = false;
- _mainBtn.IsEnabled = false;
- _prevBtn.IsEnabled = false;
- _nextBtn.IsEnabled = false;
- }
- }
-
- public void UnlockUIButton()
- {
- if (ManualTest.IsWearable())
- {
- WearableTemplate.TestPage.GetInstance().UnlockUIButton();
- }
- else
- {
- _passBtn.IsEnabled = true;
- _failBtn.IsEnabled = true;
- _blockBtn.IsEnabled = true;
- _mainBtn.IsEnabled = true;
- _prevBtn.IsEnabled = true;
- _nextBtn.IsEnabled = true;
- }
- }
-
- public void Show(NavigationPage navigationPage, int testcaseIndex)
- {
- _navigationPage = navigationPage;
- _tcIndex = testcaseIndex - 1;
- _descriptionTitle.Text = "DESCRIPTION : #" + testcaseIndex;
- _tcResultText.Text = _listItem[_tcIndex].Result;
- SetColor(_tcResultText.Text);
- UpdateDescriptions();
- navigationPage.PushAsync(_tcContentPage);
- _passBtn.IsEnabled = false;
- _failBtn.IsEnabled = false;
- _blockBtn.IsEnabled = false;
- }
-
- private void NextTestcase()
- {
- _pressButton = NavigationButton.Next;
- if (!ManualTest.IsConfirmed())
- {
- _tsettings.TCResult = StrResult.NOTRUN;
- ManualTest.Confirm();
- }
- else
- {
- Next();
- }
- }
-
- private void Next()
- {
- if (_tcIndex < _tcIDList.Count - 1)
- {
- _tcIndex = _tcIndex + 1;
- _descriptionTitle.Text = "DESCRIPTION : #" + (_tcIndex + 1);
- _tcResultText.Text = _listItem[_tcIndex].Result;
- SetColor(_tcResultText.Text);
- UpdateDescriptions();
- }
- else if (_tcIndex == _tcIDList.Count - 1)
- {
- _toastMessage.Message = "This is last testcase";
- _toastMessage.Post();
- }
- }
-
- private void PreviousTestcase()
- {
- _pressButton = NavigationButton.Previous;
- if (!ManualTest.IsConfirmed())
- {
- _tsettings.TCResult = StrResult.NOTRUN;
- ManualTest.Confirm();
- }
- else
- {
- Previous();
- }
- }
-
- private void Previous()
- {
- if (_tcIndex > 0)
- {
- _tcIndex = _tcIndex - 1;
- _descriptionTitle.Text = "DESCRIPTION : #" + (_tcIndex + 1);
- _tcResultText.Text = _listItem[_tcIndex].Result;
- SetColor(_tcResultText.Text);
- UpdateDescriptions();
- }
- else if (_tcIndex == 0)
- {
- _toastMessage.Message = "This is first testcase";
- _toastMessage.Post();
- }
- }
-
- private void SetColor(string result)
- {
- if (result.Equals(StrResult.PASS))
- {
- _tcResultText.TextColor = Color.Green;
- }
- else if (result.Equals(StrResult.FAIL))
- {
- _tcResultText.TextColor = Color.Red;
- }
- else if (result.Equals(StrResult.BLOCK))
- {
- _tcResultText.TextColor = Color.Orange;
- }
- else
- {
- _tcResultText.TextColor = Color.White;
- }
- }
-
- private int FindMaxLineDescription()
- {
- int maxLine = 0;
- for (int i = 0; i < _tcInfoList.Count; i++)
- {
- int len = _tcInfoList[i].Steps.Count + _tcInfoList[i].Preconditions.Count + _tcInfoList[i].Postconditions.Count;
- maxLine = maxLine < len ? len : maxLine;
- }
- return maxLine;
- }
-
- private void ShowDescription()
- {
- int lenght = FindMaxLineDescription() + 3;
- var template = new DataTemplate(() =>
- {
- var grid = new Grid();
-
- var descriptionLabel = new Label
- {
- HorizontalOptions = LayoutOptions.FillAndExpand,
- LineBreakMode = LineBreakMode.CharacterWrap
- };
-
- descriptionLabel.SetBinding(Label.TextProperty, new Binding("Description"));
-
- grid.Children.Add(descriptionLabel);
-
- return new ViewCell
- {
- View = grid,
- };
- });
-
- _tcDescriptions = new ListView()
- {
- ItemTemplate = template,
- HorizontalOptions = LayoutOptions.FillAndExpand,
- RowHeight = 150,
- Margin = new Thickness(10),
- };
- _currentTCInfo = new List<TestcaseDescription>();
-
- for (int i = 0; i < lenght; i++)
- {
- _currentTCInfo.Add(new TestcaseDescription(""));
- }
- UpdateDescriptions();
- _tcDescriptions.ItemsSource = _currentTCInfo;
- }
-
- private void UpdateDescriptions()
- {
- _prevBtn.IsEnabled = false;
- _nextBtn.IsEnabled = false;
- int lenght = FindMaxLineDescription() + 3;
- for (int i = 0; i < lenght; i++)
- {
- _currentTCInfo[i].Description = "";
- }
- int index = 0;
- _currentTCInfo[index].Description = "TC : " + _tcInfoList[_tcIndex].TestcaseName;
- foreach (string precondition in _tcInfoList[_tcIndex].Preconditions.ToArray())
- {
- index++;
- _currentTCInfo[index].Description = precondition;
- }
- foreach (string step in _tcInfoList[_tcIndex].Steps.ToArray())
- {
- index++;
- _currentTCInfo[index].Description = step;
- }
- foreach (string postcondition in _tcInfoList[_tcIndex].Postconditions.ToArray())
- {
- index++;
- _currentTCInfo[index].Description = postcondition;
- }
- _prevBtn.IsEnabled = true;
- _nextBtn.IsEnabled = true;
- }
-
- private void MakeTCInfoList()
- {
- foreach (var testcaseItem in _listItem)
+ MakeTCInfoList();\r
+ _summaryLabel = new Label()\r
+ {\r
+ Text = "",\r
+ HorizontalOptions = LayoutOptions.CenterAndExpand,\r
+ MinimumHeightRequest = 60,\r
+ TextColor = Color.White\r
+ };\r
+ SetResultNumber(0, 0, 0);\r
+ MakeTestPage();\r
+ }\r
+\r
+ private void OnSingleTestDone(object sender, SingleTestDoneEventArgs e)\r
+ {\r
+ // check old result\r
+ if (_listItem[_tcIndex].Result.Contains(StrResult.FAIL))\r
+ {\r
+ ResultNumber.Fail = ResultNumber.Fail - 1;\r
+ }\r
+ else if (_listItem[_tcIndex].Result.Contains(StrResult.PASS))\r
+ {\r
+ ResultNumber.Pass = ResultNumber.Pass - 1;\r
+ }\r
+ else if (_listItem[_tcIndex].Result.Contains(StrResult.BLOCK))\r
+ ResultNumber.Block = ResultNumber.Block - 1;\r
+\r
+ // Update new result\r
+ _listItem[_tcIndex].Result = e.Result;\r
+ if (e.Result.Contains(StrResult.PASS))\r
+ {\r
+ ResultNumber.Pass += 1;\r
+ }\r
+ else if (e.Result.Contains(StrResult.FAIL))\r
+ {\r
+ ResultNumber.Fail += 1;\r
+ }\r
+ else if (e.Result.Contains(StrResult.BLOCK))\r
+ {\r
+ ResultNumber.Block += 1;\r
+ }\r
+\r
+ UpdateLayout();\r
+ }\r
+\r
+ private void UpdateLayout()\r
+ {\r
+ SetResultNumber(ResultNumber.Pass, ResultNumber.Fail, ResultNumber.Block);\r
+ _tcResultText.Text = _listItem[_tcIndex].Result;\r
+ SetColor(_tcResultText.Text);\r
+ if (_tcUILayout != null)\r
+ {\r
+ _tcUILayout.Children.Clear();\r
+ }\r
+ if (_pressButton == NavigationButton.Next)\r
+ {\r
+ Next();\r
+ }\r
+ else if (_pressButton == NavigationButton.Previous)\r
+ {\r
+ Previous();\r
+ }\r
+ else if (_pressButton == NavigationButton.Home)\r
+ {\r
+ _navigationPage.PopAsync();\r
+ }\r
+ OnTestcaseDone(null);\r
+ _passBtn.IsEnabled = false;\r
+ _failBtn.IsEnabled = false;\r
+ _blockBtn.IsEnabled = false;\r
+ _runBtn.IsEnabled = true;\r
+ _mainBtn.IsEnabled = true;\r
+ _prevBtn.IsEnabled = true;\r
+ _nextBtn.IsEnabled = true;\r
+ }\r
+\r
+ private void SetResultNumber(int pass, int fail, int block)\r
+ {\r
+ ResultNumber.NotRun = ResultNumber.Total - pass - fail - block;\r
+ _summaryLabel.Text = "Total : " + ResultNumber.Total + ", Pass : " + pass + ", Fail : " + fail + ", Block : " + block + ", Not Run : " + ResultNumber.NotRun;\r
+ }\r
+\r
+ private void MakeTestPage()\r
+ {\r
+ _mainLayout = new StackLayout()\r
+ {\r
+ Orientation = StackOrientation.Vertical,\r
+ IsVisible = true,\r
+ HorizontalOptions = LayoutOptions.FillAndExpand,\r
+ VerticalOptions = LayoutOptions.FillAndExpand,\r
+ Spacing = 10,\r
+ Padding = new Thickness(10),\r
+ };\r
+ _descriptionTitle = new Label()\r
+ {\r
+ Text = "DESCRIPTION:",\r
+ HorizontalOptions = LayoutOptions.FillAndExpand,\r
+ VerticalOptions = LayoutOptions.Start,\r
+ HeightRequest = 50,\r
+ TextColor = Color.White\r
+ };\r
+ // layout\r
+ StackLayout functionLayout = new StackLayout()\r
+ {\r
+ Orientation = StackOrientation.Horizontal,\r
+ IsVisible = true,\r
+ HorizontalOptions = LayoutOptions.FillAndExpand,\r
+ Spacing = 10,\r
+ VerticalOptions = LayoutOptions.End,\r
+ };\r
+\r
+ _mainBtn = new Button()\r
+ {\r
+ HorizontalOptions = LayoutOptions.Start,\r
+ Text = "Home",\r
+ HeightRequest = 80,\r
+ };\r
+\r
+ _mainBtn.Clicked += (sender, e) =>\r
+ {\r
+ _pressButton = NavigationButton.Home;\r
+ if (!ManualTest.IsConfirmed())\r
+ {\r
+ _tsettings.TCResult = StrResult.NOTRUN;\r
+ ManualTest.Confirm();\r
+ }\r
+ else\r
+ {\r
+ _navigationPage.PopAsync();\r
+ }\r
+ };\r
+\r
+ _prevBtn = new Button()\r
+ {\r
+ HorizontalOptions = LayoutOptions.Start,\r
+ Text = "<<",\r
+ HeightRequest = 80,\r
+ };\r
+\r
+ _prevBtn.Clicked += (sender, e) =>\r
+ {\r
+ PreviousTestcase();\r
+ };\r
+\r
+ _nextBtn = new Button()\r
+ {\r
+ Text = ">>",\r
+ HorizontalOptions = LayoutOptions.Start,\r
+ HeightRequest = 80,\r
+ };\r
+\r
+ _nextBtn.Clicked += (sender, e) =>\r
+ {\r
+ NextTestcase();\r
+ };\r
+\r
+ _tcResultText = new Label()\r
+ {\r
+ HorizontalOptions = LayoutOptions.Start,\r
+ VerticalOptions = LayoutOptions.FillAndExpand,\r
+ HorizontalTextAlignment = TextAlignment.Center,\r
+ VerticalTextAlignment = TextAlignment.Center,\r
+ HeightRequest = 80,\r
+ };\r
+ functionLayout.Children.Add(_mainBtn);\r
+ functionLayout.Children.Add(_tcResultText);\r
+ functionLayout.Children.Add(_prevBtn);\r
+ functionLayout.Children.Add(_nextBtn);\r
+ // Show description\r
+ ShowDescription();\r
+\r
+ var navigationLayout = new StackLayout()\r
+ {\r
+ Orientation = StackOrientation.Horizontal,\r
+ IsVisible = true,\r
+ HorizontalOptions = LayoutOptions.FillAndExpand,\r
+ Spacing = 10,\r
+ VerticalOptions = LayoutOptions.End,\r
+ };\r
+\r
+ _passBtn = new Button()\r
+ {\r
+ HorizontalOptions = LayoutOptions.Start,\r
+ Text = "Pass",\r
+ HeightRequest = 80,\r
+ IsEnabled = false,\r
+ };\r
+\r
+ _passBtn.Clicked += (sender, e) =>\r
+ {\r
+ if (!ManualTest.IsConfirmed())\r
+ {\r
+ _tsettings.TCResult = StrResult.PASS;\r
+ ManualTest.Confirm();\r
+ }\r
+ };\r
+\r
+ _failBtn = new Button()\r
+ {\r
+ HorizontalOptions = LayoutOptions.Start,\r
+ Text = "Fail",\r
+ HeightRequest = 80,\r
+ IsEnabled = false,\r
+ };\r
+\r
+ _failBtn.Clicked += (sender, e) =>\r
+ {\r
+ if (!ManualTest.IsConfirmed())\r
+ {\r
+ _tsettings.TCResult = StrResult.FAIL;\r
+ ManualTest.Confirm();\r
+ }\r
+ };\r
+\r
+ _blockBtn = new Button()\r
+ {\r
+ HorizontalOptions = LayoutOptions.Start,\r
+ Text = "Block",\r
+ HeightRequest = 80,\r
+ IsEnabled = false,\r
+ };\r
+\r
+ _blockBtn.Clicked += (sender, e) =>\r
+ {\r
+ if (!ManualTest.IsConfirmed())\r
+ {\r
+ _tsettings.TCResult = StrResult.BLOCK;\r
+ ManualTest.Confirm();\r
+ }\r
+ };\r
+\r
+ _runBtn = new Button()\r
+ {\r
+ HorizontalOptions = LayoutOptions.Start,\r
+ Text = "Run",\r
+ HeightRequest = 80,\r
+ };\r
+\r
+ _runBtn.Clicked += (sender, e) =>\r
+ {\r
+ LockUIButton();\r
+ _pressButton = NavigationButton.NA;\r
+ _tsettings.Testcase_ID = _tcIDList[_tcIndex];\r
+ _tsettings.TCResult = "";\r
+ _tunitRunner.Execute();\r
+ };\r
+\r
+ navigationLayout.Children.Add(_passBtn);\r
+ navigationLayout.Children.Add(_failBtn);\r
+ navigationLayout.Children.Add(_blockBtn);\r
+ navigationLayout.Children.Add(_runBtn);\r
+\r
+ _tcUILayout = new StackLayout()\r
+ {\r
+ Orientation = StackOrientation.Vertical,\r
+ HorizontalOptions = LayoutOptions.FillAndExpand,\r
+ HeightRequest = 200\r
+ };\r
+\r
+ _mainLayout.Children.Add(_summaryLabel);\r
+ _mainLayout.Children.Add(_descriptionTitle);\r
+ _mainLayout.Children.Add(_tcDescriptions);\r
+ _mainLayout.Children.Add(_tcUILayout);\r
+ _mainLayout.Children.Add(navigationLayout);\r
+ _mainLayout.Children.Add(functionLayout);\r
+ _tcContentPage = new ContentPage()\r
+ {\r
+ Content = _mainLayout\r
+ };\r
+ NavigationPage.SetHasNavigationBar(_tcContentPage, false);\r
+ }\r
+\r
+ public void LockUIButton()\r
+ {\r
+ if (ManualTest.IsWearable())\r
+ {\r
+ WearableTemplate.TestPage.GetInstance().LockUIButton();\r
+ }\r
+ else\r
+ {\r
+ _runBtn.IsEnabled = false;\r
+ _passBtn.IsEnabled = false;\r
+ _failBtn.IsEnabled = false;\r
+ _blockBtn.IsEnabled = false;\r
+ _mainBtn.IsEnabled = false;\r
+ _prevBtn.IsEnabled = false;\r
+ _nextBtn.IsEnabled = false;\r
+ }\r
+ }\r
+\r
+ public void UnlockUIButton()\r
+ {\r
+ if (ManualTest.IsWearable())\r
+ {\r
+ WearableTemplate.TestPage.GetInstance().UnlockUIButton();\r
+ }\r
+ else\r
+ {\r
+ _passBtn.IsEnabled = true;\r
+ _failBtn.IsEnabled = true;\r
+ _blockBtn.IsEnabled = true;\r
+ _mainBtn.IsEnabled = true;\r
+ _prevBtn.IsEnabled = true;\r
+ _nextBtn.IsEnabled = true;\r
+ }\r
+ }\r
+\r
+ public void Show(NavigationPage navigationPage, int testcaseIndex)\r
+ {\r
+ _navigationPage = navigationPage;\r
+ _tcIndex = testcaseIndex - 1;\r
+ _descriptionTitle.Text = "DESCRIPTION : #" + testcaseIndex;\r
+ _tcResultText.Text = _listItem[_tcIndex].Result;\r
+ SetColor(_tcResultText.Text);\r
+ UpdateDescriptions();\r
+ navigationPage.PushAsync(_tcContentPage);\r
+ _passBtn.IsEnabled = false;\r
+ _failBtn.IsEnabled = false;\r
+ _blockBtn.IsEnabled = false;\r
+ }\r
+\r
+ private void NextTestcase()\r
+ {\r
+ _pressButton = NavigationButton.Next;\r
+ if (!ManualTest.IsConfirmed())\r
+ {\r
+ _tsettings.TCResult = StrResult.NOTRUN;\r
+ ManualTest.Confirm();\r
+ }\r
+ else\r
+ {\r
+ Next();\r
+ }\r
+ }\r
+\r
+ private void Next()\r
+ {\r
+ if (_tcIndex < _tcIDList.Count - 1)\r
+ {\r
+ _tcIndex = _tcIndex + 1;\r
+ _descriptionTitle.Text = "DESCRIPTION : #" + (_tcIndex + 1);\r
+ _tcResultText.Text = _listItem[_tcIndex].Result;\r
+ SetColor(_tcResultText.Text);\r
+ UpdateDescriptions();\r
+ }\r
+ else if (_tcIndex == _tcIDList.Count - 1)\r
+ {\r
+ _toastMessage.Message = "This is last testcase";\r
+ _toastMessage.Post();\r
+ }\r
+ }\r
+\r
+ private void PreviousTestcase()\r
+ {\r
+ _pressButton = NavigationButton.Previous;\r
+ if (!ManualTest.IsConfirmed())\r
+ {\r
+ _tsettings.TCResult = StrResult.NOTRUN;\r
+ ManualTest.Confirm();\r
+ }\r
+ else\r
+ {\r
+ Previous();\r
+ }\r
+ }\r
+\r
+ private void Previous()\r
+ {\r
+ if (_tcIndex > 0)\r
+ {\r
+ _tcIndex = _tcIndex - 1;\r
+ _descriptionTitle.Text = "DESCRIPTION : #" + (_tcIndex + 1);\r
+ _tcResultText.Text = _listItem[_tcIndex].Result;\r
+ SetColor(_tcResultText.Text);\r
+ UpdateDescriptions();\r
+ }\r
+ else if (_tcIndex == 0)\r
+ {\r
+ _toastMessage.Message = "This is first testcase";\r
+ _toastMessage.Post();\r
+ }\r
+ }\r
+\r
+ private void SetColor(string result)\r
+ {\r
+ if (result.Equals(StrResult.PASS))\r
+ {\r
+ _tcResultText.TextColor = Color.Green;\r
+ }\r
+ else if (result.Equals(StrResult.FAIL))\r
+ {\r
+ _tcResultText.TextColor = Color.Red;\r
+ }\r
+ else if (result.Equals(StrResult.BLOCK))\r
+ {\r
+ _tcResultText.TextColor = Color.Orange;\r
+ }\r
+ else\r
+ {\r
+ _tcResultText.TextColor = Color.White;\r
+ }\r
+ }\r
+\r
+ private int FindMaxLineDescription()\r
+ {\r
+ int maxLine = 0;\r
+ for (int i = 0; i < _tcInfoList.Count; i++)\r
+ {\r
+ int len = _tcInfoList[i].Steps.Count + _tcInfoList[i].Preconditions.Count + _tcInfoList[i].Postconditions.Count;\r
+ maxLine = maxLine < len ? len : maxLine;\r
+ }\r
+ return maxLine;\r
+ }\r
+\r
+ private void ShowDescription()\r
+ {\r
+ int lenght = FindMaxLineDescription() + 3;\r
+ var template = new DataTemplate(() =>\r
+ {\r
+ var grid = new Grid();\r
+\r
+ var descriptionLabel = new Label\r
+ {\r
+ HorizontalOptions = LayoutOptions.FillAndExpand,\r
+ LineBreakMode = LineBreakMode.CharacterWrap\r
+ };\r
+\r
+ descriptionLabel.SetBinding(Label.TextProperty, new Binding("Description"));\r
+\r
+ grid.Children.Add(descriptionLabel);\r
+\r
+ return new ViewCell\r
+ {\r
+ View = grid,\r
+ };\r
+ });\r
+\r
+ _tcDescriptions = new ListView()\r
+ {\r
+ ItemTemplate = template,\r
+ HorizontalOptions = LayoutOptions.FillAndExpand,\r
+ RowHeight = 150,\r
+ Margin = new Thickness(10),\r
+ };\r
+ _currentTCInfo = new List<TestcaseDescription>();\r
+\r
+ for (int i = 0; i < lenght; i++)\r
+ {\r
+ _currentTCInfo.Add(new TestcaseDescription(""));\r
+ }\r
+ UpdateDescriptions();\r
+ _tcDescriptions.ItemsSource = _currentTCInfo;\r
+ }\r
+\r
+ private void UpdateDescriptions()\r
+ {\r
+ _prevBtn.IsEnabled = false;\r
+ _nextBtn.IsEnabled = false;\r
+ int lenght = FindMaxLineDescription() + 3;\r
+ for (int i = 0; i < lenght; i++)\r
+ {\r
+ _currentTCInfo[i].Description = "";\r
+ }\r
+ int index = 0;\r
+ if(_tcInfoList.Count == 0)\r
+ {\r
+ _toastMessage.Message = "Some testing class wrong, plz recheck";\r
+ _toastMessage.Post();\r
+ return;\r
+ }\r
+\r
+ _currentTCInfo[index].Description = "TC : " + _tcInfoList[_tcIndex].TestcaseName;\r
+ foreach (string precondition in _tcInfoList[_tcIndex].Preconditions.ToArray())\r
+ {\r
+ index++;\r
+ _currentTCInfo[index].Description = precondition;\r
+ }\r
+ foreach (string step in _tcInfoList[_tcIndex].Steps.ToArray())\r
+ {\r
+ index++;\r
+ _currentTCInfo[index].Description = step;\r
+ }\r
+ foreach (string postcondition in _tcInfoList[_tcIndex].Postconditions.ToArray())\r
+ {\r
+ index++;\r
+ _currentTCInfo[index].Description = postcondition;\r
+ }\r
+ _prevBtn.IsEnabled = true;\r
+ _nextBtn.IsEnabled = true;\r
+ }\r
+\r
+ private void MakeTCInfoList()\r
+ {\r
+ foreach (var testcaseItem in _listItem)\r
{\r
foreach (KeyValuePair<string, ITest> pair in _tunitRunner.GetTestList())\r
{\r
});\r
break;\r
}\r
- }
- }
- }
-
- public void ExecuteTC(Layout layout)
- {
- if (ManualTest.IsWearable())
- {
- WearableTemplate.TestPage.GetInstance().ExecuteTC(layout);
- }
- else
- {
- _tcUILayout.Children.Add(layout);
- }
- }
-
- public void ExecuteTC(Page page)
- {
- if (ManualTest.IsWearable())
- {
- if (String.IsNullOrEmpty(page.Title))
- {
- NavigationPage.SetHasNavigationBar(page, false);
- }
- WearableTemplate.TestPage.GetInstance().ExecuteTC(page);
- }
- else
- {
- _tcUIPage = page;
- _navigationPage.PushAsync(page);
- }
- }
- }
-}
+ }\r
+ }\r
+ }\r
+\r
+ public void ExecuteTC(Layout layout)\r
+ {\r
+ if (ManualTest.IsWearable())\r
+ {\r
+ WearableTemplate.TestPage.GetInstance().ExecuteTC(layout);\r
+ }\r
+ else\r
+ {\r
+ _tcUILayout.Children.Add(layout);\r
+ }\r
+ }\r
+\r
+ public void ExecuteTC(Page page)\r
+ {\r
+ if (ManualTest.IsWearable())\r
+ {\r
+ if (String.IsNullOrEmpty(page.Title))\r
+ {\r
+ NavigationPage.SetHasNavigationBar(page, false);\r
+ }\r
+ WearableTemplate.TestPage.GetInstance().ExecuteTC(page);\r
+ }\r
+ else\r
+ {\r
+ _tcUIPage = page;\r
+ _navigationPage.PushAsync(page);\r
+ }\r
+ }\r
+ }\r
+}\r
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License
- */
-
-using System;
-using System.Collections.Generic;
-using NUnitLite.TUnit;
-using NUnit.Framework.TUnit;
-using NUnit.Framework.Interfaces;
-using System.Reflection;
-using Xamarin.Forms;
-using Tizen.Applications;
-
-namespace WearableTemplate
-{
- public class TestPage
- {
- private static TestPage instance;
- private static Object lockObject = new object();
-
- private NavigationPage _navigationPage;
- private ContentPage _tcContentPage;
- private Page _tcUIPage;
- private Label _summaryLabel1, _summaryLabel2, _tcResultText, _descriptionTitle;
- private ListView _tcDescriptions;
- private Button _runBtn, _passBtn, _failBtn, _blockBtn;
- private Button _mainBtn, _prevBtn, _nextBtn;
- private StackLayout _mainLayout, _tcUILayout;
-
- private int _tcIndex = 0;
- private List<string> _tcIDList;
- private List<ItemData> _listItem;
- private List<TestcaseInfo> _tcInfoList;
- private List<TestcaseDescription> _currentTCInfo;
- private TRunner _tunitRunner;
- private TSettings _tsettings;
- private NavigationButton _pressButton = NavigationButton.NA;
- private ToastMessage _toastMessage;
-
- private const string STEP_ATTRIBUTE_NAME = "NUnit.Framework.StepAttribute";
- private const string PRECONDITION_ATTRIBUTE_NAME = "NUnit.Framework.PreconditionAttribute";
- private const string POSTCONDITION_ATTRIBUTE_NAME = "NUnit.Framework.PostconditionAttribute";
-
- public event EventHandler<string> TestcaseDone;
-
- private void OnTestcaseDone(string e)
- {
- EventHandler<string> handler = TestcaseDone;
- if (handler != null)
- {
- handler(this, e);
- }
- }
-
- public NavigationPage getNavigationPage()
- {
- return _navigationPage;
- }
-
- public static TestPage GetInstance()
- {
-
- lock (lockObject)
- {
- if (instance == null)
- {
- instance = new TestPage();
- }
- }
- return instance;
- }
-
- private TestPage()
- {
- }
-
- public void Initialize(TRunner tunitRunner, List<string> testcaseIDList, List<ItemData> listItem)
- {
- _toastMessage = new ToastMessage();
- RunType.Value = RunType.MANUAL;
- _tunitRunner = tunitRunner;
- _tunitRunner.SingleTestDone += OnSingleTestDone;
- _tcInfoList = new List<TestcaseInfo>();
- _tcIDList = testcaseIDList;
- _tsettings = TSettings.GetInstance();
- _tsettings.IsManual = true;
- _listItem = listItem;
- MakeTCInfoList();
-
- _summaryLabel1 = new Label()
- {
- Text = "",
- HeightRequest = 25,
- HorizontalOptions = LayoutOptions.Center,
- VerticalOptions = LayoutOptions.Center,
- TextColor = Color.White,
- FontSize = 5,
- };
- _summaryLabel2 = new Label()
- {
- Text = "",
- HeightRequest = 25,
- HorizontalOptions = LayoutOptions.Center,
- VerticalOptions = LayoutOptions.Center,
- TextColor = Color.White,
- FontSize = 5,
- };
- SetResultNumber(0, 0, 0);
- MakeTestPage();
- }
-
- private void OnSingleTestDone(object sender, SingleTestDoneEventArgs e)
- {
- // check old result
- if (_listItem[_tcIndex].Result.Contains(StrResult.FAIL))
- {
- ResultNumber.Fail = ResultNumber.Fail - 1;
- }
- else if (_listItem[_tcIndex].Result.Contains(StrResult.PASS))
- {
- ResultNumber.Pass = ResultNumber.Pass - 1;
- }
- else if (_listItem[_tcIndex].Result.Contains(StrResult.BLOCK))
- ResultNumber.Block = ResultNumber.Block - 1;
-
- // Update new result
- _listItem[_tcIndex].Result = e.Result;
- if (e.Result.Contains(StrResult.PASS))
- {
- ResultNumber.Pass += 1;
- }
- else if (e.Result.Contains(StrResult.FAIL))
- {
- ResultNumber.Fail += 1;
- }
- else if (e.Result.Contains(StrResult.BLOCK))
- {
- ResultNumber.Block += 1;
- }
-
- UpdateLayout();
- }
-
- private void UpdateLayout()
- {
- SetResultNumber(ResultNumber.Pass, ResultNumber.Fail, ResultNumber.Block);
- _tcResultText.Text = _listItem[_tcIndex].Result;
- SetColor(_tcResultText.Text);
- if (_tcUILayout != null)
- {
- _tcUILayout.Children.Clear();
- }
- if (_pressButton == NavigationButton.Next)
- {
- Next();
- }
- else if (_pressButton == NavigationButton.Previous)
- {
- Previous();
- }
- else if (_pressButton == NavigationButton.Home)
- {
- _navigationPage.PopAsync();
- }
- OnTestcaseDone(null);
- _passBtn.IsEnabled = false;
- _failBtn.IsEnabled = false;
- _blockBtn.IsEnabled = false;
- _runBtn.IsEnabled = true;
- _mainBtn.IsEnabled = true;
- _prevBtn.IsEnabled = true;
- _nextBtn.IsEnabled = true;
- }
-
- private void SetResultNumber(int pass, int fail, int block)
- {
- ResultNumber.NotRun = ResultNumber.Total - pass - fail - block;
- _summaryLabel1.Text = "T : " + ResultNumber.Total + ", P : " + pass;
- _summaryLabel2.Text = "F : " + fail + ", B : " + block + ", NR : " + ResultNumber.NotRun;
- }
-
- private void MakeTestPage()
- {
- _mainLayout = new StackLayout()
- {
- Orientation = StackOrientation.Vertical,
- IsVisible = true,
- HorizontalOptions = LayoutOptions.CenterAndExpand,
- VerticalOptions = LayoutOptions.CenterAndExpand,
- Spacing = 5,
- Padding = new Thickness(10),
- };
- _descriptionTitle = new Label()
- {
- Text = "DESCRIPTION:",
- HorizontalOptions = LayoutOptions.FillAndExpand,
- VerticalOptions = LayoutOptions.Start,
- HeightRequest = 23,
- Margin = new Thickness(40, 0, 0, 0),
- FontSize = 5,
- TextColor = Color.White,
- };
-
- StackLayout functionLayout = new StackLayout()
- {
- Orientation = StackOrientation.Horizontal,
- IsVisible = true,
- HeightRequest = 30,
- HorizontalOptions = LayoutOptions.CenterAndExpand,
- VerticalOptions = LayoutOptions.Start,
- Spacing = 2,
- Margin = new Thickness(0, 0, 0, 15)
- };
-
- _mainBtn = new Button()
- {
- HorizontalOptions = LayoutOptions.Start,
- Text = "H",
- HeightRequest = 30,
- WidthRequest = 55,
- FontSize = 5
- };
-
- _mainBtn.Clicked += (sender, e) =>
- {
- _pressButton = NavigationButton.Home;
- if (!ManualTest.IsConfirmed())
- {
- _tsettings.TCResult = StrResult.NOTRUN;
- ManualTest.Confirm();
- }
- else
- {
- _navigationPage.PopAsync();
- }
- };
-
- _prevBtn = new Button()
- {
- HorizontalOptions = LayoutOptions.Start,
- Text = "<<",
- HeightRequest = 30,
- WidthRequest = 55,
- FontSize = 4
- };
-
- _prevBtn.Clicked += (sender, e) =>
- {
- PreviousTestcase();
- };
-
- _nextBtn = new Button()
- {
- Text = ">>",
- HorizontalOptions = LayoutOptions.Start,
- HeightRequest = 30,
- WidthRequest = 55,
- FontSize = 4
- };
-
- _nextBtn.Clicked += (sender, e) =>
- {
- NextTestcase();
- };
-
- _tcResultText = new Label()
- {
- HorizontalOptions = LayoutOptions.Start,
- VerticalOptions = LayoutOptions.FillAndExpand,
- HorizontalTextAlignment = TextAlignment.Center,
- VerticalTextAlignment = TextAlignment.Center,
- HeightRequest = 30,
- FontSize = 3
- };
- functionLayout.Children.Add(_mainBtn);
- functionLayout.Children.Add(_tcResultText);
- functionLayout.Children.Add(_prevBtn);
- functionLayout.Children.Add(_nextBtn);
- // Show description
- ShowDescription();
-
- var navigationLayout = new StackLayout()
- {
- Orientation = StackOrientation.Horizontal,
- IsVisible = true,
- HeightRequest = 30,
- HorizontalOptions = LayoutOptions.CenterAndExpand,
- VerticalOptions = LayoutOptions.Start,
- Spacing = 5,
- };
-
- _passBtn = new Button()
- {
- HorizontalOptions = LayoutOptions.Start,
- Text = "P",
- HeightRequest = 30,
- IsEnabled = false,
- FontSize = 5,
- WidthRequest = 60
- };
-
- _passBtn.Clicked += (sender, e) =>
- {
- if (!ManualTest.IsConfirmed())
- {
- _tsettings.TCResult = StrResult.PASS;
- ManualTest.Confirm();
- }
- };
-
- _failBtn = new Button()
- {
- HorizontalOptions = LayoutOptions.Start,
- Text = "F",
- HeightRequest = 30,
- IsEnabled = false,
- FontSize = 5,
- WidthRequest = 60
- };
-
- _failBtn.Clicked += (sender, e) =>
- {
- if (!ManualTest.IsConfirmed())
- {
- _tsettings.TCResult = StrResult.FAIL;
- ManualTest.Confirm();
- }
- };
-
- _blockBtn = new Button()
- {
- HorizontalOptions = LayoutOptions.Start,
- Text = "B",
- HeightRequest = 30,
- IsEnabled = false,
- FontSize = 5,
- WidthRequest = 60
- };
-
- _blockBtn.Clicked += (sender, e) =>
- {
- if (!ManualTest.IsConfirmed())
- {
- _tsettings.TCResult = StrResult.BLOCK;
- ManualTest.Confirm();
- }
- };
-
- _runBtn = new Button()
- {
- HorizontalOptions = LayoutOptions.Start,
- Text = "R",
- HeightRequest = 30,
- FontSize = 5,
- WidthRequest = 60
- };
-
- _runBtn.Clicked += (sender, e) =>
- {
- LockUIButton();
- _pressButton = NavigationButton.NA;
- _tsettings.Testcase_ID = _tcIDList[_tcIndex];
- _tsettings.TCResult = "";
- _tunitRunner.Execute();
- };
-
- navigationLayout.Children.Add(_passBtn);
- navigationLayout.Children.Add(_failBtn);
- navigationLayout.Children.Add(_blockBtn);
- navigationLayout.Children.Add(_runBtn);
-
- _tcUILayout = new StackLayout()
- {
- Orientation = StackOrientation.Vertical,
- HorizontalOptions = LayoutOptions.FillAndExpand,
- VerticalOptions = LayoutOptions.Start,
- HeightRequest = 40,
- WidthRequest = 280,
- Margin = new Thickness(10, 0, 10, 0)
- };
-
- _mainLayout.Children.Add(_summaryLabel1);
- _mainLayout.Children.Add(_summaryLabel2);
- _mainLayout.Children.Add(_descriptionTitle);
- _mainLayout.Children.Add(_tcDescriptions);
- _mainLayout.Children.Add(_tcUILayout);
- _mainLayout.Children.Add(navigationLayout);
- _mainLayout.Children.Add(functionLayout);
- _tcContentPage = new ContentPage()
- {
- Content = _mainLayout
- };
- NavigationPage.SetHasNavigationBar(_tcContentPage, false);
- }
-
- public void LockUIButton()
- {
- _runBtn.IsEnabled = false;
- _passBtn.IsEnabled = false;
- _failBtn.IsEnabled = false;
- _blockBtn.IsEnabled = false;
- _mainBtn.IsEnabled = false;
- _prevBtn.IsEnabled = false;
- _nextBtn.IsEnabled = false;
-
- }
-
- public void UnlockUIButton()
- {
- _passBtn.IsEnabled = true;
- _failBtn.IsEnabled = true;
- _blockBtn.IsEnabled = true;
- _mainBtn.IsEnabled = true;
- _prevBtn.IsEnabled = true;
- _nextBtn.IsEnabled = true;
- }
-
- public void Show(NavigationPage navigationPage, int testcaseIndex)
- {
+/*\r
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License\r
+ */\r
+\r
+using System;\r
+using System.Collections.Generic;\r
+using NUnitLite.TUnit;\r
+using NUnit.Framework.TUnit;\r
+using NUnit.Framework.Interfaces;\r
+using System.Reflection;\r
+using Xamarin.Forms;\r
+using Tizen.Applications;\r
+\r
+namespace WearableTemplate\r
+{\r
+ public class TestPage\r
+ {\r
+ private static TestPage instance;\r
+ private static Object lockObject = new object();\r
+\r
+ private NavigationPage _navigationPage;\r
+ private ContentPage _tcContentPage;\r
+ private Page _tcUIPage;\r
+ private Label _summaryLabel1, _summaryLabel2, _tcResultText, _descriptionTitle;\r
+ private ListView _tcDescriptions;\r
+ private Button _runBtn, _passBtn, _failBtn, _blockBtn;\r
+ private Button _mainBtn, _prevBtn, _nextBtn;\r
+ private StackLayout _mainLayout, _tcUILayout;\r
+\r
+ private int _tcIndex = 0;\r
+ private List<string> _tcIDList;\r
+ private List<ItemData> _listItem;\r
+ private List<TestcaseInfo> _tcInfoList;\r
+ private List<TestcaseDescription> _currentTCInfo;\r
+ private TRunner _tunitRunner;\r
+ private TSettings _tsettings;\r
+ private NavigationButton _pressButton = NavigationButton.NA;\r
+ private ToastMessage _toastMessage;\r
+\r
+ private const string STEP_ATTRIBUTE_NAME = "NUnit.Framework.StepAttribute";\r
+ private const string PRECONDITION_ATTRIBUTE_NAME = "NUnit.Framework.PreconditionAttribute";\r
+ private const string POSTCONDITION_ATTRIBUTE_NAME = "NUnit.Framework.PostconditionAttribute";\r
+\r
+ public event EventHandler<string> TestcaseDone;\r
+\r
+ private void OnTestcaseDone(string e)\r
+ {\r
+ EventHandler<string> handler = TestcaseDone;\r
+ if (handler != null)\r
+ {\r
+ handler(this, e);\r
+ }\r
+ }\r
+\r
+ public NavigationPage getNavigationPage()\r
+ {\r
+ return _navigationPage;\r
+ }\r
+\r
+ public static TestPage GetInstance()\r
+ {\r
+\r
+ lock (lockObject)\r
+ {\r
+ if (instance == null)\r
+ {\r
+ instance = new TestPage();\r
+ }\r
+ }\r
+ return instance;\r
+ }\r
+\r
+ private TestPage()\r
+ {\r
+ }\r
+\r
+ public void Initialize(TRunner tunitRunner, List<string> testcaseIDList, List<ItemData> listItem)\r
+ {\r
+ _toastMessage = new ToastMessage();\r
+ RunType.Value = RunType.MANUAL;\r
+ _tunitRunner = tunitRunner;\r
+ _tunitRunner.SingleTestDone += OnSingleTestDone;\r
+ _tcInfoList = new List<TestcaseInfo>();\r
+ _tcIDList = testcaseIDList;\r
+ _tsettings = TSettings.GetInstance();\r
+ _tsettings.IsManual = true;\r
+ _listItem = listItem;\r
+ MakeTCInfoList();\r
+\r
+ _summaryLabel1 = new Label()\r
+ {\r
+ Text = "",\r
+ HeightRequest = 25,\r
+ HorizontalOptions = LayoutOptions.Center,\r
+ VerticalOptions = LayoutOptions.Center,\r
+ TextColor = Color.White,\r
+ FontSize = 5,\r
+ };\r
+ _summaryLabel2 = new Label()\r
+ {\r
+ Text = "",\r
+ HeightRequest = 25,\r
+ HorizontalOptions = LayoutOptions.Center,\r
+ VerticalOptions = LayoutOptions.Center,\r
+ TextColor = Color.White,\r
+ FontSize = 5,\r
+ };\r
+ SetResultNumber(0, 0, 0);\r
+ MakeTestPage();\r
+ }\r
+\r
+ private void OnSingleTestDone(object sender, SingleTestDoneEventArgs e)\r
+ {\r
+ // check old result\r
+ if (_listItem[_tcIndex].Result.Contains(StrResult.FAIL))\r
+ {\r
+ ResultNumber.Fail = ResultNumber.Fail - 1;\r
+ }\r
+ else if (_listItem[_tcIndex].Result.Contains(StrResult.PASS))\r
+ {\r
+ ResultNumber.Pass = ResultNumber.Pass - 1;\r
+ }\r
+ else if (_listItem[_tcIndex].Result.Contains(StrResult.BLOCK))\r
+ ResultNumber.Block = ResultNumber.Block - 1;\r
+\r
+ // Update new result\r
+ _listItem[_tcIndex].Result = e.Result;\r
+ if (e.Result.Contains(StrResult.PASS))\r
+ {\r
+ ResultNumber.Pass += 1;\r
+ }\r
+ else if (e.Result.Contains(StrResult.FAIL))\r
+ {\r
+ ResultNumber.Fail += 1;\r
+ }\r
+ else if (e.Result.Contains(StrResult.BLOCK))\r
+ {\r
+ ResultNumber.Block += 1;\r
+ }\r
+\r
+ UpdateLayout();\r
+ }\r
+\r
+ private void UpdateLayout()\r
+ {\r
+ SetResultNumber(ResultNumber.Pass, ResultNumber.Fail, ResultNumber.Block);\r
+ _tcResultText.Text = _listItem[_tcIndex].Result;\r
+ SetColor(_tcResultText.Text);\r
+ if (_tcUILayout != null)\r
+ {\r
+ _tcUILayout.Children.Clear();\r
+ }\r
+ if (_pressButton == NavigationButton.Next)\r
+ {\r
+ Next();\r
+ }\r
+ else if (_pressButton == NavigationButton.Previous)\r
+ {\r
+ Previous();\r
+ }\r
+ else if (_pressButton == NavigationButton.Home)\r
+ {\r
+ _navigationPage.PopAsync();\r
+ }\r
+ OnTestcaseDone(null);\r
+ _passBtn.IsEnabled = false;\r
+ _failBtn.IsEnabled = false;\r
+ _blockBtn.IsEnabled = false;\r
+ _runBtn.IsEnabled = true;\r
+ _mainBtn.IsEnabled = true;\r
+ _prevBtn.IsEnabled = true;\r
+ _nextBtn.IsEnabled = true;\r
+ }\r
+\r
+ private void SetResultNumber(int pass, int fail, int block)\r
+ {\r
+ ResultNumber.NotRun = ResultNumber.Total - pass - fail - block;\r
+ _summaryLabel1.Text = "T : " + ResultNumber.Total + ", P : " + pass;\r
+ _summaryLabel2.Text = "F : " + fail + ", B : " + block + ", NR : " + ResultNumber.NotRun;\r
+ }\r
+\r
+ private void MakeTestPage()\r
+ {\r
+ _mainLayout = new StackLayout()\r
+ {\r
+ Orientation = StackOrientation.Vertical,\r
+ IsVisible = true,\r
+ HorizontalOptions = LayoutOptions.CenterAndExpand,\r
+ VerticalOptions = LayoutOptions.CenterAndExpand,\r
+ Spacing = 5,\r
+ Padding = new Thickness(10),\r
+ };\r
+ _descriptionTitle = new Label()\r
+ {\r
+ Text = "DESCRIPTION:",\r
+ HorizontalOptions = LayoutOptions.FillAndExpand,\r
+ VerticalOptions = LayoutOptions.Start,\r
+ HeightRequest = 23,\r
+ Margin = new Thickness(40, 0, 0, 0),\r
+ FontSize = 5,\r
+ TextColor = Color.White,\r
+ };\r
+\r
+ StackLayout functionLayout = new StackLayout()\r
+ {\r
+ Orientation = StackOrientation.Horizontal,\r
+ IsVisible = true,\r
+ HeightRequest = 30,\r
+ HorizontalOptions = LayoutOptions.CenterAndExpand,\r
+ VerticalOptions = LayoutOptions.Start,\r
+ Spacing = 2,\r
+ Margin = new Thickness(0, 0, 0, 15)\r
+ };\r
+\r
+ _mainBtn = new Button()\r
+ {\r
+ HorizontalOptions = LayoutOptions.Start,\r
+ Text = "H",\r
+ HeightRequest = 30,\r
+ WidthRequest = 55,\r
+ FontSize = 5\r
+ };\r
+\r
+ _mainBtn.Clicked += (sender, e) =>\r
+ {\r
+ _pressButton = NavigationButton.Home;\r
+ if (!ManualTest.IsConfirmed())\r
+ {\r
+ _tsettings.TCResult = StrResult.NOTRUN;\r
+ ManualTest.Confirm();\r
+ }\r
+ else\r
+ {\r
+ _navigationPage.PopAsync();\r
+ }\r
+ };\r
+\r
+ _prevBtn = new Button()\r
+ {\r
+ HorizontalOptions = LayoutOptions.Start,\r
+ Text = "<<",\r
+ HeightRequest = 30,\r
+ WidthRequest = 55,\r
+ FontSize = 4\r
+ };\r
+\r
+ _prevBtn.Clicked += (sender, e) =>\r
+ {\r
+ PreviousTestcase();\r
+ };\r
+\r
+ _nextBtn = new Button()\r
+ {\r
+ Text = ">>",\r
+ HorizontalOptions = LayoutOptions.Start,\r
+ HeightRequest = 30,\r
+ WidthRequest = 55,\r
+ FontSize = 4\r
+ };\r
+\r
+ _nextBtn.Clicked += (sender, e) =>\r
+ {\r
+ NextTestcase();\r
+ };\r
+\r
+ _tcResultText = new Label()\r
+ {\r
+ HorizontalOptions = LayoutOptions.Start,\r
+ VerticalOptions = LayoutOptions.FillAndExpand,\r
+ HorizontalTextAlignment = TextAlignment.Center,\r
+ VerticalTextAlignment = TextAlignment.Center,\r
+ HeightRequest = 30,\r
+ FontSize = 3\r
+ };\r
+ functionLayout.Children.Add(_mainBtn);\r
+ functionLayout.Children.Add(_tcResultText);\r
+ functionLayout.Children.Add(_prevBtn);\r
+ functionLayout.Children.Add(_nextBtn);\r
+ // Show description\r
+ ShowDescription();\r
+\r
+ var navigationLayout = new StackLayout()\r
+ {\r
+ Orientation = StackOrientation.Horizontal,\r
+ IsVisible = true,\r
+ HeightRequest = 30,\r
+ HorizontalOptions = LayoutOptions.CenterAndExpand,\r
+ VerticalOptions = LayoutOptions.Start,\r
+ Spacing = 5,\r
+ };\r
+\r
+ _passBtn = new Button()\r
+ {\r
+ HorizontalOptions = LayoutOptions.Start,\r
+ Text = "P",\r
+ HeightRequest = 30,\r
+ IsEnabled = false,\r
+ FontSize = 5,\r
+ WidthRequest = 60\r
+ };\r
+\r
+ _passBtn.Clicked += (sender, e) =>\r
+ {\r
+ if (!ManualTest.IsConfirmed())\r
+ {\r
+ _tsettings.TCResult = StrResult.PASS;\r
+ ManualTest.Confirm();\r
+ }\r
+ };\r
+\r
+ _failBtn = new Button()\r
+ {\r
+ HorizontalOptions = LayoutOptions.Start,\r
+ Text = "F",\r
+ HeightRequest = 30,\r
+ IsEnabled = false,\r
+ FontSize = 5,\r
+ WidthRequest = 60\r
+ };\r
+\r
+ _failBtn.Clicked += (sender, e) =>\r
+ {\r
+ if (!ManualTest.IsConfirmed())\r
+ {\r
+ _tsettings.TCResult = StrResult.FAIL;\r
+ ManualTest.Confirm();\r
+ }\r
+ };\r
+\r
+ _blockBtn = new Button()\r
+ {\r
+ HorizontalOptions = LayoutOptions.Start,\r
+ Text = "B",\r
+ HeightRequest = 30,\r
+ IsEnabled = false,\r
+ FontSize = 5,\r
+ WidthRequest = 60\r
+ };\r
+\r
+ _blockBtn.Clicked += (sender, e) =>\r
+ {\r
+ if (!ManualTest.IsConfirmed())\r
+ {\r
+ _tsettings.TCResult = StrResult.BLOCK;\r
+ ManualTest.Confirm();\r
+ }\r
+ };\r
+\r
+ _runBtn = new Button()\r
+ {\r
+ HorizontalOptions = LayoutOptions.Start,\r
+ Text = "R",\r
+ HeightRequest = 30,\r
+ FontSize = 5,\r
+ WidthRequest = 60\r
+ };\r
+\r
+ _runBtn.Clicked += (sender, e) =>\r
+ {\r
+ LockUIButton();\r
+ _pressButton = NavigationButton.NA;\r
+ _tsettings.Testcase_ID = _tcIDList[_tcIndex];\r
+ _tsettings.TCResult = "";\r
+ _tunitRunner.Execute();\r
+ };\r
+\r
+ navigationLayout.Children.Add(_passBtn);\r
+ navigationLayout.Children.Add(_failBtn);\r
+ navigationLayout.Children.Add(_blockBtn);\r
+ navigationLayout.Children.Add(_runBtn);\r
+\r
+ _tcUILayout = new StackLayout()\r
+ {\r
+ Orientation = StackOrientation.Vertical,\r
+ HorizontalOptions = LayoutOptions.FillAndExpand,\r
+ VerticalOptions = LayoutOptions.Start,\r
+ HeightRequest = 40,\r
+ WidthRequest = 280,\r
+ Margin = new Thickness(10, 0, 10, 0)\r
+ };\r
+\r
+ _mainLayout.Children.Add(_summaryLabel1);\r
+ _mainLayout.Children.Add(_summaryLabel2);\r
+ _mainLayout.Children.Add(_descriptionTitle);\r
+ _mainLayout.Children.Add(_tcDescriptions);\r
+ _mainLayout.Children.Add(_tcUILayout);\r
+ _mainLayout.Children.Add(navigationLayout);\r
+ _mainLayout.Children.Add(functionLayout);\r
+ _tcContentPage = new ContentPage()\r
+ {\r
+ Content = _mainLayout\r
+ };\r
+ NavigationPage.SetHasNavigationBar(_tcContentPage, false);\r
+ }\r
+\r
+ public void LockUIButton()\r
+ {\r
+ _runBtn.IsEnabled = false;\r
+ _passBtn.IsEnabled = false;\r
+ _failBtn.IsEnabled = false;\r
+ _blockBtn.IsEnabled = false;\r
+ _mainBtn.IsEnabled = false;\r
+ _prevBtn.IsEnabled = false;\r
+ _nextBtn.IsEnabled = false;\r
+\r
+ }\r
+\r
+ public void UnlockUIButton()\r
+ {\r
+ _passBtn.IsEnabled = true;\r
+ _failBtn.IsEnabled = true;\r
+ _blockBtn.IsEnabled = true;\r
+ _mainBtn.IsEnabled = true;\r
+ _prevBtn.IsEnabled = true;\r
+ _nextBtn.IsEnabled = true;\r
+ }\r
+\r
+ public void Show(NavigationPage navigationPage, int testcaseIndex)\r
+ {\r
_navigationPage = navigationPage;\r
_tcIndex = testcaseIndex - 1;\r
- _descriptionTitle.Text = "DESCRIPTION : #" + testcaseIndex;
- _tcResultText.Text = _listItem[_tcIndex].Result;
- SetColor(_tcResultText.Text);
- UpdateDescriptions();
- navigationPage.PushAsync(_tcContentPage);
- _passBtn.IsEnabled = false;
- _failBtn.IsEnabled = false;
- _blockBtn.IsEnabled = false;
- }
-
- private void NextTestcase()
- {
- _pressButton = NavigationButton.Next;
- if (!ManualTest.IsConfirmed())
- {
- _tsettings.TCResult = StrResult.NOTRUN;
- ManualTest.Confirm();
- }
- else
- {
- Next();
- }
- }
-
- private void Next()
- {
- if (_tcIndex < _tcIDList.Count - 1)
- {
- _tcIndex = _tcIndex + 1;
- _descriptionTitle.Text = "DESCRIPTION : #" + (_tcIndex + 1);
- _tcResultText.Text = _listItem[_tcIndex].Result;
- SetColor(_tcResultText.Text);
- UpdateDescriptions();
- }
- else if (_tcIndex == _tcIDList.Count - 1)
- {
- _toastMessage.Message = "This is last testcase";
- _toastMessage.Post();
- }
- }
-
- private void PreviousTestcase()
- {
- _pressButton = NavigationButton.Previous;
- if (!ManualTest.IsConfirmed())
- {
- _tsettings.TCResult = StrResult.NOTRUN;
- ManualTest.Confirm();
- }
- else
- {
- Previous();
- }
- }
-
- private void Previous()
- {
- if (_tcIndex > 0)
- {
- _tcIndex = _tcIndex - 1;
- _descriptionTitle.Text = "DESCRIPTION : #" + (_tcIndex + 1);
- _tcResultText.Text = _listItem[_tcIndex].Result;
- SetColor(_tcResultText.Text);
- UpdateDescriptions();
- }
- else if (_tcIndex == 0)
- {
- _toastMessage.Message = "This is first testcase";
- _toastMessage.Post();
- }
- }
-
- private void SetColor(string result)
- {
- if (result.Equals(StrResult.PASS))
- {
- _tcResultText.TextColor = Color.Green;
- }
- else if (result.Equals(StrResult.FAIL))
- {
- _tcResultText.TextColor = Color.Red;
- }
- else if (result.Equals(StrResult.BLOCK))
- {
- _tcResultText.TextColor = Color.Orange;
- }
- else
- {
- _tcResultText.TextColor = Color.White;
- }
- }
-
- private int FindMaxLineDescription()
- {
- int maxLine = 0;
- for (int i = 0; i < _tcInfoList.Count; i++)
- {
- int len = _tcInfoList[i].Steps.Count + _tcInfoList[i].Preconditions.Count + _tcInfoList[i].Postconditions.Count;
- maxLine = maxLine < len ? len : maxLine;
- }
- return maxLine;
- }
-
- private void ShowDescription()
- {
- int lenght = FindMaxLineDescription() + 3;
- var template = new DataTemplate(() =>
- {
- var grid = new Grid();
-
- var descriptionLabel = new Label
- {
- HorizontalOptions = LayoutOptions.FillAndExpand,
- LineBreakMode = LineBreakMode.CharacterWrap,
- FontSize = 6
- };
-
- descriptionLabel.SetBinding(Label.TextProperty, new Binding("Description"));
-
- grid.Children.Add(descriptionLabel);
-
- return new ViewCell
- {
- View = grid,
- };
- });
-
- _tcDescriptions = new ListView()
- {
- ItemTemplate = template,
- HorizontalOptions = LayoutOptions.FillAndExpand,
- RowHeight = 110,
- Margin = new Thickness(10, 0, 10, 0),
- };
- _currentTCInfo = new List<TestcaseDescription>();
- for (int i = 0; i < lenght; i++)
- {
- _currentTCInfo.Add(new TestcaseDescription(""));
- }
- UpdateDescriptions();
- _tcDescriptions.ItemsSource = _currentTCInfo;
- }
-
- private void UpdateDescriptions()
- {
- _prevBtn.IsEnabled = false;
- _nextBtn.IsEnabled = false;
- int lenght = FindMaxLineDescription() + 3;
- for (int i = 0; i < lenght; i++)
- {
- _currentTCInfo[i].Description = "";
- }
- int index = 0;
- _currentTCInfo[index].Description = "TC : " + _tcInfoList[_tcIndex].TestcaseName;
- foreach (string precondition in _tcInfoList[_tcIndex].Preconditions.ToArray())
- {
- index++;
- _currentTCInfo[index].Description = precondition;
- }
- foreach (string step in _tcInfoList[_tcIndex].Steps.ToArray())
- {
- index++;
- _currentTCInfo[index].Description = step;
- }
- foreach (string postcondition in _tcInfoList[_tcIndex].Postconditions.ToArray())
- {
- index++;
- _currentTCInfo[index].Description = postcondition;
- }
- _prevBtn.IsEnabled = true;
- _nextBtn.IsEnabled = true;
- }
-
- private void MakeTCInfoList()
- {
- foreach (var testcaseItem in _listItem)
- {
- foreach (KeyValuePair<string, ITest> pair in _tunitRunner.GetTestList())
- {
- if (testcaseItem.TCName.Equals(pair.Key))
- {
- IEnumerator<CustomAttributeData> customAttributes = pair.Value.Method.MethodInfo.CustomAttributes.GetEnumerator();
- List<string> _preconditonsStr = new List<string>(); _preconditonsStr.Add("Preconditions:");
- List<string> _stepsStr = new List<string>(); _stepsStr.Add("Steps:");
+ _descriptionTitle.Text = "DESCRIPTION : #" + testcaseIndex;\r
+ _tcResultText.Text = _listItem[_tcIndex].Result;\r
+ SetColor(_tcResultText.Text);\r
+ UpdateDescriptions();\r
+ navigationPage.PushAsync(_tcContentPage);\r
+ _passBtn.IsEnabled = false;\r
+ _failBtn.IsEnabled = false;\r
+ _blockBtn.IsEnabled = false;\r
+ }\r
+\r
+ private void NextTestcase()\r
+ {\r
+ _pressButton = NavigationButton.Next;\r
+ if (!ManualTest.IsConfirmed())\r
+ {\r
+ _tsettings.TCResult = StrResult.NOTRUN;\r
+ ManualTest.Confirm();\r
+ }\r
+ else\r
+ {\r
+ Next();\r
+ }\r
+ }\r
+\r
+ private void Next()\r
+ {\r
+ if (_tcIndex < _tcIDList.Count - 1)\r
+ {\r
+ _tcIndex = _tcIndex + 1;\r
+ _descriptionTitle.Text = "DESCRIPTION : #" + (_tcIndex + 1);\r
+ _tcResultText.Text = _listItem[_tcIndex].Result;\r
+ SetColor(_tcResultText.Text);\r
+ UpdateDescriptions();\r
+ }\r
+ else if (_tcIndex == _tcIDList.Count - 1)\r
+ {\r
+ _toastMessage.Message = "This is last testcase";\r
+ _toastMessage.Post();\r
+ }\r
+ }\r
+\r
+ private void PreviousTestcase()\r
+ {\r
+ _pressButton = NavigationButton.Previous;\r
+ if (!ManualTest.IsConfirmed())\r
+ {\r
+ _tsettings.TCResult = StrResult.NOTRUN;\r
+ ManualTest.Confirm();\r
+ }\r
+ else\r
+ {\r
+ Previous();\r
+ }\r
+ }\r
+\r
+ private void Previous()\r
+ {\r
+ if (_tcIndex > 0)\r
+ {\r
+ _tcIndex = _tcIndex - 1;\r
+ _descriptionTitle.Text = "DESCRIPTION : #" + (_tcIndex + 1);\r
+ _tcResultText.Text = _listItem[_tcIndex].Result;\r
+ SetColor(_tcResultText.Text);\r
+ UpdateDescriptions();\r
+ }\r
+ else if (_tcIndex == 0)\r
+ {\r
+ _toastMessage.Message = "This is first testcase";\r
+ _toastMessage.Post();\r
+ }\r
+ }\r
+\r
+ private void SetColor(string result)\r
+ {\r
+ if (result.Equals(StrResult.PASS))\r
+ {\r
+ _tcResultText.TextColor = Color.Green;\r
+ }\r
+ else if (result.Equals(StrResult.FAIL))\r
+ {\r
+ _tcResultText.TextColor = Color.Red;\r
+ }\r
+ else if (result.Equals(StrResult.BLOCK))\r
+ {\r
+ _tcResultText.TextColor = Color.Orange;\r
+ }\r
+ else\r
+ {\r
+ _tcResultText.TextColor = Color.White;\r
+ }\r
+ }\r
+\r
+ private int FindMaxLineDescription()\r
+ {\r
+ int maxLine = 0;\r
+ for (int i = 0; i < _tcInfoList.Count; i++)\r
+ {\r
+ int len = _tcInfoList[i].Steps.Count + _tcInfoList[i].Preconditions.Count + _tcInfoList[i].Postconditions.Count;\r
+ maxLine = maxLine < len ? len : maxLine;\r
+ }\r
+ return maxLine;\r
+ }\r
+\r
+ private void ShowDescription()\r
+ {\r
+ int lenght = FindMaxLineDescription() + 3;\r
+ var template = new DataTemplate(() =>\r
+ {\r
+ var grid = new Grid();\r
+\r
+ var descriptionLabel = new Label\r
+ {\r
+ HorizontalOptions = LayoutOptions.FillAndExpand,\r
+ LineBreakMode = LineBreakMode.CharacterWrap,\r
+ FontSize = 6\r
+ };\r
+\r
+ descriptionLabel.SetBinding(Label.TextProperty, new Binding("Description"));\r
+\r
+ grid.Children.Add(descriptionLabel);\r
+\r
+ return new ViewCell\r
+ {\r
+ View = grid,\r
+ };\r
+ });\r
+\r
+ _tcDescriptions = new ListView()\r
+ {\r
+ ItemTemplate = template,\r
+ HorizontalOptions = LayoutOptions.FillAndExpand,\r
+ RowHeight = 110,\r
+ Margin = new Thickness(10, 0, 10, 0),\r
+ };\r
+ _currentTCInfo = new List<TestcaseDescription>();\r
+ for (int i = 0; i < lenght; i++)\r
+ {\r
+ _currentTCInfo.Add(new TestcaseDescription(""));\r
+ }\r
+ UpdateDescriptions();\r
+ _tcDescriptions.ItemsSource = _currentTCInfo;\r
+ }\r
+\r
+ private void UpdateDescriptions()\r
+ {\r
+ _prevBtn.IsEnabled = false;\r
+ _nextBtn.IsEnabled = false;\r
+ int lenght = FindMaxLineDescription() + 3;\r
+ for (int i = 0; i < lenght; i++)\r
+ {\r
+ _currentTCInfo[i].Description = "";\r
+ }\r
+ int index = 0;\r
+ if (_tcInfoList.Count == 0)\r
+ {\r
+ _toastMessage.Message = "Some testing class wrong, plz recheck";\r
+ _toastMessage.Post();\r
+ return;\r
+ }\r
+\r
+ _currentTCInfo[index].Description = "TC : " + _tcInfoList[_tcIndex].TestcaseName;\r
+ foreach (string precondition in _tcInfoList[_tcIndex].Preconditions.ToArray())\r
+ {\r
+ index++;\r
+ _currentTCInfo[index].Description = precondition;\r
+ }\r
+ foreach (string step in _tcInfoList[_tcIndex].Steps.ToArray())\r
+ {\r
+ index++;\r
+ _currentTCInfo[index].Description = step;\r
+ }\r
+ foreach (string postcondition in _tcInfoList[_tcIndex].Postconditions.ToArray())\r
+ {\r
+ index++;\r
+ _currentTCInfo[index].Description = postcondition;\r
+ }\r
+ _prevBtn.IsEnabled = true;\r
+ _nextBtn.IsEnabled = true;\r
+ }\r
+\r
+ private void MakeTCInfoList()\r
+ {\r
+ foreach (var testcaseItem in _listItem)\r
+ {\r
+ foreach (KeyValuePair<string, ITest> pair in _tunitRunner.GetTestList())\r
+ {\r
+ if (testcaseItem.TCName.Equals(pair.Key))\r
+ {\r
+ IEnumerator<CustomAttributeData> customAttributes = pair.Value.Method.MethodInfo.CustomAttributes.GetEnumerator();\r
+ List<string> _preconditonsStr = new List<string>(); _preconditonsStr.Add("Preconditions:");\r
+ List<string> _stepsStr = new List<string>(); _stepsStr.Add("Steps:");\r
List<string> _postconditionsStr = new List<string>(); _postconditionsStr.Add("Postconditions:\n");\r
\r
while (customAttributes.MoveNext())\r
{\r
_postconditionsStr.Add(customAttributes.Current.ConstructorArguments[0].Value + "." + customAttributes.Current.ConstructorArguments[1].Value);\r
}\r
- }
-
- _tcInfoList.Add(new TestcaseInfo
- {
- TestcaseName = pair.Key,
- Preconditions = _preconditonsStr,
- Steps = _stepsStr,
- Postconditions = _postconditionsStr,
- });
- break;
- }
- }
- }
- }
-
- public void ExecuteTC(Layout layout)
- {
- _tcUILayout.Children.Add(layout);
- }
-
- public void ExecuteTC(Page page)
- {
- _tcUIPage = page;
- _navigationPage.PushAsync(page);
- }
- }
-}
+ }\r
+\r
+ _tcInfoList.Add(new TestcaseInfo\r
+ {\r
+ TestcaseName = pair.Key,\r
+ Preconditions = _preconditonsStr,\r
+ Steps = _stepsStr,\r
+ Postconditions = _postconditionsStr,\r
+ });\r
+ break;\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ public void ExecuteTC(Layout layout)\r
+ {\r
+ _tcUILayout.Children.Add(layout);\r
+ }\r
+\r
+ public void ExecuteTC(Page page)\r
+ {\r
+ _tcUIPage = page;\r
+ _navigationPage.PushAsync(page);\r
+ }\r
+ }\r
+}\r