mattercontrol/Tests/MatterControl.Tests/MatterControl/AutomationTests/PrintQueueTests.cs
2015-10-29 12:02:54 -07:00

586 lines
21 KiB
C#

/*
Copyright (c) 2014, Lars Brubaker
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using MatterHackers.Agg;
using MatterHackers.Agg.Image;
using MatterHackers.Agg.UI;
using NUnit.Framework;
using System;
using System.Threading.Tasks;
using MatterHackers.GuiAutomation;
using MatterHackers.Agg.PlatformAbstract;
using System.IO;
using MatterHackers.MatterControl.CreatorPlugins;
using MatterHackers.Agg.UI.Tests;
using MatterHackers.MatterControl.PrintQueue;
using MatterHackers.MatterControl.DataStorage;
using System.Diagnostics;
namespace MatterHackers.MatterControl.UI
{
[TestFixture, Category("MatterControl.UI"), RunInApplicationDomain]
public class BuyButtonTests
{
[Test, RequiresSTA, RunInApplicationDomain, Ignore("Not Finished")]
public void ClickOnBuyButton()
{
// Run a copy of MatterControl
Action<AutomationTesterHarness> testToRun = (AutomationTesterHarness resultsHarness) =>
{
AutomationRunner testRunner = new AutomationRunner(MatterControlUtilities.DefaultTestImages);
{
//Make sure image does not exist before we click the buy button
testRunner.MatchLimit = 500000;
bool imageExists = testRunner.ImageExists("MatterHackersStoreImage.png");
resultsHarness.AddTestResult(imageExists == false, "Web page is not open");
//Click Buy button and test that the MatterHackers store web page is open
testRunner.ClickByName("Buy Materials Button", 5);
bool imageExists2 = testRunner.ImageExists("MatterHackersStoreImage.png", 10);
resultsHarness.AddTestResult(imageExists2 == true, "Web page is open");
MatterControlUtilities.CloseMatterControl(testRunner);
}
};
AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun, "MC_Three_Queue_Items");
Assert.IsTrue(testHarness.AllTestsPassed);
Assert.IsTrue(testHarness.TestCount == 2); // make sure we ran all our tests
}
}
[TestFixture, Category("MatterControl.UI"), RunInApplicationDomain]
public class CreateButtonTest
{
[Test, RequiresSTA, RunInApplicationDomain]
//Test Works
public void ClickOnCreateButton()
{
// Run a copy of MatterControl
Action<AutomationTesterHarness> testToRun = (AutomationTesterHarness resultsHarness) =>
{
AutomationRunner testRunner = new AutomationRunner(MatterControlUtilities.DefaultTestImages);
{
//Make sure that plugin window does not exist
bool pluginWindowExists1 = testRunner.WaitForName("Plugin Chooser Window", 0);
resultsHarness.AddTestResult(pluginWindowExists1 == false, "Plugin window does not exist");
testRunner.ClickByName("Design Tool Button", 5);
//Test that the plugin window does exist after the create button is clicked
SystemWindow containingWindow;
GuiWidget pluginWindowExists = testRunner.GetWidgetByName("Plugin Chooser Window", out containingWindow, secondsToWait: 3);
resultsHarness.AddTestResult(pluginWindowExists != null, "Plugin Chooser Window");
pluginWindowExists.CloseOnIdle();
testRunner.Wait(.5);
MatterControlUtilities.CloseMatterControl(testRunner);
}
};
AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun);
Assert.IsTrue(testHarness.AllTestsPassed);
Assert.IsTrue(testHarness.TestCount == 2); // make sure we ran all our tests
}
}
[TestFixture, Category("MatterControl.UI"), RunInApplicationDomain]//, Ignore("Not Finished")]
public class ExportButtonTest
{
[Test, RequiresSTA, RunInApplicationDomain]
//Test Works
public void ClickOnExportButton()
{
// Run a copy of MatterControl
Action<AutomationTesterHarness> testToRun = (AutomationTesterHarness resultsHarness) =>
{
AutomationRunner testRunner = new AutomationRunner(MatterControlUtilities.DefaultTestImages);
{
//Make sure that the export window does not exist
bool exportWindowExists1 = testRunner.WaitForName( "Export Window Queue", 0);
resultsHarness.AddTestResult(exportWindowExists1 == false, "Export window does not exist");
testRunner.ClickByName("Export Queue Button", 5);
SystemWindow containingWindow;
GuiWidget exportWindow = testRunner.GetWidgetByName("Export Window Queue", out containingWindow, 5);
resultsHarness.AddTestResult(exportWindow != null, "Export window does exist");
if (exportWindow != null)
{
exportWindow.CloseOnIdle();
testRunner.Wait(.5);
}
MatterControlUtilities.CloseMatterControl(testRunner);
}
};
AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun, null, null, "Three_Queue_Items");
Assert.IsTrue(testHarness.AllTestsPassed);
Assert.IsTrue(testHarness.TestCount == 2); // make sure we ran all our tests
}
}
[TestFixture, Category("MatterControl.UI"), RunInApplicationDomain, Ignore("Not Finished")]
public class ExportButtonDisabledNoQueueItems
{
[Test, RequiresSTA, RunInApplicationDomain]
public void ExportButtonIsDisabledWithNoItemsInQueue()
{
// Run a copy of MatterControl
Action<AutomationTesterHarness> testToRun = (AutomationTesterHarness resultsHarness) =>
{
AutomationRunner testRunner = new AutomationRunner(MatterControlUtilities.DefaultTestImages);
{
//bool exportButtonExists = testRunner.NameExists("Export Queue Button");
bool exportButtonExists = testRunner.WaitForName("Export Queue Button", 10);
testRunner.Wait(5);
resultsHarness.AddTestResult(exportButtonExists == false, "Export button is disabled");
MatterControlUtilities.CloseMatterControl(testRunner);
}
};
AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun);
Assert.IsTrue(testHarness.AllTestsPassed);
Assert.IsTrue(testHarness.TestCount == 1); // make sure we ran all our tests
}
}
[TestFixture, Category("MatterControl.UI"), RunInApplicationDomain]
public class QueueItemThumnailWidget
{
[Test, RequiresSTA, RunInApplicationDomain]
public void QueueThumbnailWidgetOpensPartPreview()
{
// Run a copy of MatterControl
Action<AutomationTesterHarness> testToRun = (AutomationTesterHarness resultsHarness) =>
{
AutomationRunner testRunner = new AutomationRunner(MatterControlUtilities.DefaultTestImages);
{
bool partPreviewWindowExists1 = testRunner.WaitForName("Part Preview Window Thumbnail", 0);
resultsHarness.AddTestResult(partPreviewWindowExists1 == false, "Part Preview Window Does Not Exist");
testRunner.ClickByName("Queue Item Thumbnail");
SystemWindow containingWindow;
GuiWidget partPreviewWindowExists = testRunner.GetWidgetByName("Part Preview Window Thumbnail", out containingWindow, 3);
resultsHarness.AddTestResult(partPreviewWindowExists != null, "Part Preview Window Exists");
partPreviewWindowExists.CloseOnIdle();
testRunner.Wait(.5);
MatterControlUtilities.CloseMatterControl(testRunner);
}
};
AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun, null, null, "Three_Queue_Items");
Assert.IsTrue(testHarness.AllTestsPassed);
Assert.IsTrue(testHarness.TestCount == 2); // make sure we ran all our tests
}
}
[TestFixture, Category("MatterControl.UI"), RunInApplicationDomain]
public class ClickCopyButtonMakesACopyOfPrintItemInQueue
{
[Test, RequiresSTA, RunInApplicationDomain]
public void CopyButtonMakesACopyOfPartInTheQueue()
{
// Run a copy of MatterControl
Action<AutomationTesterHarness> testToRun = (AutomationTesterHarness resultsHarness) =>
{
AutomationRunner testRunner = new AutomationRunner(MatterControlUtilities.DefaultTestImages);
{
/* Tests that when the Queue Copy button is clicked:
* 1. The Queue Tab Count is increased by one
* 2. A Queue Row item is created and added to the queue with the correct name
*/
int queueCountBeforeCopyButtonIsClicked = QueueData.Instance.Count;
bool copyIncreasesQueueDataCount = false;
testRunner.ClickByName("Queue Item " + "Batman", 3);
testRunner.ClickByName("Queue Copy Button", 3);
testRunner.Wait(1);
int currentQueueCount = QueueData.Instance.Count;
if (currentQueueCount == queueCountBeforeCopyButtonIsClicked + 1)
{
copyIncreasesQueueDataCount = true;
}
resultsHarness.AddTestResult(copyIncreasesQueueDataCount == true, "Copy button clicked increases queue tab count by one");
bool batmanQueueItemCopyExists = testRunner.WaitForName("Queue Item " + "Batman" + " - copy", 2);
resultsHarness.AddTestResult(batmanQueueItemCopyExists == true);
MatterControlUtilities.CloseMatterControl(testRunner);
}
};
AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun, null, null, "Three_Queue_Items");
Assert.IsTrue(testHarness.AllTestsPassed);
Assert.IsTrue(testHarness.TestCount == 2); // make sure we ran all our tests
}
}
[TestFixture, Category("MatterControl.UI"), RunInApplicationDomain]
public class AddSingleItemToQueueAddsItem
{
[Test, RequiresSTA, RunInApplicationDomain]
public void AddSingleItemToQueue()
{
// Run a copy of MatterControl
Action<AutomationTesterHarness> testToRun = (AutomationTesterHarness resultsHarness) =>
{
AutomationRunner testRunner = new AutomationRunner(MatterControlUtilities.DefaultTestImages);
{
/*
* Tests that when the QueueData.Instance.AddItem function is called:
* 1. The Queue count is increased by 1
* 2. A QueueRowItem is created and added to the queue
*/
//TODO: Eventually modify test so that we test adding queue items via file
bool queueDataCountEqualsZero = false;
bool addedPartIncreasesQueueDataCount = false;
int currentQueueCount = QueueData.Instance.Count;
string partToBeAdded = Path.Combine("..", "..", "..", "TestData", "TestParts", "Batman.stl");
//Make Sure Queue Count = 0
if(currentQueueCount == 0)
{
queueDataCountEqualsZero = true;
}
resultsHarness.AddTestResult(queueDataCountEqualsZero == true, "Queue count is zero before the test starts");
testRunner.Wait(3);
//Make sure queue item does not exist
bool batmanSTLExists = testRunner.WaitForName("Queue Item " + "Batman", 2);
resultsHarness.AddTestResult(batmanSTLExists == false);
QueueData.Instance.AddItem(new PrintItemWrapper(new PrintItem(Path.GetFileNameWithoutExtension(partToBeAdded), partToBeAdded)));
resultsHarness.AddTestResult(testRunner.WaitForName("Queue Item " + "Batman", 2));
int queueCountAfterAdd = QueueData.Instance.Count;
if(queueCountAfterAdd == currentQueueCount + 1)
{
addedPartIncreasesQueueDataCount = true;
}
resultsHarness.AddTestResult(addedPartIncreasesQueueDataCount == true);
testRunner.Wait(3);
MatterControlUtilities.CloseMatterControl(testRunner);
}
};
AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun);
Assert.IsTrue(testHarness.AllTestsPassed);
Assert.IsTrue(testHarness.TestCount == 4); // make sure we ran all our tests
}
}
[TestFixture, Category("MatterControl.UI"), RunInApplicationDomain]
public class QueueAddAMFToQueue
{
[Test, RequiresSTA, RunInApplicationDomain]
public void AddAMFFile()
{
// Run a copy of MatterControl
Action<AutomationTesterHarness> testToRun = (AutomationTesterHarness resultsHarness) =>
{
AutomationRunner testRunner = new AutomationRunner(MatterControlUtilities.DefaultTestImages);
{
/*
*Tests:
*1. When a zip file is added to the queue all items in the zip file are aadded to queue
*/
bool queueDataCountEqualsZero = false;
string zipFileToAMF = Path.Combine("..", "..", "..", "TestData", "TestParts", "Rook.amf");
int currentQueueCount = QueueData.Instance.Count;
//Make Sure Queue Count = 0
if (currentQueueCount == 0)
{
queueDataCountEqualsZero = true;
}
resultsHarness.AddTestResult(queueDataCountEqualsZero = true);
testRunner.Wait(2);
QueueData.Instance.AddItem(new PrintItemWrapper(new PrintItem(Path.GetFileNameWithoutExtension(zipFileToAMF), zipFileToAMF)));
resultsHarness.AddTestResult(testRunner.WaitForName("Queue Item " + "Rook", 2));
testRunner.Wait(3);
bool queueDataIncreasesByOneAfterAdd = false;
int queueCountAfterAdd = QueueData.Instance.Count;
if(queueCountAfterAdd != 1)
{
queueDataIncreasesByOneAfterAdd = true;
}
resultsHarness.AddTestResult(queueDataIncreasesByOneAfterAdd = true);
MatterControlUtilities.CloseMatterControl(testRunner);
}
};
AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun);
Assert.IsTrue(testHarness.AllTestsPassed);
Assert.IsTrue(testHarness.TestCount == 3); // make sure we ran all our tests
}
}
[TestFixture, Category("MatterControl.UI"), RunInApplicationDomain]
public class RemoveAllMenuItemClicked
{
[Test, RequiresSTA, RunInApplicationDomain]//, Ignore("Not Finished")]
public void RemoveAllMenuItemClickedRemovesAll()
{
// Run a copy of MatterControl
Action<AutomationTesterHarness> testToRun = (AutomationTesterHarness resultsHarness) =>
{
AutomationRunner testRunner = new AutomationRunner(MatterControlUtilities.DefaultTestImages);
{
/*
*Tests that when the Remove All menu item is clicked
*1. Queue Item count is set to zero
*2. All queue row items that were previously in the queue are removed
*/
bool queueEmpty = true;
int queueItemCountBeforeRemoveAllClicked = QueueData.Instance.Count;
if(queueItemCountBeforeRemoveAllClicked != 0)
{
queueEmpty = false;
}
resultsHarness.AddTestResult(queueEmpty = true);
bool batmanPartExists1 = testRunner.WaitForName("Queue Item " + "Batman", 1);
bool foxPartExistst1 = testRunner.WaitForName("Queue Item " + "Fennec_Fox", 1);
bool mouthpiecePartExists1 = testRunner.WaitForName("Queue Item " + "2013-01-25_Mouthpiece_v2", 1);
resultsHarness.AddTestResult(batmanPartExists1 == true);
resultsHarness.AddTestResult(mouthpiecePartExists1 == true);
resultsHarness.AddTestResult(foxPartExistst1 == true);
testRunner.ClickByName("Queue... Menu", 2);
testRunner.ClickByName(" Remove All Menu Item", 2);
testRunner.Wait(2);
int queueItemCountAfterRemoveAll = QueueData.Instance.Count;
if(queueItemCountAfterRemoveAll == 0)
{
queueEmpty = true;
}
resultsHarness.AddTestResult(queueEmpty = true);
bool batmanPartExists2 = testRunner.WaitForName("Queue Item " + "Batman", 1);
bool foxPartExistst2 = testRunner.WaitForName("Queue Item " + "Fennec_Fox", 1);
bool mouthpiecePartExists2 = testRunner.WaitForName("Queue Item " + "2013-01-25_Mouthpiece_v2", 1);
resultsHarness.AddTestResult(batmanPartExists2 == false);
resultsHarness.AddTestResult(mouthpiecePartExists2 == false);
resultsHarness.AddTestResult(foxPartExistst2 == false);
MatterControlUtilities.CloseMatterControl(testRunner);
}
};
AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun, null, null, "Three_Queue_Items");
Assert.IsTrue(testHarness.AllTestsPassed);
Assert.IsTrue(testHarness.TestCount == 8); // make sure we ran all our tests
}
}
[TestFixture, Category("MatterControl.UI"), RunInApplicationDomain]
public class QueueRowItemRemoveViewButtons
{
[Test, RequiresSTA, RunInApplicationDomain]//, Ignore("Not Finished")]
public void ClickQueueRoWItemViewAndRemove()
{
// Run a copy of MatterControl
Action<AutomationTesterHarness> testToRun = (AutomationTesterHarness resultsHarness) =>
{
AutomationRunner testRunner = new AutomationRunner(MatterControlUtilities.DefaultTestImages);
{
/*
*Tests:
*1. When the remove button on a queue item is clicked the queue tab count decreases by one
*2. When the remove button on a queue item is clicked the item is removed
*3. When the View button on a queue item is clicked the part preview window is opened
*/
testRunner.Wait(2);
int currentQueueItemCount = QueueData.Instance.Count;
bool threeItemsInQueue = true;
if(currentQueueItemCount != 3)
{
threeItemsInQueue = false;
}
resultsHarness.AddTestResult(threeItemsInQueue == true);
resultsHarness.AddTestResult(testRunner.WaitForName("Queue Item " + "Batman", 1));
resultsHarness.AddTestResult(testRunner.WaitForName("Queue Item " + "2013-01-25_Mouthpiece_v2", 1));
testRunner.ClickByName("Queue Item " + "Batman", 1);
testRunner.ClickByName("Queue Item " + "Batman" + " Remove");
testRunner.Wait(2);
int queueItemCountAfterRemove = QueueData.Instance.Count;
bool correctItemCountAfterRemove;
if (queueItemCountAfterRemove == 2)
{
correctItemCountAfterRemove = true;
}
else
{
correctItemCountAfterRemove = false;
}
resultsHarness.AddTestResult(correctItemCountAfterRemove == true);
bool batmanQueueItemExists = testRunner.WaitForName("Queue Item " + "Batman", 1);
resultsHarness.AddTestResult(batmanQueueItemExists == false);
bool partPreviewWindowExists1 = testRunner.WaitForName("Queue Item " + "2013-01-25_Mouthpiece_v2" + " Part Preview", 1);
resultsHarness.AddTestResult(partPreviewWindowExists1 == false);
testRunner.ClickByName("Queue Item " + "2013-01-25_Mouthpiece_v2", 1);
testRunner.Wait(2);
testRunner.ClickByName("Queue Item " + "2013-01-25_Mouthpiece_v2" + " View", 1);
bool partPreviewWindowExists2 = testRunner.WaitForName("Queue Item " + "2013-01-25_Mouthpiece_v2" + " Part Preview", 2);
resultsHarness.AddTestResult(partPreviewWindowExists2 == true);
MatterControlUtilities.CloseMatterControl(testRunner);
}
};
AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun, null, null, "Three_Queue_Items");
Assert.IsTrue(testHarness.AllTestsPassed);
Assert.IsTrue(testHarness.TestCount == 7); // make sure we ran all our tests
}
}
[TestFixture, Category("MatterControl.UI"), RunInApplicationDomain, Ignore("Not Finished")]
public class QueueAddButtonAddsZipToQueue
{
[Test, RequiresSTA, RunInApplicationDomain]
public void QueueAddButtonAddsZipFile()
{
Action<AutomationTesterHarness> testToRun = (AutomationTesterHarness resultsHarness) =>
{
AutomationRunner testRunner = new AutomationRunner(MatterControlUtilities.DefaultTestImages);
{
/* Tests that when the Queue Copy button is clicked:
* 1. QueueCount = Zero
* 2. All files in compressed zip are added to queue
*/
testRunner.Wait(5);
testRunner.ClickByName("Queue Add Button");
testRunner.Wait(2);
string test = "%USERPROFILE%";
string test2 = @"\Development\MatterControl\Tests\TestData\TestParts\Batman.zip";
string fullPath = test + test2;
Debug.WriteLine(fullPath);
testRunner.Type(fullPath);
MatterControlUtilities.CloseMatterControl(testRunner);
}
};
AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun);
Assert.IsTrue(testHarness.AllTestsPassed);
Assert.IsTrue(testHarness.TestCount == 0); // make sure we ran all our tests
}
}
}