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

selenium tests, only works in VB I think, but the tests work at least #47

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,6 @@ bin/
obj/

# MonoDevelop preferences
*.userprefs
*.userprefs

.vs/
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"jsonld": "^0.4.5",
"material-ui": "^0.20.0",
"n3": "^0.11.2",
"nuget": "^2.0.1",
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this actually useful or is this just dead code?

Installing NuGet as a separate global dependency shouldn't be a problem at all for people who already installed a C# compiler and an MSBuild-like build system. But maybe you've got a different perspective on that and this line is warranted anyway.

Regardless, please don't put NuGet in the package.json's "dependencies"—if you really do need it, put it in the "devDependencies".

"rdflib": "^0.15",
"react": "^16.2.0",
"react-dom": "^16.2.0",
Expand Down
Binary file added selenium/.vs/selenium/DesignTimeBuild/.dtbcache
Binary file not shown.
Binary file added selenium/.vs/selenium/v15/.suo
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
6 changes: 4 additions & 2 deletions selenium/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public static class Program
/// <summary>
/// A sequence of all test cases to run.
/// </summary>
private static readonly IEnumerable<TestCase> TestCases = SanityChecks.All;
private static readonly IEnumerable<TestCase> TestCases = (ConformanceTests.All);

public static int Main(string[] args)
{
// Acquire a log for printing output.
var rawLog = new RecordingLog(TerminalLog.Acquire());
var rawLog = new RecordingLog();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why'd you change this? This'll secretly eat up all error messages, making it impossible to tell what happened when something went wrong. The tests will still fail by exiting with a nonzero exit code, but that will be obscured now.


// Create a derived log for printing diagnostics.
var log = CreateDiagnosticLog(rawLog);
Expand Down Expand Up @@ -78,6 +78,7 @@ public static int Main(string[] args)
return 0;
}


string testUrl = parsedOptions.GetValue<string>(Options.Url);
bool noUrl = string.IsNullOrWhiteSpace(testUrl);

Expand Down Expand Up @@ -190,6 +191,7 @@ public static int Main(string[] args)
return new SafariDriver(options);
}
}

};

/// <summary>
Expand Down
7 changes: 6 additions & 1 deletion selenium/SeleniumTests.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -31,6 +31,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Windows.Forms" />
<Reference Include="WebDriver">
<HintPath>packages\Selenium.WebDriver.3.11.2\lib\net45\WebDriver.dll</HintPath>
</Reference>
Expand All @@ -48,7 +49,11 @@
<Compile Include="Options.cs" />
<Compile Include="TestCase.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Tests\ConformanceTests.cs" />
<Compile Include="Tests\EditGraphTests.cs" />
<Compile Include="Tests\Help.cs" />
<Compile Include="Tests\SanityChecks.cs" />
<Compile Include="Tests\UploadFileTests.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="packages\Selenium.WebDriver.GeckoDriver.0.20.1\build\Selenium.WebDriver.GeckoDriver.targets" Condition="Exists('packages\Selenium.WebDriver.GeckoDriver.0.20.1\build\Selenium.WebDriver.GeckoDriver.targets')" />
Expand Down
6 changes: 6 additions & 0 deletions selenium/SeleniumTests.csproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<StartArguments>"http://192.168.1.12:5000"</StartArguments>
</PropertyGroup>
</Project>
131 changes: 131 additions & 0 deletions selenium/Tests/ConformanceTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
using System.Collections.Generic;
using OpenQA.Selenium;
using System;
using System.Windows.Forms;
using static System.Diagnostics.Stopwatch;
using static System.Threading.Thread;
using System.Diagnostics;

namespace SeleniumTests.Tests
{
public static class ConformanceTests
{
public static readonly TestCase CheckGreenWhenConforming =
new TestCase(
"Header remains green when there are no conformance errors",
(driver, log) =>
{
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
//Log in
driver.ByPassLogin();
Sleep(100);
//Open data file
driver.OpenDataFile("demo_data_conforming.ttl");
driver.OpenSHACLFile("demo_shacl.ttl");
Sleep(1000);
IReadOnlyCollection<IWebElement> elements = driver.FindElements(By.XPath("//*[@fill='#a1e44d']"), 10);
Assert.IsTrue(elements.Count == 2);
});

public static readonly TestCase CheckRedWhenNotConforming =
new TestCase(
"Header turns red when there are conformance erros",
(driver, log) =>
{
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
//Log in
driver.ByPassLogin();
Sleep(100);
//Open data file
driver.OpenDataFile("demo_data_non-conforming.ttl");
driver.OpenSHACLFile("demo_shacl.ttl");
Sleep(1000);
IReadOnlyCollection<IWebElement> elements = driver.FindElements(By.XPath("//*[@fill='#c10000']"), 10);
Assert.IsTrue(elements.Count == 1);
});

public static readonly TestCase CheckTimeForConformanceError =
new TestCase(
"Check that the time for the header turning red is less than 1000ms",
(driver, log) =>
{
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
//Log in
driver.ByPassLogin();
Sleep(100);
//Open data file
Stopwatch stopwatch = new Stopwatch();
driver.OpenDataFile("demo_data_non-conforming.ttl");
var header = driver.FindElement(By.XPath("//*[@fill='#a1e44d']"), 10);
driver.OpenSHACLFile("demo_shacl.ttl");
stopwatch.Start();
Sleep(200);
IReadOnlyCollection<IWebElement> elements = driver.FindElements(By.XPath("//*[@fill='#c10000']"));
while(elements.Count == 0)
{
elements = driver.FindElements(By.XPath("//*[@fill='#c10000']"));
}
stopwatch.Stop();
long time = stopwatch.ElapsedMilliseconds;
Assert.IsTrue(elements.Count == 1);
Assert.IsTrue(time < 1000);
});


public static readonly TestCase CheckReportConforming =
new TestCase(
"No errors are reported when the data is conforming",
(driver, log) =>
{
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
//Log in
driver.ByPassLogin();
Sleep(100);
//Open data file
driver.OpenDataFile("demo_data_conforming.ttl");
var header = driver.FindElement(By.XPath("//*[@fill='#a1e44d']"), 10);
driver.OpenSHACLFile("demo_shacl.ttl");
Sleep(200);
var conformanceButton = driver.FindElement(By.Id("conformance"));
conformanceButton.Click();
Sleep(200);
var conformanceReport = driver.FindElement(By.XPath("/html/body/div[2]/div/label"),10);
Assert.IsTrue(conformanceReport.Text.Equals("No conformance errors"));


});

public static readonly TestCase CheckReportNotConforming =
new TestCase(
"Errors are reported when data is not conforming",
(driver, log) =>
{
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
//Log in
driver.ByPassLogin();
Sleep(100);
//Open data file
driver.OpenDataFile("demo_data_non-conforming.ttl");
driver.OpenSHACLFile("demo_shacl.ttl");
Sleep(200);
var conformanceButton = driver.FindElement(By.Id("conformance"));
conformanceButton.Click();
Sleep(200);
var conformanceReport = driver.FindElement(By.XPath("//*[contains(text(),'The data value')]"), 10);
Assert.IsTrue(conformanceReport.Text.Contains("The data value: http://example.com/ns#Bob,"));
});



public static readonly ICollection<TestCase> All =
new[]
{
CheckGreenWhenConforming,
CheckRedWhenNotConforming,
CheckTimeForConformanceError,
CheckReportConforming,
CheckReportNotConforming
};

}
}
131 changes: 131 additions & 0 deletions selenium/Tests/EditGraphTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
using System.Collections.Generic;
using OpenQA.Selenium;
using System;
using System.Windows.Forms;
using static System.Diagnostics.Stopwatch;

namespace SeleniumTests.Tests
{
public static class EditGraphTests
{
public static readonly TestCase DeleteSHACLShape =
new TestCase(
"SHACL shapes can be deleted",
(driver, log) =>
{
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
//Log in
driver.ByPassLogin();
//Open a SHACL file
driver.OpenSHACLFile("demo_shacl.ttl");
IWebElement shaclElement = driver.FindElement(By.XPath("//*[contains(text(),'PersonShape')]"), 10);
String shaclElementID = shaclElement.GetAttribute("id");
shaclElement.Click();
SendKeys.SendWait("{DEL}");
System.Threading.Thread.Sleep(500);
try
{

IReadOnlyCollection<IWebElement> elements = driver.FindElements(By.Id(shaclElementID));
Assert.IsTrue(elements.Count == 0);
}
catch (StaleElementReferenceException) {
Assert.IsTrue(true);
}
});

public static readonly TestCase DeleteDataShape =
new TestCase(
"Data shapes can be deleted",
(driver, log) =>
{
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
//Log in
driver.ByPassLogin();
//Open a SHACL file
driver.OpenDataFile("demo_data_conforming.ttl");
var dataElement = driver.FindElement(By.XPath("//*[contains(text(),'Alice')]"), 10);
String elementID = dataElement.GetAttribute("id");
dataElement.Click();
SendKeys.SendWait("{DEL}");
System.Threading.Thread.Sleep(500);
try
{
IReadOnlyCollection<IWebElement> elements = driver.FindElements(By.Id(elementID));
Assert.IsTrue(elements.Count == 0);
}
catch (OpenQA.Selenium.StaleElementReferenceException) {
Assert.IsTrue(true);
}
});

public static readonly TestCase DeleteSHACLProperty =
new TestCase(
"SHACL properties can be deleted",
(driver, log) =>
{
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
//Log in
driver.ByPassLogin();

//Open a SHACL file
driver.OpenSHACLFile("demo_shacl.ttl");
var shaclElement = driver.FindElement(By.XPath("//*[contains(text(),'sh:targetClass')]"), 10);
String elementID = shaclElement.GetAttribute("id");
Assert.IsTrue(shaclElement.Text == "sh:targetClass : ex:Person");
//Element is selected
shaclElement.Click();
SendKeys.SendWait("{DEL}");
System.Threading.Thread.Sleep(500);
try
{
IReadOnlyCollection<IWebElement> elements = driver.FindElements(By.Id(elementID));
Assert.IsTrue(elements.Count == 0);
}
catch (OpenQA.Selenium.StaleElementReferenceException)
{
Assert.IsTrue(true);
}

});

public static readonly TestCase DeleteDataAttribute=
new TestCase(
"SHACL properties can be deleted",
(driver, log) =>
{
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
//Log in
driver.ByPassLogin();

//Open a SHACL file
driver.OpenDataFile("demo_data_conforming.ttl");
var dataElement = driver.FindElement(By.XPath("//*[contains(text(),'Person')]"), 10);
String elementID = dataElement.GetAttribute("id");
Assert.IsTrue(dataElement.Text.Contains("Person"));
//Element is selected
dataElement.Click();
SendKeys.SendWait("{DEL}");
System.Threading.Thread.Sleep(500);
try
{
IReadOnlyCollection<IWebElement> elements = driver.FindElements(By.Id(elementID));
Assert.IsTrue(elements.Count == 0);
}
catch (OpenQA.Selenium.StaleElementReferenceException)
{
Assert.IsTrue(true);
}

});

public static readonly ICollection<TestCase> All =
new[]
{
DeleteSHACLShape,
DeleteDataShape,
DeleteSHACLProperty,
DeleteDataAttribute
};
}
}
Loading