Skip to content

Instantly share code, notes, and snippets.

@rajaraodv
Last active May 22, 2020 04:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rajaraodv/d6d684708dfde821fcb145597eaa79c0 to your computer and use it in GitHub Desktop.
Save rajaraodv/d6d684708dfde821fcb145597eaa79c0 to your computer and use it in GitHub Desktop.
//Note: This is just an example in .Net C#. This shows how to print and also how to call that method.
//Feel free to change it to your language and framework needs
using NUnit.Framework;
using OpenQA.Selenium;
using System.IO;
namespace HackathonReport3
{
[TestFixture()]
public class Test
{
// Get the browser, viewport and device info from a variable like below or from a file or environment variable.
public static string Browser = "Firefox";
public static string Viewport = "1200X700";
public static string Device = "Laptop";
/**
* A Helper to print the test result in the following format:
* Task: <Task Number>, Test Name: <Test Name>, DOM Id:: <id>, Browser: <Browser>, Viewport: <Width x Height>, Device<Device type>, Status: <Pass | Fail>
*
* Example: Task: 1, Test Name: Search field is displayed, DOM Id: DIV__customsear__41, Browser: Chrome, Viewport: 1200 x 700, Device: Laptop, Status: Pass
*
* @param task int - 1, 2 or 3
* @param testName. string - Something meaningful. E.g. 1.1 Search field is displayed
* @param domId string - DOM ID of the element
* @param comparisonResult boolean - The result of comparing the "Expected" value and the "Actual" value.
* @return boolean - returns the same comparison result back so that it can be used for further Assertions in the test code.
*/
public bool HackathonReport(int task, string testName, string domId, bool compatisonResult)
{
using (StreamWriter fs = new StreamWriter("traditional-V1-TestResults.txt", true))
{
string ReportContent = string.Format("Task: {0}, Test Name: {1}, Browser {2}, Viewport {3}, " +
"Device {4}, Status: {5}", task, testName, Browser, Viewport, Device, compatisonResult);
fs.WriteLine(ReportContent);
}
//returns the result so that it can be used for further Assertions in the test code.
return compatisonResult;
}
[Test()]
public void TestCase()
{
string searchField = "DIV__customsear__41";
string searchIcon = "DIV__customsear__42";
//Report and then soft-assert
//Assert all elements inside this test
Assert.Multiple(() =>
{
Assert.True(HackathonReport(2, "Search field is displayed", searchField, driver.FindElement(By.Id(searchField)).Displayed));
Assert.True(HackathonReport(2, "Search icon is displayed", searchIcon, driver.FindElement(By.Id(searchIcon)).Displayed));
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment