package com.intland.codebeamer.functionaltest.test;

import static com.codeborne.selenide.Selenide.open;
import static com.codeborne.selenide.Selenide.sleep;
import static org.testng.Assert.*;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

import com.intland.codebeamer.functionaltest.helper.FilterValues;
import com.intland.codebeamer.functionaltest.helper.FilterValues.CustomDateRange;
import com.intland.codebeamer.functionaltest.helper.FilterValues.FieldType;
import com.intland.codebeamer.functionaltest.helper.FilterValues.FilterValue;
import com.intland.codebeamer.functionaltest.helper.FilterValues.NumberFilterValue;
import com.intland.codebeamer.functionaltest.helper.FilterValues.NumericOperator;
import com.intland.codebeamer.functionaltest.helper.FilterValues.OrderType;
import com.intland.codebeamer.functionaltest.helper.FilterValues.TextFilterValue;
import com.intland.codebeamer.functionaltest.helper.FilterValues.TimeType;
import com.intland.codebeamer.functionaltest.helper.Helper;
import com.intland.codebeamer.functionaltest.page.ReportsPage;
import com.intland.codebeamer.functionaltest.page.projects.ProjectsPage;
import com.intland.codebeamer.functionaltest.page.trackers.TrackerConfigurationPage;
import com.intland.codebeamer.functionaltest.page.trackers.TrackersPage;

/**
 * Copyright by Intland Software
 * <p>
 * All rights reserved.
 * <p>
 * This software is the confidential and proprietary information
 * of Intland Software. ("Confidential Information"). You
 * shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the productLicense agreement
 * you entered into with Intland.
 */
public class ReportTests extends BaseTest {
	/*
	 * Helper class instance
	 */
	private static FilterValues filterValues = new FilterValues();

	/*
	 * DataProviders for parameterized tests
	 */
	@DataProvider(name = "defaultFieldsProvider")
	public static Object[][] defaultFieldNames() {
		return new Object[][] {
				{ "Accrued Effort" },
				{ "Assigned at" },
				{ "Assigned to" },
				{ "Category" },
				// { "Description" }, Description field can not be used in Group By/Order By
				{ "End Date" },
				{ "Estimated Effort" },
				{ "Modified at" },
				{ "Modified by" },
				{ "Owner" },
				{ "Priority" },
				{ "Resolution" },
				{ "Severity" },
				{ "Spent Effort" },
				{ "% Spent / Plan" },
				{ "Start Date" },
				{ "Status" },
				{ "Story Points" },
				{ "Submitted at" },
				{ "Submitted by" },
				{ "Summary" }
		};
	}

	@DataProvider(name = "referenceFieldsProvider")
	public static Object[][] referencFieldNames() {
		return new Object[][] { 
			{ "Children" },
			{ "Parent" },
			{ "Release" },
			{ "Subject" },
			{ "Team" }
		};
	}

	@DataProvider(name = "defaultFieldTypeNameValueProvider")
	public static Object[][] defaultFieldTypeNameValue() {
		return new Object[][] {
				{ "Accrued Effort", FieldType.Duration,
						filterValues.new DurationFilterValue(NumericOperator.less_than, "20", TimeType.hour) },
				{ "Assigned at", FieldType.Date, filterValues.new DateFilterValue(CustomDateRange.Current_and_previous_year) },
				{ "Assigned to", FieldType.Member,
						filterValues.new MemberFilterValue(
								new String[] { "test-user-sel-1109411 (1109411 1109411, testuser.ttt)" }) },
				{ "Category", FieldType.Choice,
						filterValues.new ChoiceFilterValue(new String[] { "Functional", "Security" }) },
				{ "Description", FieldType.Text, filterValues.new TextFilterValue("test") },
				{ "End Date", FieldType.Date, filterValues.new DateFilterValue(CustomDateRange.Current_and_next_year) },
				{ "Estimated Effort", FieldType.Duration,
						filterValues.new DurationFilterValue(NumericOperator.equals, "120", TimeType.minute) },
				{ "Modified at", FieldType.Date, filterValues.new DateFilterValue("2015-09-30", "2017-09-30") },
				{ "Modified by", FieldType.Member, filterValues.new MemberFilterValue(new String[] { "me" }) },
				{ "Owner", FieldType.Member,
						filterValues.new MemberFilterValue(
								new String[] { "test-user-sel-1109411 (1109411 1109411, testuser.ttt)" }) },
				{ "Priority", FieldType.Choice, filterValues.new ChoiceFilterValue(new String[] { "Normal" }) },
				{ "Resolution", FieldType.Choice,
						filterValues.new ChoiceFilterValue(new String[] { "Duplicate", "Won't Fix" }) },
				{ "Severity", FieldType.Choice,
						filterValues.new ChoiceFilterValue(new String[] { "Critical", "Major" }) },
				{ "Spent Effort", FieldType.Duration,
						filterValues.new DurationFilterValue(NumericOperator.greater_than_or_equals_to, "20",
								TimeType.minute) },
				{ "% Spent / Plan", FieldType.Number,
						filterValues.new NumberFilterValue(NumericOperator.less_than_or_equals_to, "90") },
				{ "Start Date", FieldType.Date,
						filterValues.new DateFilterValue(CustomDateRange.Current_and_previous_year) },
				{ "Status", FieldType.Choice,
						filterValues.new ChoiceFilterValue(new String[] { "In progress", "Unreleased", "New" }) },
				{ "Story Points", FieldType.Number,
						filterValues.new NumberFilterValue(NumericOperator.less_than, "5") },
				{ "Submitted at", FieldType.Date, filterValues.new DateFilterValue(CustomDateRange.Last_120_Days) },
				{ "Submitted by", FieldType.Member,
						filterValues.new MemberFilterValue(new String[] { "bond (Default System Administrator, bond.bondbond)" }) },
				{ "Summary", FieldType.Text, filterValues.new TextFilterValue("%test%") }
			};
	}

	@DataProvider(name = "referenceFieldNamesValuesProvider")
	public static Object[][] referenceFieldNamesValues() {
		return new Object[][] { 
			    { "Children", new String[] {}, new String[] { "Test Requirement 2" } },
				{ "Parent", new String[] {}, new String[] { "Test Requirement 1" } },
				{ "Release", new String[] {}, new String[] { "Test Release2" } },
				{ "Subject", new String[] {}, new String[] { "Test User Story 1" } },
				{ "Team", new String[] {}, new String[] { "Design Team" } }
		};
	}

	@DataProvider(name = "referenceFieldNamesValuesTrackersProvider")
	public static Object[][] referenceFieldNamesValuesTrackers() {
		return new Object[][] {
				{ "Children", new String[] {}, new String[] { "Test Requirement 2" } },
				{ "Parent", new String[] {}, new String[] { "Test Requirement 1" } },
				{ "Release", new String[] {}, new String[] { "Test Release" } },
				{ "Subject", new String[] {}, new String[] { "Test User Story 1" } },
				{ "Team", new String[] {}, new String[] { "Design Team" } },
				{ "Reference to", new String[] { "Bugs", "New User Stories" }, new String[] { "Test User Story 1" } },
				{ "Reference from", new String[] { "Bugs", "New User Stories" }, new String[] { "Test User Story 1" } }
		};
	}

	@DataProvider(name = "fieldTypesValuesProvider")
	public static Object[][] fieldTypesValuesProvider() {
		return new Object[][] {
				{ FieldType.Choice, new String[] { "Category", "Priority", "Resolution", "Severity", "Status" } },
				{ FieldType.Member, new String[] { "Assigned to", "Modified by", "Owner", "Submitted by" } },
				{ FieldType.Reference, new String[] { "Children", "Parent", "Release", "Subject", "Team" } },
				{ FieldType.Date,
						new String[] { "Assigned at", "End Date", "Modified at", "Start Date", "Submitted at" } },
				{ FieldType.Text, new String[] { "Description", "Summary" } },
				{ FieldType.Number, new String[] { "% Spent / Plan", "Story Points" } },
				{ FieldType.Duration, new String[] { "Accrued Effort", "Estimated Effort", "Spent Effort" } } };
	}

	@DataProvider(name = "addFieldsProvider")
	public static Object[][] addFields() {
		return new Object[][] { { "Project" }, { "Tracker" }, { "Tracker Type" }, { "Accrued Effort" },
				{ "Assigned at" }, { "Assigned to" }, { "Category" },
				// { "Description" }, Description field can not be used in Group By/Order By
				{ "End Date" },
				{ "Estimated Effort" },
				{ "Modified at" }, { "Modified by" }, { "Owner" }, { "Priority" }, { "Resolution" }, { "Severity" },
				{ "Spent Effort" }, { "% Spent / Plan" }, { "Start Date" }, { "Status" }, { "Story Points" },
				{ "Submitted at" }, { "Submitted by" }, { "Summary" },
				{ "Children" },
				{ "Parent" }, { "Release" }, { "Subject" }, { "Team" } };
	}

	@DataProvider(name = "textFieldValuesProvider")
	public static Object[][] textFieldValues() {
		return new Object[][] { 
				{ filterValues.new TextFilterValue("%test%") },
				{ filterValues.new TextFilterValue("%パスワードを忘れてしまった方へ%") },
				{ filterValues.new TextFilterValue("%aßen Mäxchens Vögel Rüben%") }
		};
	}

	@DataProvider(name = "numberFieldValuesProvider")
	public static Object[][] numberFieldValues() {
		return new Object[][] { 
				{ filterValues.new NumberFilterValue(NumericOperator.greater_than, "0") },
				{ filterValues.new NumberFilterValue(NumericOperator.greater_than_or_equals_to, "2") },
				{ filterValues.new NumberFilterValue(NumericOperator.equals, "2") },
				{ filterValues.new NumberFilterValue(NumericOperator.less_than_or_equals_to, "5") },
				{ filterValues.new NumberFilterValue(NumericOperator.less_than, "100") }
		};
	}

	@DataProvider(name = "choiceFieldValuesProvider")
	public static Object[][] choiceFieldValues() {
		return new Object[][] { 
				{ filterValues.new ChoiceFilterValue(new String[] { "New" }), "New, New, New" },
				{ filterValues.new ChoiceFilterValue(new String[] { "Unreleased" }), "Unreleased" },
				{ filterValues.new ChoiceFilterValue(new String[] { "Resolved" }), "Resolved, Resolved" },
				{ filterValues.new ChoiceFilterValue(new String[] { "In progress" }),"In progress, In progress, In progress" }
		};
	}

	@DataProvider(name = "memberFieldValuesProvider")
	public static Object[][] memberFieldValues() {
		return new Object[][] { {
				filterValues.new MemberFilterValue(
						new String[] { "test-user-sel-1109411 (1109411 1109411, testuser.ttt)",
								"bond (Default System Administrator, bond.bondbond)", "Project Admin", "Tester" }),
				"bond (Default System Administrator, bond.bondbond), test-use..." }, };
	}

	@Test
	public void testLeftFieldTree() {

		// PreAction
		Helper.loginWithSystemAdmin();

		// TEST STEP 1
		// Open queries page
		ReportsPage reportsPage = open("/query/new", ReportsPage.class);

		// EXPECTED RESULT 1
		// Queries page opens
		assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");

		// TEST STEP 2
		// Verify the layout of left field tree

		// EXPECTED RESULT 2
		// Field tree is closable
		assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen());
		assertTrue(reportsPage.fieldTree.isReferenceFieldsNodeOpen());
		reportsPage.fieldTree.clickOnDefaultFieldsNode();
		reportsPage.fieldTree.clickOnReferenceFieldsNode();
		assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeClosed());
		assertTrue(reportsPage.fieldTree.isReferenceFieldsNodeClosed());
		// Not test step - Reopen nodes
        reportsPage.fieldTree.clickOnDefaultFieldsNode();
        reportsPage.fieldTree.clickOnReferenceFieldsNode();
		assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen());
		assertTrue(reportsPage.fieldTree.isReferenceFieldsNodeOpen());

		// It has a text filter in header
		assertTrue(reportsPage.fieldTree.textFilterIsDisplayed());

		// It has a field type filter in header
		assertTrue(reportsPage.fieldTree.isTypeFilterDisplayed());

		// It has Default Fields category
		assertTrue(reportsPage.fieldTree.isDefaultFieldsFolderDisplayed());

		// It has Common Reference Fields category
		assertTrue(reportsPage.fieldTree.isCommonReferenceFieldsFolderDisplayed());

		List<String> filteredList = reportsPage.fieldTree.getFilteredFieldNames();
		assertEquals(filteredList.size(), 26, String.format("Expected 26 fields before filtering!"));

		// TEST STEP 3
		// Type a text in the filter field in header
		reportsPage.fieldTree.sendKeysToTextFilter("ass");

		// EXPECTED RESULT 3
		// The tree is filtered by names
		List<String> expectedFieldNames = new ArrayList<String>();
		expectedFieldNames.add("Assigned at");
		expectedFieldNames.add("Assigned to");

		filteredList = reportsPage.fieldTree.getFilteredFieldNames();
		assertEquals(filteredList.size(), 2, String.format("Expected 2 fields after filtering! ({0}, {1})",
				expectedFieldNames.get(0), expectedFieldNames.get(1)));

		assertEquals(filteredList.get(0), expectedFieldNames.get(0),
				String.format("Filtered field 0 is not {0}", expectedFieldNames.get(0)));
		assertEquals(filteredList.get(1), expectedFieldNames.get(1),
				String.format("Filtered field 1 is not {0}", expectedFieldNames.get(1)));

		// TEST STEP 4
		// Clear the filter field
		reportsPage.fieldTree.sendKeysToTextFilter("\b\b\b");

		// EXPECTED RESULT 4
		// Full tree is displayed
		filteredList = reportsPage.fieldTree.getFilteredFieldNames();
		assertEquals(filteredList.size(), 26, String.format("Expected 26 fields after clearing filter!"));

		// TEST STEP 5
		// Select a field type in the drop down in header
		reportsPage.fieldTree.selectOptionInTypeFilterByText("Text");

		// EXPECTED RESULT 5
		// Tree is filtered for field type
		expectedFieldNames.clear();
		expectedFieldNames.add("Description");
		expectedFieldNames.add("Summary");

		filteredList = reportsPage.fieldTree.getFilteredFieldNames();
		assertEquals(filteredList.size(), 2, String.format("Expected 2 fields after filtering! ({0}, {1})",
				expectedFieldNames.get(0), expectedFieldNames.get(1)));

		assertEquals(filteredList.get(0), expectedFieldNames.get(0),
				String.format("Filtered field 0 is not {0}", expectedFieldNames.get(0)));
		assertEquals(filteredList.get(1), expectedFieldNames.get(1),
				String.format("Filtered field 1 is not {0}", expectedFieldNames.get(1)));

		// TEST STEP 6
		// Clear the type filter
		reportsPage.fieldTree.selectOptionInTypeFilterByText("All types");

		// EXPECTED RESULT 6
		// Full tree is displayed
		filteredList = reportsPage.fieldTree.getFilteredFieldNames();
		assertEquals(filteredList.size(), 26, String.format("Expected 26 fields after clearing filter!"));

		// TEST STEP 7
		// Select a project, and a tracker with custom fields
		List<String> projectNames = new ArrayList<String>();
		projectNames.add("test-project-sel-526861927 1");
		List<String> trackerNames = new ArrayList<String>();
		trackerNames.add("Bugs");

		reportsPage.reportEditor.selectProjectsByName(projectNames);
		reportsPage.reportEditor.selectTrackersByName(trackerNames);

		// EXPECTED RESULT 7
		// Tree is extended with one more category: project name, tracker name,
		// custom fields
		assertTrue(reportsPage.fieldTree.isSelectedProjectFoldersDisplayed());
		assertTrue(reportsPage.fieldTree.isSelectedTrackerFoldersDisplayed());

		expectedFieldNames.clear();
		expectedFieldNames.add("Detected in");
		expectedFieldNames.add("Test Custom Field116"); //TODO warning testCreateAndDeletNewCustomField from selenium can overwrite this

		List<String> customFieldNames = reportsPage.fieldTree.getCustomFieldNames();
		assertEquals(customFieldNames.get(0), expectedFieldNames.get(0),
				String.format("Custom field 0 is not {0}", expectedFieldNames.get(0)));
		assertEquals(customFieldNames.get(1), expectedFieldNames.get(1),
				String.format("Custom field 1 is not {0}", expectedFieldNames.get(1)));

		// TEST STEP 8
		// Verify that selecting 1 tracker results in changing the field names
		// from the system names to the customized names of tracker fields

		// Clearing selection to get default field names
		trackerNames.clear();
		trackerNames.add("Any");
		reportsPage.reportEditor.selectTrackersByName(trackerNames);

		List<String> fieldIds = new ArrayList<String>();
		fieldIds.add("13"); // Category -> Type
		fieldIds.add("14"); // Severity -> Complexity
		fieldIds.add("2"); // Priority -> Business Value
		fieldIds.add("10"); // Estimated Effort -> Planned Effort

		List<String> defaultFieldNames = reportsPage.fieldTree.getFieldNamesById(fieldIds);
		assertEquals(defaultFieldNames.get(0), "Category");
		assertEquals(defaultFieldNames.get(1), "Severity");
		assertEquals(defaultFieldNames.get(2), "Priority");
		assertEquals(defaultFieldNames.get(3), "Estimated Effort");

		// EXPECTED RESULT 8
		// If tracker is selected, customized name is displayed

		// Clearing selection to get customized tracker field names
		trackerNames.clear();
		trackerNames.add("Requirements");
		reportsPage.reportEditor.selectTrackersByName(trackerNames);

		List<String> customizedFieldNames = reportsPage.fieldTree.getFieldNamesById(fieldIds);
		assertEquals(customizedFieldNames.get(0), "Type");
		assertEquals(customizedFieldNames.get(1), "Complexity");
		assertEquals(customizedFieldNames.get(2), "Business Value");
		assertEquals(customizedFieldNames.get(3), "Planned Effort");

		// TEST STEP 9
		// Verify that if no tracker is selected,
		// or more than one trackers are selected, the system names of the
		// fields are displayed in left tree

		// no tracker option tested above; selecting more than one trackers
		trackerNames.clear();
		trackerNames.add("Bugs"); // clicking only on Bugs tracker; this will
									// NOT deselect the already selected tracker
		reportsPage.reportEditor.selectTrackersByName(trackerNames);

		defaultFieldNames = reportsPage.fieldTree.getFieldNamesById(fieldIds);
		assertEquals(defaultFieldNames.get(0), "Category");
		assertEquals(defaultFieldNames.get(1), "Severity");
		assertEquals(defaultFieldNames.get(2), "Priority");
		assertEquals(defaultFieldNames.get(3), "Estimated Effort");
	}

	@Test(dataProvider = "defaultFieldTypeNameValueProvider")
	public void testDragAndDropDefaultFieldAsFilter(String fieldName, FieldType fieldType, FilterValue filterValues) {

		// PreAction
		Helper.loginWithSystemAdmin();

		// TEST STEP 1
		// Open Reports page
		ReportsPage reportsPage = open("/query/new", ReportsPage.class);

		// EXPECTED RESULT 1
		// Reports page opens.
		assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");
		try {
			// TEST STEP 2
			// Select test project, some trackers and drop field
			// ${defaultFieldName}
			// to filter area, set it up with a value
			List<String> projectNames = new ArrayList<String>();
			projectNames.add("test-project-sel-526861927 1");
			List<String> trackerNames = new ArrayList<String>();
			trackerNames.add("Bugs");
			trackerNames.add("Releases");
			trackerNames.add("Tasks");
			trackerNames.add("Test Cases");

			reportsPage.reportEditor.selectProjectsByName(projectNames);
			reportsPage.reportEditor.selectTrackersByName(trackerNames);
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen());
			assertTrue(reportsPage.fieldTree.isSelectedTrackerFoldersDisplayed());
			// use these in pair: drop field, then set value
			reportsPage.fieldTree.dragAndDropFieldToFilterArea(fieldName);
			reportsPage.reportEditor.setDefaultFieldFilterByType(fieldType, filterValues);

			// EXPECTED RESULT 2
			// Field is dropped, value is set.

			// TEST STEP 3
			// Click on the GO button
			reportsPage.reportEditor.clickOnGoButton();

			// EXPECTED RESULT 3
			// Report is executed, result list is displayed (may be empty)
			assertTrue(reportsPage.resultTable.isResultTableDisplayed());
		} finally {
			// not test step - for automation only
			reportsPage = open("/query/new", ReportsPage.class);
			reportsPage.clickOnLogout();
		}
	}

	@Test(dataProvider = "referenceFieldNamesValuesProvider")
	public void testDragAndDropReferenceFieldAsFilter(String fieldName, String[] trackersToSelect, String[] values) {
		// PreAction
		Helper.loginWithSystemAdmin();

		// TEST STEP 1
		// Open Reports page
		ReportsPage reportsPage = open("/query/new", ReportsPage.class);

		// EXPECTED RESULT 1
		// Reports page opens.
		assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");
		try {
			// TEST STEP 2
			// Select test project, some trackers and drop field
			// ${referenceFieldName} to filter area, set it up with a value
			List<String> projectNames = new ArrayList<String>();
			projectNames.add("test-project-sel-526861927 1");
			List<String> trackerNames = new ArrayList<String>();
			trackerNames.add("New Requirements");

			reportsPage.reportEditor.selectProjectsByName(projectNames);
			reportsPage.reportEditor.selectTrackersByName(trackerNames);
			assertTrue(reportsPage.fieldTree.isReferenceFieldsNodeOpen());
			assertTrue(reportsPage.fieldTree.isSelectedTrackerFoldersDisplayed());
			// use these in pair: drop field, then set value
			reportsPage.fieldTree.dragAndDropFieldToFilterArea(fieldName);
			reportsPage.reportEditor.setReferenceFieldFilterByChooseItemPopup(trackersToSelect, values);

			// EXPECTED RESULT 2
			// Field is dropped, value is set.

			// TEST STEP 3
			// Click on the GO button
			reportsPage.reportEditor.clickOnGoButton();

			// EXPECTED RESULT 3
			// Report is executed, result list is displayed (may be empty)

			assertTrue(reportsPage.resultTable.isResultTableDisplayed());
		} finally {
			// not test step - for automation only
			reportsPage = open("/query/new", ReportsPage.class);
			reportsPage.clickOnLogout();
		}
	}

	@Test(dataProvider = "defaultFieldsProvider")
	public void testDragAndDropDefaultFieldAsGroupBy(String fieldName) {
		// PreAction
		Helper.loginWithSystemAdmin();

		// TEST STEP 1
		// Open Reports page
		ReportsPage reportsPage = open("/query/new", ReportsPage.class);

		// EXPECTED RESULT 1
		// Reports page opens.
		assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");
		try {
			// TEST STEP 2
			// Select test project, some trackers and drop field
			// ${defaultFieldName}
			// to group by area
			List<String> projectNames = new ArrayList<String>();
			projectNames.add("test-project-sel-526861927 1");
			List<String> trackerNames = new ArrayList<String>();
			trackerNames.add("Bugs");
			trackerNames.add("Releases");
			trackerNames.add("Tasks");
			trackerNames.add("Test Cases");

			reportsPage.reportEditor.selectProjectsByName(projectNames);
			reportsPage.reportEditor.selectTrackersByName(trackerNames);
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen());
			assertTrue(reportsPage.fieldTree.isSelectedTrackerFoldersDisplayed());
			// use these in pair: drop field, then set value
			reportsPage.fieldTree.dragAndDropFieldToGroupByArea(fieldName);

			// EXPECTED RESULT 2
			// Field is dropped to group by area

			// TEST STEP 3
			// Click on the GO button
			reportsPage.reportEditor.clickOnGoButton();

			// EXPECTED RESULT 3
			// Report is executed, result list is grouped by dropped field.

			assertTrue(reportsPage.resultTable.isResultTableGroupedByField(fieldName));
		} finally {
			// not test step - for automation only
			reportsPage = open("/query/new", ReportsPage.class);
			reportsPage.clickOnLogout();
		}
	}

	@Test(dataProvider = "referenceFieldsProvider")
	public void testDragAndDropReferenceFieldAsGroupBy(String fieldName) {
		// PreAction
		Helper.loginWithSystemAdmin();

		// TEST STEP 1
		// Open Reports page
		ReportsPage reportsPage = open("/query/new", ReportsPage.class);

		// EXPECTED RESULT 1
		// Reports page opens.
		assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");
		try {
			// TEST STEP 2
			// Select test project, some trackers and drop field
			// ${referenceFieldName}
			// to group by area
			List<String> projectNames = new ArrayList<String>();
			projectNames.add("test-project-sel-526861927 1");
			List<String> trackerNames = new ArrayList<String>();
			trackerNames.add("New Requirements");

			reportsPage.reportEditor.selectProjectsByName(projectNames);
			reportsPage.reportEditor.selectTrackersByName(trackerNames);
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen());
			assertTrue(reportsPage.fieldTree.isSelectedTrackerFoldersDisplayed());
			// use these in pair: drop field, then set value
			reportsPage.fieldTree.dragAndDropFieldToGroupByArea(fieldName);

			// EXPECTED RESULT 2
			// Field is dropped to group by area

			// TEST STEP 3
			// Click on the GO button
			reportsPage.reportEditor.clickOnGoButton();

			// EXPECTED RESULT 3
			// Report is executed, result list is grouped by dropped field.

			assertTrue(reportsPage.resultTable.isResultTableGroupedByField(fieldName));
		} finally {
			// not test step - for automation only
			reportsPage = open("/query/new", ReportsPage.class);
			reportsPage.clickOnLogout();
		}
	}

	@Test(dataProvider = "defaultFieldsProvider")
	public void testDragAndDropDefaultFieldAsOrderBy(String fieldName) {
		// PreAction
		Helper.loginWithSystemAdmin();

		// TEST STEP 1
		// Open Reports page
		ReportsPage reportsPage = open("/query/new", ReportsPage.class);

		// EXPECTED RESULT 1
		// Reports page opens.
		assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");
		try {
			// TEST STEP 2
			// Select test project, some trackers and drop field
			// ${defaultFieldName}
			// to order by area
			List<String> projectNames = new ArrayList<String>();
			projectNames.add("test-project-sel-526861927 1");
			List<String> trackerNames = new ArrayList<String>();
			switch (fieldName) {
			case "Category":
				trackerNames.add("New Requirements");
				trackerNames.add("Requirements");
				break;
			case "Resolution":
				trackerNames.add("New Tasks");
				break;
			case "Severity":
				trackerNames.add("New Tasks");
				trackerNames.add("New Requirements");
				break;
			case "Start Date":
				trackerNames.add("New Tasks");
				break;
			default:
				trackerNames.add("New Requirements");
				trackerNames.add("New Tasks");
				trackerNames.add("New User Stories");
				break;
			}

			reportsPage.reportEditor.selectProjectsByName(projectNames);
			reportsPage.reportEditor.selectTrackersByName(trackerNames);
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen());
			assertTrue(reportsPage.fieldTree.isSelectedTrackerFoldersDisplayed());
			// use these in pair: drop field, then set value
			reportsPage.fieldTree.dragAndDropFieldToOrderByArea(fieldName);

			// EXPECTED RESULT 2
			// Field is dropped to order by area

			// TEST STEP 3
			// Click on the GO button
			reportsPage.reportEditor.clickOnGoButton();

			// EXPECTED RESULT 3
			// Report is executed, result list is displayed
			assertTrue(reportsPage.resultTable.isResultTableDisplayed());

			// TEST STEP 4
			// Drop field ${defaultFieldName} to result table
			reportsPage.fieldTree.dragAndDropFieldToResultTable(fieldName);

			// EXPECTED RESULT 4
			// Result list is displayed, and sorted ascending by field.
			assertTrue(reportsPage.resultTable.isResultTableOrderedByField(fieldName, OrderType.Ascending));

			// TEST STEP 5
			// Change sorting order by clicking on button with text ASC in field
			// widget in Order By area.
			assertEquals(reportsPage.reportEditor.getFieldOrderTypeButtonText(fieldName), "ASC");
			reportsPage.reportEditor.clickFieldOrderTypeButton(fieldName);

			// EXPECTED RESULT 5
			// Button text changed to DESC.
			assertEquals(reportsPage.reportEditor.getFieldOrderTypeButtonText(fieldName), "DESC");

			// TEST STEP 6
			// Click on GO button.
			reportsPage.reportEditor.clickOnGoButton();
			// TODO - nothing to sync on yet, table is present. Try "Loading..."
			// overlay
			sleep(1000);
			// EXPECTED RESULT 6
			// Result list is displayed, and sorted descending by sort field.
			assertTrue(reportsPage.resultTable.isResultTableOrderedByField(fieldName, OrderType.Descending));
		} finally {
			reportsPage = open("/query/new", ReportsPage.class);
			reportsPage.clickOnLogout();
		}
	}

	@Test(dataProvider = "referenceFieldsProvider")
	public void testDragAndDropReferenceFieldAsOrderBy(String fieldName) {
		// PreAction
		Helper.loginWithSystemAdmin();

		// TEST STEP 1
		// Open Reports page
		ReportsPage reportsPage = open("/query/new", ReportsPage.class);

		// EXPECTED RESULT 1
		// Reports page opens.
		assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");
		try {
			// "Children" field can not be dropped to Order By area
			if (fieldName != "Children") {
				// TEST STEP 2
				// Select test project, some trackers and drop field
				// ${referenceFieldName}
				// to order by area
				List<String> projectNames = new ArrayList<String>();
				projectNames.add("test-project-sel-526861927 1");
				List<String> trackerNames = new ArrayList<String>();
				trackerNames.add("New Requirements");
				trackerNames.add("New Tasks");
				trackerNames.add("New User Stories");

				reportsPage.reportEditor.selectProjectsByName(projectNames);
				reportsPage.reportEditor.selectTrackersByName(trackerNames);
				assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen());
				assertTrue(reportsPage.fieldTree.isSelectedTrackerFoldersDisplayed());
				reportsPage.fieldTree.dragAndDropFieldToOrderByArea(fieldName);

				// EXPECTED RESULT 2
				// Field is dropped to order by area

				// TEST STEP 3
				// Click on the GO button
				reportsPage.reportEditor.clickOnGoButton();

				// EXPECTED RESULT 3
				// Report is executed, result list is displayed
				assertTrue(reportsPage.resultTable.isResultTableDisplayed());

				// TEST STEP 4
				// Drop field ${defaultFieldName} to result table
				reportsPage.fieldTree.dragAndDropFieldToResultTable(fieldName);

				// EXPECTED RESULT 4
				// Result list is displayed, and sorted ascending by field.
				assertTrue(reportsPage.resultTable.isResultTableOrderedByField(fieldName, OrderType.Ascending));

				// TEST STEP 5
				// Change sorting order by clicking on button with text ASC in
				// field
				// widget in Order By area.
				assertEquals(reportsPage.reportEditor.getFieldOrderTypeButtonText(fieldName), "ASC");
				reportsPage.reportEditor.clickFieldOrderTypeButton(fieldName);

				// EXPECTED RESULT 5
				// Button text changed to DESC.
				assertEquals(reportsPage.reportEditor.getFieldOrderTypeButtonText(fieldName), "DESC");

				// TEST STEP 6
				// Click on GO button.
				reportsPage.reportEditor.clickOnGoButton();
				// TODO - nothing to sync on yet, table is present. Try
				// "Loading..." overlay
				sleep(1000);
				// EXPECTED RESULT 6
				// Result list is displayed, and sorted descending by sort
				// field.
				assertTrue(reportsPage.resultTable.isResultTableOrderedByField(fieldName, OrderType.Descending));
			}
		} finally {
			reportsPage = open("/query/new", ReportsPage.class);
			reportsPage.clickOnLogout();
		}
	}

	@Test
	public void testDragAndDropCustomFieldAsFilter() {
		// PreAction
		Helper.loginWithSystemAdmin();

		// TEST STEP 1
		// Open Reports page
		ReportsPage reportsPage = open("/query/new", ReportsPage.class);

		// EXPECTED RESULT 1
		// Reports page opens.
		assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");
		try {
			// TEST STEP 2
			// Select test project, a tracker and drop a custom field to filter
			// area, set it up with a value.
			List<String> projectNames = new ArrayList<String>();
			projectNames.add("test-project-sel-526861927 1");
			List<String> trackerNames = new ArrayList<String>();
			trackerNames.add("New Tasks");
			reportsPage.reportEditor.selectProjectsByName(projectNames);
			reportsPage.reportEditor.selectTrackersByName(trackerNames);
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen());
			assertTrue(reportsPage.fieldTree.isSelectedTrackerFoldersDisplayed());

			// use these in pair: drop field, then set value
			reportsPage.fieldTree.dragAndDropFieldToFilterArea("Country");
			reportsPage.reportEditor.setDefaultFieldFilterByType(FieldType.Choice,
					filterValues.new ChoiceFilterValue(new String[] { "Hungary" }));

			// EXPECTED RESULT 2
			// Filter is dropped and set.

			// TEST STEP 3
			// Click on the GO button.
			reportsPage.reportEditor.clickOnGoButton();

			// EXPECTED RESULT 3
			// Report is executed, result list is displayed.
			assertTrue(reportsPage.resultTable.isResultTableDisplayed());
		} finally {
			reportsPage = open("/query/new", ReportsPage.class);
			reportsPage.clickOnLogout();
		}
	}

	@Test
	public void testDragAndDropCustomFieldAsGroupBy() {
		// PreAction
		Helper.loginWithSystemAdmin();

		// TEST STEP 1
		// Open Reports page
		ReportsPage reportsPage = open("/query/new", ReportsPage.class);

		// EXPECTED RESULT 1
		// Reports page opens.
		assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");
		try {
			// TEST STEP 2
			// Select test project, a tracker and drop a custom field to Group
			// By area.
			List<String> projectNames = new ArrayList<String>();
			projectNames.add("test-project-sel-526861927 1");
			List<String> trackerNames = new ArrayList<String>();
			trackerNames.add("New Tasks");
			reportsPage.reportEditor.selectProjectsByName(projectNames);
			reportsPage.reportEditor.selectTrackersByName(trackerNames);
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen());
			assertTrue(reportsPage.fieldTree.isSelectedTrackerFoldersDisplayed());

			reportsPage.fieldTree.dragAndDropFieldToGroupByArea("Country");

			// EXPECTED RESULT 2
			// Filter is dropped and set.

			// TEST STEP 3
			// Click on the GO button.
			reportsPage.reportEditor.clickOnGoButton();

			// EXPECTED RESULT 3
			// Report is executed, result list is grouped by dropped field
			assertTrue(reportsPage.resultTable.isResultTableGroupedByField("Country"));
		} finally {
			reportsPage = open("/query/new", ReportsPage.class);
			reportsPage.clickOnLogout();
		}
	}

	@Test(dataProvider = "fieldTypesValuesProvider")
	public void testFieldTreeFieldTypeFilter(FieldType fieldType, String[] values) {
		// PreAction
		Helper.loginWithSystemAdmin();

		// TEST STEP 1
		// Open Reports page
		ReportsPage reportsPage = open("/query/new", ReportsPage.class);

		// EXPECTED RESULT 1
		// Reports page opens.
		assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");
		try {
			List<String> filteredList = reportsPage.fieldTree.getFilteredFieldNames();
			assertEquals(filteredList.size(), 26, String.format("Expected 26 fields before filtering!"));
			// TEST STEP 2
			// Select field type ${FieldType} in the drop down in field tree
			// header
			reportsPage.fieldTree.selectOptionInTypeFilterByText(fieldType.toString());

			// EXPECTED RESULT 2
			// Tree is filtered for field type. ${Fields} fields are displayed
			// only.
			List<String> expectedFieldNames = new ArrayList<String>();
			expectedFieldNames.addAll(Arrays.asList(values));

			filteredList = reportsPage.fieldTree.getFilteredFieldNames();
			assertEquals(filteredList.size(), expectedFieldNames.size(),
					String.format("Expected {0} fields after filtering!", expectedFieldNames.size()));
			for (int i = 0; i < filteredList.size(); i++) {
				assertEquals(filteredList.get(i), expectedFieldNames.get(i),
						String.format("Filtered field {0} is not {1}", filteredList.get(i), expectedFieldNames.get(i)));
			}
		} finally {
			reportsPage = open("/query/new", ReportsPage.class);
			reportsPage.clickOnLogout();
		}
	}

	@Test
	public void testDragAndDropAll() {
		// PreAction
		Helper.loginWithSystemAdmin();

		// TEST STEP 1
		// Open Reports page
		ReportsPage reportsPage = open("/query", ReportsPage.class);

		// EXPECTED RESULT 1
		// Reports page opens.
		assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");
		try {
			// TEST STEP 2
			// Select test project, and a tracker with custom fields.
			List<String> projectNames = new ArrayList<String>();
			projectNames.add("test-project-sel-526861927 1");
			List<String> trackerNames = new ArrayList<String>();
			trackerNames.add("New Requirements");

			reportsPage.reportEditor.selectProjectsByName(projectNames);
			reportsPage.reportEditor.selectTrackersByName(trackerNames);
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen());
			assertTrue(reportsPage.fieldTree.isSelectedTrackerFoldersDisplayed());

			// EXPECTED RESULT 2
			// Project, tracker is selected, custom fields appear in left field
			// tree

			// TEST STEP 3
			// Drop all fields to criteria area, set them up with a value
			for (Object[] item : defaultFieldTypeNameValue()) {
				final String fieldName = (String) item[0];
				switch (fieldName) {
				case "Category":
					reportsPage.fieldTree.dragAndDropFieldToFilterArea("Type");
					break;
				case "Estimated Effort":
					reportsPage.fieldTree.dragAndDropFieldToFilterArea("Planned Effort");
					break;
				case "Priority":
					reportsPage.fieldTree.dragAndDropFieldToFilterArea("Business Value");
					break;
				case "Severity":
					reportsPage.fieldTree.dragAndDropFieldToFilterArea("Complexity");
					break;
				default:
					reportsPage.fieldTree.dragAndDropFieldToFilterArea((String) item[0]);
					break;
				}
				reportsPage.reportEditor.setDefaultFieldFilterByType((FieldType) item[1], (FilterValue) item[2]);
			}
			for (Object[] item : referenceFieldNamesValues()) {
				reportsPage.fieldTree.dragAndDropFieldToFilterArea((String) item[0]);
				reportsPage.reportEditor.setReferenceFieldFilterByChooseItemPopup((String[]) item[1],
						(String[]) item[2]);
			}

			// EXPECTED RESULT 3
			// All fields dropped, and set

			// TEST STEP 4
			// Drop 3 fields to group by area
			reportsPage.fieldTree.dragAndDropFieldToGroupByArea("Accrued Effort");
			reportsPage.fieldTree.dragAndDropFieldToGroupByArea("Assigned to");
			reportsPage.fieldTree.dragAndDropFieldToGroupByArea("Release");

			// EXPECTED RESULT 4
			// 3 fields dropped
			assertEquals(reportsPage.reportEditor.getFieldCountInGroupByArea(), 3, "Field count in Group By is not 3!");

			// TEST STEP 5
			// Drop 3 fields to order by area
			reportsPage.fieldTree.dragAndDropFieldToOrderByArea("Planned Effort");
			reportsPage.fieldTree.dragAndDropFieldToOrderByArea("Status");
			reportsPage.fieldTree.dragAndDropFieldToOrderByArea("Team");

			// EXPECTED RESULT 5
			// 3 fields dropped
			assertEquals(reportsPage.reportEditor.getFieldCountInOrderByArea(), 3, "Field count in Order By is not 3!");

			// TEST STEP 6
			// Try to drop some fields again to the group by area
			reportsPage.fieldTree.dragAndDropFieldToGroupByArea("Owner");

			// EXPECTED RESULT 6
			// It is not possible to drop any more fields
			assertEquals(reportsPage.reportEditor.getFieldCountInGroupByArea(), 3,
					"Field count in Group By is not 3! D&D-ing a 4th item was possible!");

			// TEST STEP 7
			// Try to drop some fields again to the order by area
			reportsPage.fieldTree.dragAndDropFieldToOrderByArea("Owner");

			// EXPECTED RESULT 7
			//
			assertEquals(reportsPage.reportEditor.getFieldCountInOrderByArea(), 3,
					"Field count in Order By is not 3! D&D-ing a 4th item was possible!");

			// TEST STEP 8
			// Click on the GO button
			reportsPage.reportEditor.clickOnGoButton();

			// EXPECTED RESULT 8
			// Report is executed, result list is displayed (may be empty)
			reportsPage.resultTable.isSuccessfulExecution();

		} finally {
			reportsPage = open("/query/new", ReportsPage.class);
			reportsPage.clickOnLogout();
		}
	}

	@Test(dataProvider = "defaultFieldTypeNameValueProvider")
	public void testSelectDefaultFieldAsFilter(String fieldName, FieldType fieldType, FilterValue filterValues) {
		// PreAction
		Helper.loginWithSystemAdmin();

		// TEST STEP 1
		// Open Reports page
		ReportsPage reportsPage = open("/query", ReportsPage.class);

		// EXPECTED RESULT 1
		// Reports page opens.
		assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");
		try {
			// TEST STEP 2
			// Select test project, some trackers and add field
			// ${defaultFieldName} using "+Add filter"
			// to filter area, set it up with a value
			List<String> projectNames = new ArrayList<String>();
			projectNames.add("test-project-sel-526861927 1");
			List<String> trackerNames = new ArrayList<String>();
			trackerNames.add("Bugs");
			trackerNames.add("Releases");
			trackerNames.add("Tasks");
			trackerNames.add("Test Cases");

			reportsPage.reportEditor.selectProjectsByName(projectNames);
			reportsPage.reportEditor.selectTrackersByName(trackerNames);
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen());
			assertTrue(reportsPage.fieldTree.isSelectedTrackerFoldersDisplayed());
			// use these in pair: add field, then set value
			reportsPage.reportEditor.addDefaultFieldToFilterArea(fieldName);
			reportsPage.reportEditor.setDefaultFieldFilterByType(fieldType, filterValues);

			// EXPECTED RESULT 2
			// Filter is added and set

			// TEST STEP 3
			// Click on the GO button
			reportsPage.reportEditor.clickOnGoButton();

			// EXPECTED RESULT 3
			// Report is executed, result list is displayed
			assertTrue(reportsPage.resultTable.isResultTableDisplayed());
		} finally {
			// not test step - for automation only
			reportsPage = open("/query/new", ReportsPage.class);
			reportsPage.clickOnLogout();
		}
	}

	@Test(dataProvider = "referenceFieldNamesValuesTrackersProvider")
	public void testSelectReferenceFieldAsFilter(String fieldName, String[] trackersToSelect, String[] values) {
		// PreAction
		Helper.loginWithSystemAdmin();

		// TEST STEP 1
		// Open Reports page
		ReportsPage reportsPage = open("/query", ReportsPage.class);

		// EXPECTED RESULT 1
		// Reports page opens.
		assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");
		try {
			// TEST STEP 2
			// Select test project, some trackers and add field
			// ${referenceFieldName} using "+Add filter"
			// to filter area, set it up with a value
			List<String> projectNames = new ArrayList<String>();
			projectNames.add("test-project-sel-526861927 1");
			List<String> trackerNames = new ArrayList<String>();
			trackerNames.add("New Requirements");
			trackerNames.add("Teams");

			reportsPage.reportEditor.selectProjectsByName(projectNames);
			reportsPage.reportEditor.selectTrackersByName(trackerNames);
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen());
			assertTrue(reportsPage.fieldTree.isSelectedTrackerFoldersDisplayed());
			// use these in pair: add field, then set value
			reportsPage.reportEditor.addReferenceFieldToFilterArea(fieldName);
			reportsPage.reportEditor.setReferenceFieldFilterByChooseItemPopup(trackersToSelect, values);

			// EXPECTED RESULT 2
			// Filter is added and set

			// TEST STEP 3
			// Click on the GO button
			reportsPage.reportEditor.clickOnGoButton();

			// EXPECTED RESULT 3
			// Report is executed, result list is displayed
			assertTrue(reportsPage.resultTable.isResultTableDisplayed());
		} finally {
			// not test step - for automation only
			reportsPage = open("/query/new", ReportsPage.class);
			reportsPage.clickOnLogout();
		}
	}

	@Test(dataProvider = "addFieldsProvider")
	public void testSelectFieldAsGroupBy(String fieldName) {
		// PreAction
		Helper.loginWithSystemAdmin();

		// TEST STEP 1
		// Open Reports page
		ReportsPage reportsPage = open("/query", ReportsPage.class);

		// EXPECTED RESULT 1
		// Reports page opens.
		assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");
		try {
			// TEST STEP 2
			// Select test project, some trackers and select field
			// ${groupbyname} using the "+Add" link in the
			// group by area
			List<String> projectNames = new ArrayList<String>();
			projectNames.add("test-project-sel-526861927 1");
			List<String> trackerNames = new ArrayList<String>();
			trackerNames.add("Bugs");
			trackerNames.add("Releases");
			trackerNames.add("Tasks");
			trackerNames.add("Test Cases");
			trackerNames.add("New Requirements");

			reportsPage.reportEditor.selectProjectsByName(projectNames);
			reportsPage.reportEditor.selectTrackersByName(trackerNames);
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen());
			assertTrue(reportsPage.fieldTree.isSelectedTrackerFoldersDisplayed());
			
			reportsPage.reportEditor.addFieldToGroupByArea(fieldName);

			// EXPECTED RESULT 2
			// Field is dropped to group by area

			// TEST STEP 3
			// Click on the GO button
			reportsPage.reportEditor.clickOnGoButton();

			// EXPECTED RESULT 3
			// Report is executed, result list is grouped by dropped field.

			assertTrue(reportsPage.resultTable.isResultTableGroupedByField(fieldName));
		} finally {
			// not test step - for automation only
			reportsPage = open("/query/new", ReportsPage.class);
			reportsPage.clickOnLogout();
		}
	}

	@Test(dataProvider = "defaultFieldsProvider")
	public void testSelectDefaultFieldAsOrderBy(String fieldName) {
		// PreAction
		Helper.loginWithSystemAdmin();

		// TEST STEP 1
		// Open Reports page
		ReportsPage reportsPage = open("/query", ReportsPage.class);

		// EXPECTED RESULT 1
		// Reports page opens.
		assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");
		try {
			// TEST STEP 2
			// Select test project, some trackers and select field
			// ${defaultFieldName} using "+Add" link in "Order by" area
			List<String> projectNames = new ArrayList<String>();
			projectNames.add("test-project-sel-526861927 1");
			List<String> trackerNames = new ArrayList<String>();
			switch (fieldName) {
			case "Category":
				trackerNames.add("New Requirements");
				trackerNames.add("Requirements");
				break;
			case "Resolution":
				trackerNames.add("New Tasks");
				break;
			case "Severity":
				trackerNames.add("New Tasks");
				trackerNames.add("New Requirements");
				break;
			case "Start Date":
				trackerNames.add("New Tasks");
				break;
			default:
				trackerNames.add("New Requirements");
				trackerNames.add("New Tasks");
				trackerNames.add("New User Stories");
				break;
			}

			reportsPage.reportEditor.selectProjectsByName(projectNames);
			reportsPage.reportEditor.selectTrackersByName(trackerNames);
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen());
			assertTrue(reportsPage.fieldTree.isSelectedTrackerFoldersDisplayed());

			reportsPage.reportEditor.addFieldToOrderByArea(fieldName);

			// EXPECTED RESULT 2
			// Field is selected as "Order by" field

			// TEST STEP 3
			// Click on the GO button
			reportsPage.reportEditor.clickOnGoButton();

			// EXPECTED RESULT 3
			// Report is executed, result list is displayed
			assertTrue(reportsPage.resultTable.isResultTableDisplayed());

			// TEST STEP 4
			// Drop field ${defaultFieldName} to result table
			reportsPage.fieldTree.dragAndDropFieldToResultTable(fieldName);

			// EXPECTED RESULT 4
			// Result list is displayed, and sorted ascending by field.
			assertTrue(reportsPage.resultTable.isResultTableOrderedByField(fieldName, OrderType.Ascending));

			// TEST STEP 5
			// Change sorting order by clicking on button with text ASC in field
			// widget in Order By area.
			assertEquals(reportsPage.reportEditor.getFieldOrderTypeButtonText(fieldName), "ASC");
			reportsPage.reportEditor.clickFieldOrderTypeButton(fieldName);

			// EXPECTED RESULT 5
			// Button text changed to DESC.
			assertEquals(reportsPage.reportEditor.getFieldOrderTypeButtonText(fieldName), "DESC");

			// TEST STEP 6
			// Click on GO button.
			reportsPage.reportEditor.clickOnGoButton();
			// TODO - nothing to sync on yet, table is present. Try "Loading..."
			// overlay
			sleep(1000);
			// EXPECTED RESULT 6
			// Result list is displayed, and sorted descending by sort field.
			assertTrue(reportsPage.resultTable.isResultTableOrderedByField(fieldName, OrderType.Descending));
		} finally {
			reportsPage = open("/query/new", ReportsPage.class);
			reportsPage.clickOnLogout();
		}
	}

	@Test(dataProvider = "referenceFieldsProvider")
	public void testSelectReferenceFieldAsOrderBy(String fieldName) {
		// PreAction
		Helper.loginWithSystemAdmin();

		// TEST STEP 1
		// Open Reports page
		ReportsPage reportsPage = open("/query", ReportsPage.class);

		// EXPECTED RESULT 1
		// Reports page opens.
		assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");
		try {
			// "Children" field can not be dropped to/selected in Order By area
			if (fieldName != "Children") {
				// TEST STEP 2
				// Select test project, some trackers and select field
				// ${referenceFieldName} using "+Add" link in "Order by" area
				List<String> projectNames = new ArrayList<String>();
				projectNames.add("test-project-sel-526861927 1");
				List<String> trackerNames = new ArrayList<String>();
				trackerNames.add("New Requirements");
				trackerNames.add("New Tasks");
				trackerNames.add("New User Stories");

				reportsPage.reportEditor.selectProjectsByName(projectNames);
				reportsPage.reportEditor.selectTrackersByName(trackerNames);
				assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen());
				assertTrue(reportsPage.fieldTree.isSelectedTrackerFoldersDisplayed());
				reportsPage.reportEditor.addFieldToOrderByArea(fieldName);

				// EXPECTED RESULT 2
				// Field is selected as "Order by" field

				// TEST STEP 3
				// Click on the GO button
				reportsPage.reportEditor.clickOnGoButton();

				// EXPECTED RESULT 3
				// Report is executed, result list is displayed
				assertTrue(reportsPage.resultTable.isResultTableDisplayed());

				// TEST STEP 4
				// Drop field ${defaultFieldName} to result table
				reportsPage.fieldTree.dragAndDropFieldToResultTable(fieldName);

				// EXPECTED RESULT 4
				// Result list is displayed, and sorted ascending by field.
				assertTrue(reportsPage.resultTable.isResultTableOrderedByField(fieldName, OrderType.Ascending));

				// TEST STEP 5
				// Change sorting order by clicking on button with text ASC in
				// field
				// widget in Order By area.
				assertEquals(reportsPage.reportEditor.getFieldOrderTypeButtonText(fieldName), "ASC");
				reportsPage.reportEditor.clickFieldOrderTypeButton(fieldName);

				// EXPECTED RESULT 5
				// Button text changed to DESC.
				assertEquals(reportsPage.reportEditor.getFieldOrderTypeButtonText(fieldName), "DESC");

				// TEST STEP 6
				// Click on GO button.
				reportsPage.reportEditor.clickOnGoButton();
				// TODO - nothing to sync on yet, table is present. Try
				// "Loading..." overlay
				sleep(1000);
				// EXPECTED RESULT 6
				// Result list is displayed, and sorted descending by sort
				// field.
				assertTrue(reportsPage.resultTable.isResultTableOrderedByField(fieldName, OrderType.Descending));
			}
		} finally {
			reportsPage = open("/query/new", ReportsPage.class);
			reportsPage.clickOnLogout();
		}
	}

	@Test
	public void testMaximumNumberOfGroupByItems() {
		// PreAction
		Helper.loginWithSystemAdmin();

		// TEST STEP 1
		// Open Reports page
		ReportsPage reportsPage = open("/query", ReportsPage.class);

		// EXPECTED RESULT 1
		// Reports page opens.
		assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");
		try {
			// TEST STEP 2
			// Select test project, some trackers and drop
			// three fields to group by area
			List<String> projectNames = new ArrayList<String>();
			projectNames.add("test-project-sel-526861927 1");
			List<String> trackerNames = new ArrayList<String>();
			trackerNames.add("Bugs");
			trackerNames.add("Releases");
			trackerNames.add("Tasks");
			trackerNames.add("Test Cases");

			reportsPage.reportEditor.selectProjectsByName(projectNames);
			reportsPage.reportEditor.selectTrackersByName(trackerNames);
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen());
			assertTrue(reportsPage.fieldTree.isSelectedTrackerFoldersDisplayed());

			reportsPage.fieldTree.dragAndDropFieldToGroupByArea("Accrued Effort");
			reportsPage.fieldTree.dragAndDropFieldToGroupByArea("Assigned to");
			reportsPage.fieldTree.dragAndDropFieldToGroupByArea("Release");

			// EXPECTED RESULT 2
			// * 3 items appear in the group by area
			// * Link "+Add" disappear
			assertEquals(reportsPage.reportEditor.getFieldCountInGroupByArea(), 3, "Field count in Group By is not 3!");
			assertFalse(reportsPage.reportEditor.isAddLinkVisibleInGroupByArea());

			// TEST STEP 3
			// Verify that you cannot add anymore fields to group by area in any
			// way

			// trying a drop, Add link is not visible
			reportsPage.fieldTree.dragAndDropFieldToGroupByArea("Owner");

			// EXPECTED RESULT 3
			// Cannot add anymore fields to group by area in any way
			assertEquals(reportsPage.reportEditor.getFieldCountInGroupByArea(), 3,
					"Field count in Group By is not 3! D&D-ing a 4th item was possible!");

			// TEST STEP 4
			// Remove fields from group by area
			reportsPage.reportEditor.removeFieldFromGroupByArea("Accrued Effort");
			reportsPage.reportEditor.removeFieldFromGroupByArea("Assigned to");
			reportsPage.reportEditor.removeFieldFromGroupByArea("Release");

			// EXPECTED RESULT 4
			// * Group by area is empty
			// * Link "+Add" reappears in group by area
			assertEquals(reportsPage.reportEditor.getFieldCountInGroupByArea(), 0,
					"Field count in Group By is not 0! Remove was not successful!");
			assertTrue(reportsPage.reportEditor.isAddLinkVisibleInGroupByArea());

			// TEST STEP 5
			// Use the "+Add" link to add fields to the group by area, do it 3
			// times
			reportsPage.reportEditor.addFieldToGroupByArea("Accrued Effort");
			reportsPage.reportEditor.addFieldToGroupByArea("Assigned to");
			reportsPage.reportEditor.addFieldToGroupByArea("Release");

			// EXPECTED RESULT 5
			// * 3 items appear in the group by area
			// * Link "+Add" disappear
			assertEquals(reportsPage.reportEditor.getFieldCountInGroupByArea(), 3, "Field count in Group By is not 3!");
			assertFalse(reportsPage.reportEditor.isAddLinkVisibleInGroupByArea());
		} finally {
			reportsPage = open("/query/new", ReportsPage.class);
			reportsPage.clickOnLogout();
		}
	}

	@Test
	public void testMaximumNumberOfOrderByItems() {
		// PreAction
		Helper.loginWithSystemAdmin();

		// TEST STEP 1
		// Open Reports page
		ReportsPage reportsPage = open("/query", ReportsPage.class);

		// EXPECTED RESULT 1
		// Reports page opens.
		assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");
		try {
			// TEST STEP 2
			// Select test project, some trackers and drop
			// three fields to order by area
			List<String> projectNames = new ArrayList<String>();
			projectNames.add("test-project-sel-526861927 1");
			List<String> trackerNames = new ArrayList<String>();
			trackerNames.add("Bugs");
			trackerNames.add("Releases");
			trackerNames.add("Tasks");
			trackerNames.add("Test Cases");

			reportsPage.reportEditor.selectProjectsByName(projectNames);
			reportsPage.reportEditor.selectTrackersByName(trackerNames);
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen());
			assertTrue(reportsPage.fieldTree.isSelectedTrackerFoldersDisplayed());

			reportsPage.fieldTree.dragAndDropFieldToOrderByArea("Modified at");
			reportsPage.fieldTree.dragAndDropFieldToOrderByArea("Status");
			reportsPage.fieldTree.dragAndDropFieldToOrderByArea("Team");

			// EXPECTED RESULT 2
			// * 3 items appear in the order by area
			// * Link "+Add" disappear
			assertEquals(reportsPage.reportEditor.getFieldCountInOrderByArea(), 3, "Field count in Group By is not 3!");
			assertFalse(reportsPage.reportEditor.isAddLinkVisibleInOrderByArea());

			// TEST STEP 3
			// Verify that you cannot add anymore fields to order by area in any
			// way

			// trying a drop, Add link is not visible
			reportsPage.fieldTree.dragAndDropFieldToOrderByArea("Owner");

			// EXPECTED RESULT 3
			// Cannot add anymore fields to order by area in any way
			assertEquals(reportsPage.reportEditor.getFieldCountInOrderByArea(), 3,
					"Field count in Group By is not 3! D&D-ing a 4th item was possible!");

			// TEST STEP 4
			// Remove fields from order by area
			reportsPage.reportEditor.removeFieldFromOrderByArea("Modified at");
			reportsPage.reportEditor.removeFieldFromOrderByArea("Status");
			reportsPage.reportEditor.removeFieldFromOrderByArea("Team");

			// EXPECTED RESULT 4
			// * Order by area is empty
			// * Link "+Add" reappears in order by area
			assertEquals(reportsPage.reportEditor.getFieldCountInOrderByArea(), 0,
					"Field count in Group By is not 0! Remove was not successful!");
			assertTrue(reportsPage.reportEditor.isAddLinkVisibleInOrderByArea());

			// TEST STEP 5
			// Use the "+Add" link to add fields to the order by area, do it 3
			// times
			reportsPage.reportEditor.addFieldToOrderByArea("Modified at");
			reportsPage.reportEditor.addFieldToOrderByArea("Status");
			reportsPage.reportEditor.addFieldToOrderByArea("Team");

			// EXPECTED RESULT 5
			// * 3 items appear in the order by area
			// * Link "+Add" disappear
			assertEquals(reportsPage.reportEditor.getFieldCountInOrderByArea(), 3, "Field count in Group By is not 3!");
			assertFalse(reportsPage.reportEditor.isAddLinkVisibleInOrderByArea());
		} finally {
			reportsPage = open("/query/new", ReportsPage.class);
			reportsPage.clickOnLogout();
		}
	}

	@Test
	public void testPredefinedReports() {
		// PreAction
		Helper.loginWithSystemAdmin();

		// TEST STEP 1
		// Open Reports page
		ReportsPage reportsPage = open("/query", ReportsPage.class);

		// EXPECTED RESULT 1
		// Reports page opens.
		assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");
		try {
			// TEST STEP 2
			// Open My Reports section
			reportsPage.myReports.clickMyReports();

			// EXPECTED RESULT 2
			// My Reports section appears
			assertTrue(reportsPage.myReports.isMyReportsOpen());

			// TEST STEP 3
			// Click on link "My Unresolved Items"
			reportsPage.myReports.clickMyUnresolvedItems();

			// EXPECTED RESULT 3
			// Report is executed, result appears
			assertTrue(reportsPage.resultTable.isResultTableDisplayed());

			// TEST STEP 4
			// Click on link "Submitted by me"

			reportsPage.myReports.clickMyReports();
			assertTrue(reportsPage.myReports.isMyReportsOpen());
			reportsPage.myReports.clickSubmittedByMe();

			// EXPECTED RESULT 4
			// Report is executed, result appears
			assertTrue(reportsPage.resultTable.isResultTableDisplayed());
		} finally {
			reportsPage.clickOnLogout();
		}
	}

	@Test(dataProvider = "textFieldValuesProvider")
	public void testTextFieldWidget(FilterValue filterValues) {
		// PreAction
		Helper.loginWithSystemAdmin();

		// TEST STEP 1
		// Open Reports page
		ReportsPage reportsPage = open("/query/new", ReportsPage.class);

		// Delete test report if exists
		reportsPage.reportEditor.deleteReportIfExists("testSavedReport001");

		// EXPECTED RESULT 1
		// Reports page opens.
		assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");
		try {
			// TEST STEP 2
			// Compose a report, add a criteria of a text type field like
			// Summary
			List<String> projectNames = new ArrayList<String>();
			projectNames.add("test-project-sel-526861927 1");
			List<String> trackerNames = new ArrayList<String>();
			trackerNames.add("test-tracker-wowf-sel10560");
			trackerNames.add("test-tracker-wwf-sel15699");

			reportsPage.reportEditor.selectProjectsByName(projectNames);
			reportsPage.reportEditor.selectTrackersByName(trackerNames);
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen());
			assertTrue(reportsPage.fieldTree.isSelectedTrackerFoldersDisplayed());
			// use these in pair: drop field, then set value
			reportsPage.fieldTree.dragAndDropFieldToFilterArea("Summary");

			// EXPECTED RESULT 2
			// Criteria appears in criteria area as a line,
			// criteria editor widget appears, the text field in it is focused

			// tested implicitly in next step

			// TEST STEP 3
			// Type a text in the Text field (use ${characters}).
			reportsPage.reportEditor.setDefaultFieldFilterByType(FieldType.Text, filterValues);

			// EXPECTED RESULT 3
			// Text is entered

			// tested implicitly in previous step

			// TEST STEP 4
			// Click outside the criteria editor

			// tested implicitly in previous step

			// EXPECTED RESULT 4
			// Criteria editor disappears, new value goes into criteria line in
			// criteria area

			// tested implicitly in previous step

			// TEST STEP 5
			// Click on the GO button
			reportsPage.reportEditor.clickOnGoButton();

			// EXPECTED RESULT 5
			// Report is executed, no query validation errors, result reflects
			// search criteria
			assertTrue(reportsPage.resultTable.isResultTableDisplayed());

			// TEST STEP 6
			// Save the report.
			reportsPage.reportEditor.saveReportAs("testSavedReport001", null);
			// null values mean "without sharing"

			// EXPECTED RESULT 6
			// Report is saved.
			assertTrue(reportsPage.reportEditor.isSavedReportDisplayed("testSavedReport001"));

			// TEST STEP 7
			// Log out
			// Clear cache
			// Log in again
			reportsPage.clickOnLogout();
			Helper.ClearCache();
			Helper.loginWithSystemAdmin();
			reportsPage = open("/query", ReportsPage.class);

			// EXPECTED RESULT 7
			// Logout and login successful
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");

			// TEST STEP 8
			// Verify that the saved report has the correct criteria

			// because of empty cache we have to find, load and edit saved
			// report to check filters
			reportsPage.actionBar.clickFindReports();
			reportsPage.reportFinder.loadSavedReportFromLastPage("testSavedReport001");
			assertTrue(reportsPage.reportEditor.isSavedReportDisplayed("testSavedReport001"));
			reportsPage.reportEditor.editCurrentlyLoadedSavedReportByContextMenu();
			sleep(10000);
			// EXPECTED RESULT 8
			// Summary field has the predefined text
			assertEquals(reportsPage.reportEditor.getTextFilterValue(),
					((TextFilterValue) filterValues).getFilterValue());

			// Delete report
			reportsPage.reportEditor.deleteCurrentlyLoadedSavedReportByContextMenu();
		} finally {
			reportsPage = open("/query/new", ReportsPage.class);
			reportsPage.clickOnLogout();
		}
	}

	@Test(dataProvider = "numberFieldValuesProvider")
	public void testNumberFieldWidget(FilterValue filterValues) {
		// PreAction
		Helper.loginWithSystemAdmin();

		// TEST STEP 1
		// Open Reports page
		ReportsPage reportsPage = open("/query", ReportsPage.class);
		
		// EXPECTED RESULT 1
		// Reports page opens.
		assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");
		try {
			// TEST STEP 2
			// Compose a report, add a criteria of a number type field like
			// Story Points
			List<String> projectNames = new ArrayList<String>();
			projectNames.add("test-project-sel-526861927 1");
			List<String> trackerNames = new ArrayList<String>();
			trackerNames.add("New Requirements");
			trackerNames.add("New Tasks");
			trackerNames.add("New User Stories");

			reportsPage.reportEditor.selectProjectsByName(projectNames);
			reportsPage.reportEditor.selectTrackersByName(trackerNames);
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen());
			assertTrue(reportsPage.fieldTree.isSelectedTrackerFoldersDisplayed());
			// use these in pair: drop field, then set value
			reportsPage.fieldTree.dragAndDropFieldToFilterArea("Story Points");

			// EXPECTED RESULT 2
			// Criteria appears in criteria area as a line. Criteria editor
			// widget appears
			// *There is a Number label in it
			// *There is a drop down in it with the relations
			// *There is a value selector with increase and decrease buttons

			// tested implicitly in next steps

			// TEST STEP 3
			// Set following values: ${filterValues}
			reportsPage.reportEditor.setDefaultFieldFilterByType(FieldType.Number, filterValues);

			// EXPECTED RESULT 3
			// Filter values are set.

			// tested implicitly in previous step

			// TEST STEP 4
			// Click on the GO button
			reportsPage.reportEditor.clickOnGoButton();

			// EXPECTED RESULT 4
			// Report is executed, no report validation errors, result reflects
			// search criteria
			assertTrue(reportsPage.resultTable.isResultTableDisplayed());

			// TEST STEP 5
			// Save the report.
			reportsPage.reportEditor.saveReportAs("testSavedReport001", null);
			// null values mean "without sharing"

			// EXPECTED RESULT 5
			// Report is saved.
			assertTrue(reportsPage.reportEditor.isSavedReportDisplayed("testSavedReport001"));

			// TEST STEP 6
			// Log out
			// Clear cache
			// Log in again
			reportsPage.clickOnLogout();
			Helper.ClearCache();
			Helper.loginWithSystemAdmin();
			reportsPage = open("/query", ReportsPage.class);

			// EXPECTED RESULT 6
			// Logout and login successful
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");

			// TEST STEP 7
			// Verify that the saved report has the correct criteria

			// because of empty cache we have to find, load and edit saved
			// report to check filters
			reportsPage.actionBar.clickFindReports();
			reportsPage.reportFinder.loadSavedReportFromLastPage("testSavedReport001");
			assertTrue(reportsPage.reportEditor.isSavedReportDisplayed("testSavedReport001"));
			reportsPage.reportEditor.editCurrentlyLoadedSavedReportByContextMenu();

			// EXPECTED RESULT 7
			// Story Points field has the predefined text
			assertEquals(reportsPage.reportEditor.getNumberFilterValue(),
					String.format("%1$s %2$s",
							((NumberFilterValue) filterValues).getOperatorType().name().replace('_', ' '),
							((NumberFilterValue) filterValues).getNumber()));

			// Delete report
			reportsPage.reportEditor.deleteCurrentlyLoadedSavedReportByContextMenu();

		}
		finally {
			reportsPage = open("/query/new", ReportsPage.class);
			reportsPage.clickOnLogout();
		}
	}

	@Test(dataProvider = "choiceFieldValuesProvider")
	public void testChoiceFieldWidget(FilterValue filterValues, String filterText) {
		// PreAction
		Helper.loginWithSystemAdmin();

		// TEST STEP 1
		// Open Reports page
		ReportsPage reportsPage = open("/query/new", ReportsPage.class);

		// Delete test report if exists
		reportsPage.reportEditor.deleteReportIfExists("testSavedReport001");

		// EXPECTED RESULT 1
		// Reports page opens.
		assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");
		try {
			// TEST STEP 2
			// Compose a report, add a criteria of a choice type field like
			// Status
			List<String> projectNames = new ArrayList<String>();
			projectNames.add("test-project-sel-526861927 1");
			List<String> trackerNames = new ArrayList<String>();
			trackerNames.add("Bugs");
			trackerNames.add("Releases");
			trackerNames.add("Tasks");
			trackerNames.add("Test Cases");

			reportsPage.reportEditor.selectProjectsByName(projectNames);
			reportsPage.reportEditor.selectTrackersByName(trackerNames);
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen());
			assertTrue(reportsPage.fieldTree.isSelectedTrackerFoldersDisplayed());
			// use these in pair: drop field, then set value
			reportsPage.fieldTree.dragAndDropFieldToFilterArea("Status");

			// EXPECTED RESULT 2
			// Criteria appears in criteria area as a line. Criteria editor
			// widget appears
			// *It has a Filter field
			// *It has an Any with a check box
			// *For each selected tracker that has the selected field it has a
			// section with all values of selected field with check boxes

			// tested implicitly in next steps

			// TEST STEP 3
			// Set following values: ${filterValues}
			reportsPage.reportEditor.setDefaultFieldFilterByType(FieldType.Choice, filterValues);

			// EXPECTED RESULT 3
			// Filter values are set.

			// tested implicitly in previous step

			// TEST STEP 4
			// Click on the GO button
			reportsPage.reportEditor.clickOnGoButton();

			// EXPECTED RESULT 4
			// Report is executed, no report validation errors, result reflects
			// search criteria
			assertTrue(reportsPage.resultTable.isResultTableDisplayed());

			// TEST STEP 5
			// Save the report.
			reportsPage.reportEditor.saveReportAs("testSavedReport001", null);
			// null values mean "without sharing"

			// EXPECTED RESULT 5
			// Report is saved.
			assertTrue(reportsPage.reportEditor.isSavedReportDisplayed("testSavedReport001"));

			// TEST STEP 6
			// Log out
			// Clear cache
			// Log in again
			reportsPage.clickOnLogout();
			Helper.ClearCache();
			Helper.loginWithSystemAdmin();
			reportsPage = open("/query", ReportsPage.class);

			// EXPECTED RESULT 6
			// Logout and login successful
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");

			// TEST STEP 7
			// Verify that the saved report has the correct criteria

			// because of empty cache we have to find, load and edit saved
			// report to check filters
			reportsPage.actionBar.clickFindReports();
			reportsPage.reportFinder.loadSavedReportFromLastPage("testSavedReport001");
			assertTrue(reportsPage.reportEditor.isSavedReportDisplayed("testSavedReport001"));
			reportsPage.reportEditor.editCurrentlyLoadedSavedReportByContextMenu();

			// EXPECTED RESULT 7
			// Status field has the predefined text
			assertEquals(reportsPage.reportEditor.getChoiceFilterValue(), filterText);

			// Delete report
			reportsPage.reportEditor.deleteCurrentlyLoadedSavedReportByContextMenu();

		} finally {
			reportsPage = open("/query/new", ReportsPage.class);
			reportsPage.clickOnLogout();
		}
	}

	@Test(dataProvider = "memberFieldValuesProvider")
	public void testMemberFieldWidget(FilterValue filterValues, String filterText) {
		// PreAction
		Helper.loginWithSystemAdmin();

		// TEST STEP 1
		// Open Reports page
		ReportsPage reportsPage = open("/query/new", ReportsPage.class);

		// EXPECTED RESULT 1
		// Reports page opens.
		assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");
		try {
			// TEST STEP 2
			// Compose a report, add a criteria of a member type field like
			// Owner
			List<String> projectNames = new ArrayList<String>();
			projectNames.add("test-project-sel-526861927 1");
			List<String> trackerNames = new ArrayList<String>();
			trackerNames.add("Tasks");

			reportsPage.reportEditor.selectProjectsByName(projectNames);
			reportsPage.reportEditor.selectTrackersByName(trackerNames);
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen());
			assertTrue(reportsPage.fieldTree.isSelectedTrackerFoldersDisplayed());
			// use these in pair: drop field, then set value
			reportsPage.fieldTree.dragAndDropFieldToFilterArea("Owner");

			// EXPECTED RESULT 2
			// Filter is added

			// tested implicitly in next step

			// TEST STEP 3
			// Verify that user list contains also the domain name of the user
			// email

			// EXPECTED RESULT 3
			// User list contains the requested data.

			// ensured by test's dataProvider

			// TEST STEP 4
			// Click the check boxes of 2 users and 2 roles
			reportsPage.reportEditor.setDefaultFieldFilterByType(FieldType.Member, filterValues);

			// EXPECTED RESULT 4
			// Check boxes are checked

			// tested implicitly in previous step

			// TEST STEP 5
			// Click outside the owner selector

			// done in previous step

			// EXPECTED RESULT 5
			// Owner selector disappears, new value goes into criteria widget in
			// search field

			// TEST STEP 6
			// Click on the GO button
			reportsPage.reportEditor.clickOnGoButton();

			// EXPECTED RESULT 6
			// Report is executed, no report validation errors, result reflects
			// search criteria
			reportsPage.resultTable.isResultTableDisplayed();

			// TEST STEP 7
			// Save the report.
			reportsPage.reportEditor.saveReportAs("testSavedReport001", null);
			// null values mean "without sharing"

			// EXPECTED RESULT 7
			// Report is saved.
			assertTrue(reportsPage.reportEditor.isSavedReportDisplayed("testSavedReport001"));

			// TEST STEP 8
			// Log out
			// Clear cache
			// Log in again
			reportsPage.clickOnLogout();
			Helper.ClearCache();
			Helper.loginWithSystemAdmin();
			reportsPage = open("/query", ReportsPage.class);

			// EXPECTED RESULT 8
			// Logout and login successful
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");

			// TEST STEP 9
			// Verify that the saved report has the correct criteria

			// because of empty cache we have to find, load and edit saved
			// report to check filters
			reportsPage.actionBar.clickFindReports();
			reportsPage.reportFinder.loadSavedReportFromLastPage("testSavedReport001");
			assertTrue(reportsPage.reportEditor.isSavedReportDisplayed("testSavedReport001"));
			reportsPage.reportEditor.editCurrentlyLoadedSavedReportByContextMenu();

			// EXPECTED RESULT 9
			// Status field has the predefined text
			assertEquals(reportsPage.reportEditor.getMemberFilterValue(), filterText);

			// Delete report
			reportsPage.reportEditor.deleteCurrentlyLoadedSavedReportByContextMenu();
		} finally {
			reportsPage = open("/query/new", ReportsPage.class);
			reportsPage.clickOnLogout();
		}
	}
	
	@Test
	public void testReportSaveAndRecentReports() {
		// PreAction
		Helper.loginWithSystemAdmin();

		// TEST STEP 1
		// Open Reports page
		ReportsPage reportsPage = open("/query/new", ReportsPage.class);

		// EXPECTED RESULT 1
		// Reports page opens.
		assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");
		try {
			// TEST STEP 2
			// Setup a report and save it as Report1
			List<String> projectNames = new ArrayList<String>();
			projectNames.add("test-project-sel-526861927 1");
			List<String> trackerNames = new ArrayList<String>();
			trackerNames.add("Tasks");

			reportsPage.reportEditor.selectProjectsByName(projectNames);
			reportsPage.reportEditor.selectTrackersByName(trackerNames);
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen());
			assertTrue(reportsPage.fieldTree.isSelectedTrackerFoldersDisplayed());
			
			reportsPage.reportEditor.saveReportAs("Report1", null);
			
			// EXPECTED RESULT 2
			// Report1 is saved
			assertTrue(reportsPage.reportEditor.isSavedReportDisplayed("Report1"));
			
			// TEST STEP 
			// Try to create a report with the same name (Click Yes in dialog)
			reportsPage.actionBar.clickNewReport();
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");
			projectNames = new ArrayList<String>();
			projectNames.add("test-project-sel-526861927 1");
			trackerNames = new ArrayList<String>();
			trackerNames.add("Tasks");

			reportsPage.reportEditor.selectProjectsByName(projectNames);
			reportsPage.reportEditor.selectTrackersByName(trackerNames);
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen());
			assertTrue(reportsPage.fieldTree.isSelectedTrackerFoldersDisplayed());
			
			reportsPage.reportEditor.saveReportAs("Report1", null);
			assertTrue(reportsPage.reportEditor.isSavedReportDisplayed("Report1"));
			
			// EXPECTED RESULT 
			// Confirmation box appears to overwrite the existing report
			
			// tested in previous step - overwrite is the default behavior of saveReportAs function
			
			// TEST STEP 
			// Expand the menu of Reports using the triangle icon in it.
			
			// done implicitly in getRecentReports method in next step

			// EXPECTED RESULT 
			// Reports menu opens, Report1 appears in it
			assertTrue(reportsPage.getRecentReports().contains("Report1"));
			
			// TEST STEP 
			// Setup another report and save it as Report2
			reportsPage.actionBar.clickNewReport();
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");
			projectNames = new ArrayList<String>();
			projectNames.add("test-project-sel-526861927 1");
			trackerNames = new ArrayList<String>();
			trackerNames.add("Tasks");

			reportsPage.reportEditor.selectProjectsByName(projectNames);
			reportsPage.reportEditor.selectTrackersByName(trackerNames);
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen());
			assertTrue(reportsPage.fieldTree.isSelectedTrackerFoldersDisplayed());
			
			reportsPage.reportEditor.saveReportAs("Report2", null);

			// EXPECTED RESULT 
			// Report2 is saved
			assertTrue(reportsPage.reportEditor.isSavedReportDisplayed("Report2"));
			
			// TEST STEP 
			// Expand the menu of Reports using the triangle icon in it.
			
			// done implicitly in getRecentReports method in next step

			// EXPECTED RESULT 
			// Reports menu opens, Report2 appears in it
			assertTrue(reportsPage.getRecentReports().contains("Report2"));
			
			// TEST STEP 
			// Setup another report, and save it as Report3
			reportsPage.actionBar.clickNewReport();
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");
			projectNames = new ArrayList<String>();
			projectNames.add("test-project-sel-526861927 1");
			trackerNames = new ArrayList<String>();
			trackerNames.add("Tasks");

			reportsPage.reportEditor.selectProjectsByName(projectNames);
			reportsPage.reportEditor.selectTrackersByName(trackerNames);
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen());
			assertTrue(reportsPage.fieldTree.isSelectedTrackerFoldersDisplayed());
			
			reportsPage.reportEditor.saveReportAs("Report3", null);

			// EXPECTED RESULT 
			// Report3 is saved
			assertTrue(reportsPage.reportEditor.isSavedReportDisplayed("Report3"));
			
			// TEST STEP 
			// Expand the menu of Reports using the triangle icon in it.
			
			// done implicitly in getRecentReports method in next step

			// EXPECTED RESULT 
			// Report menu opens, Report3 appears in it
			assertTrue(reportsPage.getRecentReports().contains("Report3"));
			
			// TEST STEP 
			// Setup another report and save it as Report4
			reportsPage.actionBar.clickNewReport();
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");
			projectNames = new ArrayList<String>();
			projectNames.add("test-project-sel-526861927 1");
			trackerNames = new ArrayList<String>();
			trackerNames.add("Tasks");

			reportsPage.reportEditor.selectProjectsByName(projectNames);
			reportsPage.reportEditor.selectTrackersByName(trackerNames);
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen());
			assertTrue(reportsPage.fieldTree.isSelectedTrackerFoldersDisplayed());
			
			reportsPage.reportEditor.saveReportAs("Report4", null);

			// EXPECTED RESULT 
			// Report4 is saved
			assertTrue(reportsPage.reportEditor.isSavedReportDisplayed("Report4"));
			
			// TEST STEP 
			// Expand the menu of Reports using the triangle icon in it.
			
			// done implicitly in getRecentReports method in next step

			// EXPECTED RESULT 
			// Reports menu opens, Report4 appears in it
			assertTrue(reportsPage.getRecentReports().contains("Report4"));
			
			// TEST STEP 
			// Setup another report, and save it as Report5
			reportsPage.actionBar.clickNewReport();
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");
			projectNames = new ArrayList<String>();
			projectNames.add("test-project-sel-526861927 1");
			trackerNames = new ArrayList<String>();
			trackerNames.add("Tasks");

			reportsPage.reportEditor.selectProjectsByName(projectNames);
			reportsPage.reportEditor.selectTrackersByName(trackerNames);
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen());
			assertTrue(reportsPage.fieldTree.isSelectedTrackerFoldersDisplayed());
			
			reportsPage.reportEditor.saveReportAs("Report5", null);

			// EXPECTED RESULT 
			// Report5 is saved
			assertTrue(reportsPage.reportEditor.isSavedReportDisplayed("Report5"));
			
			// TEST STEP 
			// Expand the menu of Reports using the triangle icon in it.
			
			// done implicitly in getRecentReports method in next step

			// EXPECTED RESULT 
			// Reports menu opens, Report5 appears in it
			assertTrue(reportsPage.getRecentReports().contains("Report5"));
			
			// TEST STEP 
			// Setup another report, and save it as Report6
			reportsPage.actionBar.clickNewReport();
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");
			projectNames = new ArrayList<String>();
			projectNames.add("test-project-sel-526861927 1");
			trackerNames = new ArrayList<String>();
			trackerNames.add("Tasks");

			reportsPage.reportEditor.selectProjectsByName(projectNames);
			reportsPage.reportEditor.selectTrackersByName(trackerNames);
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen());
			assertTrue(reportsPage.fieldTree.isSelectedTrackerFoldersDisplayed());
			
			reportsPage.reportEditor.saveReportAs("Report6", null);

			// EXPECTED RESULT 
			// Report6 is saved
			assertTrue(reportsPage.reportEditor.isSavedReportDisplayed("Report6"));
			
			// TEST STEP 
			// Expand the menu of Reports using the triangle icon in it.
			
			// done implicitly in getRecentReports method in next step

			// EXPECTED RESULT 
			// Reports menu opens, Report6 appears in it, Report1 disappears from it
			List<String> recentReports = reportsPage.getRecentReports();
			assertTrue(recentReports.contains("Report6"));
			assertFalse(recentReports.contains("Report1"));
			
		} finally {
			reportsPage = open("/query/new", ReportsPage.class);
			reportsPage.clickOnLogout();
		}
	}
	
	@Test
	public void testSelectCustomFieldAsFilter() {
		// PreAction
		Helper.loginWithSystemAdmin();

		// TEST STEP 1
		// Open Reports page
		ReportsPage reportsPage = open("/query/new", ReportsPage.class);

		// EXPECTED RESULT 1
		// Reports page opens.
		assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");
		try {
			// TEST STEP 2
			// Select a project and a tracker
			List<String> projectNames = new ArrayList<String>();
			projectNames.add("test-project-sel-526861927 1");
			List<String> trackerNames = new ArrayList<String>();
			trackerNames.add("New Tasks");
			reportsPage.reportEditor.selectProjectsByName(projectNames);
			reportsPage.reportEditor.selectTrackersByName(trackerNames);

			// EXPECTED RESULT 2
			// Project and tracker are selected
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen());
			assertTrue(reportsPage.fieldTree.isSelectedTrackerFoldersDisplayed());
			
			// TEST STEP 3
			// Select a custom field as filter using "+Add filter", set it up with a value
			reportsPage.reportEditor.addCustomFieldToFilterArea(projectNames.get(0), trackerNames.get(0), "Country");
			reportsPage.reportEditor.setDefaultFieldFilterByType(FieldType.Choice,
					filterValues.new ChoiceFilterValue(new String[] { "Hungary" }));

			// EXPECTED RESULT 3
			// Filter is added and set.

			// TEST STEP 4
			// Click on the GO button.
			reportsPage.reportEditor.clickOnGoButton();

			// EXPECTED RESULT 4
			// Report is executed, result list is displayed.
			assertTrue(reportsPage.resultTable.isResultTableDisplayed());
			
		} finally {
			reportsPage = open("/query/new", ReportsPage.class);
			reportsPage.clickOnLogout();
		}
	}
	
	@Test
	public void testReportsLanguage() {
		// PreAction
		Helper.loginWithSystemAdmin();

		// TEST STEP 1
		// Open Reports page
		ReportsPage reportsPage = open("/query/new", ReportsPage.class);

		// EXPECTED RESULT 1
		// Reports page opens.
		assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");
		try {
			// TEST STEP 2
			// Define a report with
			// * several projects
			// * several trackers
			// * all the fields involved
			// * several group by clauses
			// * several ordering clauses
			// Execute it.
			List<String> projectNames = new ArrayList<String>();
			projectNames.add("test-project-sel-526861927 1");
			List<String> trackerNames = new ArrayList<String>();
			trackerNames.add("New Requirements");
			trackerNames.add("New Tasks");
			trackerNames.add("New User Stories");
			// selecting project and trackers
			reportsPage.reportEditor.selectProjectsByName(projectNames);
			reportsPage.reportEditor.selectTrackersByName(trackerNames);
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen());
			assertTrue(reportsPage.fieldTree.isSelectedTrackerFoldersDisplayed());
			// d&d and set fields
			for (Object[] item : defaultFieldTypeNameValue()) {
				reportsPage.fieldTree.dragAndDropFieldToFilterArea((String) item[0]);
				reportsPage.reportEditor.setDefaultFieldFilterByType((FieldType) item[1], (FilterValue) item[2]);
			}
			// group by
			reportsPage.fieldTree.dragAndDropFieldToGroupByArea("Accrued Effort");
			reportsPage.fieldTree.dragAndDropFieldToGroupByArea("Assigned to");
			reportsPage.fieldTree.dragAndDropFieldToGroupByArea("Release");
			// order by
			reportsPage.fieldTree.dragAndDropFieldToOrderByArea("Estimated Effort");
			reportsPage.fieldTree.dragAndDropFieldToOrderByArea("Status");
			reportsPage.fieldTree.dragAndDropFieldToOrderByArea("Team");
			// execute
			reportsPage.reportEditor.clickOnGoButton();
			
			// EXPECTED RESULT 2
			// Report is executed, result list appears (may be empty)
			assertTrue(reportsPage.resultTable.isSuccessfulExecution());
			
			// TEST STEP 3
			// Click on Advanced beside the GO button
			reportsPage.reportEditor.clickOnAdvancedButton();
			
			// EXPECTED RESULT 3
			// Report UI disappears from report field, report text appears
			
			// tested implicitly in previous step
			
			// TEST STEP 4
			// Verify that there are IN clauses everywhere where multiple values are defined,
			// instead of OR clauses
			
			// tested implicitly in next step

			// EXPECTED RESULT 5
			// There are IN clauses everywhere where multiple values are defined,
			// instead of OR clauses
			String cbqlString = reportsPage.reportEditor.getCbqlStringFromAdvancedEditor(); 
			assertTrue(cbqlString.contains("tracker.id IN (554463,570965,554549)"));
			
			// TEST STEP 5
			// Change the report text to get an invalid report, click on GO button to execute it
			reportsPage.reportEditor.setCbqlStringToAdvancedEditor(cbqlString + "invalid");
			reportsPage.reportEditor.clickOnGoButton();
			
			// EXPECTED RESULT 5
			// Validation error message appears
			assertTrue(reportsPage.resultTable.IsExpectedErrorMessageDisplayed());
			// TEST STEP 6
			// Change the report text to get an valid report, click on GO button to execute it
			reportsPage.reportEditor.setCbqlStringToAdvancedEditor(cbqlString);
			reportsPage.reportEditor.clickOnGoButton();
			
			// EXPECTED RESULT 6
			// Report is executed
			assertTrue(reportsPage.resultTable.isSuccessfulExecution());
		} finally {
			reportsPage = open("/query/new", ReportsPage.class);
			reportsPage.clickOnLogout();
		}
	}
	
	@Test
	public void testMySharedReports() {
		// PreAction
		Helper.loginWithSystemAdmin();

		// TEST STEP 1
		// Open Reports page
		ReportsPage reportsPage = open("/query/new", ReportsPage.class);

		// EXPECTED RESULT 1
		// Reports page opens.
		assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");
		try {
			// TEST STEP 
			// Compose a report and Save it, share it with a role of user2
			List<String> projectNames = new ArrayList<String>();
			projectNames.add("test-project-sel-526861927 1");
			List<String> trackerNames = new ArrayList<String>();
			trackerNames.add("New Requirements");
			trackerNames.add("New Tasks");
			trackerNames.add("New User Stories");
			// selecting project and trackers
			reportsPage.reportEditor.selectProjectsByName(projectNames);
			reportsPage.reportEditor.selectTrackersByName(trackerNames);
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen());
			assertTrue(reportsPage.fieldTree.isSelectedTrackerFoldersDisplayed());
			// execute
			reportsPage.reportEditor.clickOnGoButton();
			reportsPage.resultTable.isResultTableDisplayed();
			// save
			HashMap<String, List<String>> projectRolesMap = new HashMap<String, List<String>>();
			List<String> roleNames = new ArrayList<String>();
			roleNames.add("Tester");
			projectRolesMap.put(projectNames.get(0), roleNames);
			reportsPage.reportEditor.saveReportAs("SharedWithTester", projectRolesMap);
			// EXPECTED RESULT 
			// Report is saved
			assertTrue(reportsPage.reportEditor.isSavedReportDisplayed("SharedWithTester"));
			
			// TEST STEP 
			// Login as user2
			reportsPage.clickOnLogout();
			Helper.loginWithUser("Support", "support");

			// EXPECTED RESULT 
			// Login is successful
			
			// tested implicitly in previous step
			
			// TEST STEP 
			// Open Reports page
			reportsPage = open("/query/new", ReportsPage.class);

			// EXPECTED RESULT 
			// Reports page appears
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");
			
			// TEST STEP 
			// Click on Find Reports
			reportsPage.actionBar.clickFindReports();

			// EXPECTED RESULT 
			// Find Reports overlay appears
			
			// tested implicitly in next step
			
			// TEST STEP 
			// Check out My Reports option
			
			// tested implicitly in next step

			// EXPECTED RESULT 
			// Only the Shared Reports are visible.
			
			// tested implicitly in next step
			
			// TEST STEP 
			// Verify that the report defined by user 1 is visible
			
			// tested implicitly in next step

			// EXPECTED RESULT 
			// Report is visible
			
			// tested implicitly in next step
			
			// TEST STEP 
			// Click on the report to see the result list
			reportsPage.reportFinder.loadSharedReportFromFirstPage("SharedWithTester");

			// EXPECTED RESULT 
			// Result list of the report is visible
			assertTrue(reportsPage.reportEditor.isSavedReportDisplayed("SharedWithTester"));
			
		} finally {
			open("/query/new", ReportsPage.class);
			reportsPage.clickOnLogout();
		}
	}
	
	@Test
	public void testFilterInReportFinder() {
		// PreAction
		Helper.loginWithSystemAdmin();

		// TEST STEP 1
		// Open Reports page
		ReportsPage reportsPage = open("/query/new", ReportsPage.class);

		// EXPECTED RESULT 1
		// Reports page opens.
		assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");
		try {
			// TEST STEP 2
			// Click on "Find Reports" link.
			reportsPage.actionBar.clickFindReports();
			
			// EXPECTED RESULT 2
			// "Report Finder" overlay appears, "My Reports" and "Shared Reports" options are checked in by default.
			reportsPage.reportFinder.changeDriverToFrameContent();
			assertTrue(reportsPage.reportFinder.isMyReportsChecked() &&
					reportsPage.reportFinder.isSharedReportsChecked());
			
			// TEST STEP 3
			// Click on "Filter" field and start typing some text.
			String filterValue = "port1";
			reportsPage.reportFinder.sendKeysToFilter(filterValue);
			
			// EXPECTED RESULT 3
			// Reports are filtered based on the typed text.
			assertTrue(reportsPage.reportFinder.isFilteringAppliedToReports(filterValue));
			
			// TEST STEP 4
			// Clear text. Check out the "Shared Reports" option.
			reportsPage.reportFinder.sendKeysToFilter("\b\b\b\b\b");
			reportsPage.reportFinder.clickSharedReportsCheckBox();
			
			// EXPECTED RESULT 4
			// Option is unchecked, only those reports are shown which were created by the user itself.
			String sharedReportName1 = "SharedWithBondRead";
			String sharedReportName2 = "SharedWithBondWrite";
			
			assertFalse(reportsPage.reportFinder.isSharedReportsChecked());
			assertFalse(reportsPage.reportFinder.isReportsListContains(sharedReportName1));
			assertFalse(reportsPage.reportFinder.isReportsListContains(sharedReportName2));
			
			// TEST STEP 5
			// Click on "Filter" field and start to type some text.
			filterValue = "Tester";
			reportsPage.reportFinder.sendKeysToFilter(filterValue);
			
			// EXPECTED RESULT 5
			// My Reports are filtered base on the typed text.
			assertTrue(reportsPage.reportFinder.isFilteringAppliedToReports(filterValue));
			
			// TEST STEP 6
			// Clear text. Check in the "Shared Reports" and check out the "My Reports" options.
			reportsPage.reportFinder.sendKeysToFilter("\b\b\b\b\b\b");
			reportsPage.reportFinder.clickSharedReportsCheckBox();
			reportsPage.reportFinder.clickMyReportsCheckBox();
			
			// EXPECTED RESULT 6
			// Options are set, only the shared reports are visible.
			assertTrue(reportsPage.reportFinder.isSharedReportsChecked());
			assertFalse(reportsPage.reportFinder.isMyReportsChecked());
			assertTrue(reportsPage.reportFinder.isReportsListContains(sharedReportName1));
			assertTrue(reportsPage.reportFinder.isReportsListContains(sharedReportName2));
			
			// TEST STEP 7
			// Click on "Filter" field and start to type some text.
			filterValue = "Read";
			reportsPage.reportFinder.sendKeysToFilter(filterValue);
			
			// EXPECTED RESULT 7
			// Shared Reports are filtered base on the typed text.
			assertTrue(reportsPage.reportFinder.isFilteringAppliedToReports(filterValue));
			
			// TEST STEP 8
			// Clear filter text.
			reportsPage.reportFinder.sendKeysToFilter("\b\b\b\b");
			
			// EXPECTED RESULT 8
			// All of the available reports are visible.
			assertTrue(reportsPage.reportFinder.isReportsListContains(sharedReportName1));
			assertTrue(reportsPage.reportFinder.isReportsListContains(sharedReportName2));
			
			reportsPage.reportFinder.closeFindReports();
		} finally {
			open("/query/new", ReportsPage.class);
			reportsPage.clickOnLogout();
		}
	}
	
	@Test
	public void testMyFavouriteReports() {
		// PreAction
		Helper.loginWithSystemAdmin();

		// TEST STEP 1
		// Open Reports page
		ReportsPage reportsPage = open("/query/new", ReportsPage.class);

		// EXPECTED RESULT 1
		// Reports page opens.
		assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");
		try {
			// TEST STEP 2
			// Click on Find Reports
			reportsPage.actionBar.clickFindReports();

			// EXPECTED RESULT 2
			// Find Reports overlay appears
			
			// tested implicitly in next step
			
			// TEST STEP 3
			// Select an available report.
			reportsPage.reportFinder.loadSavedReportFromFirstPage("Report1");

			// EXPECTED RESULT 3
			// Result page of the report appears.
			
			// tested implicitly in previous step
			
			// TEST STEP 4
			// Click on the gear icon next the name of the report and select "Star it" option.
			reportsPage.reportEditor.clickReportContextMenuItem("Star it");

			// EXPECTED RESULT 4
			// Page reloads, on click on the gear icon menu appears with element: Unstar it.
			assertTrue(reportsPage.reportEditor.getReportContextMenuItems().contains("Unstar it"));
			
			// TEST STEP 5
			// Click on "New Report" link. Reports page appears.
			reportsPage.actionBar.clickNewReport();

			// EXPECTED RESULT 5
			// Page is reloaded
			
			// tested implicitly in previous step
			
			// TEST STEP 6
			// Click on My Reports section
			reportsPage.myReports.clickMyReports();

			// EXPECTED RESULT 6
			// My Reports section appears
			assertTrue(reportsPage.myReports.isMyReportsOpen());
			
			// TEST STEP 7
			// Verify, that starred queries appear in the My Starred Reports section
			assertTrue(reportsPage.myReports.getMyStarredReports().contains("Report1"));

			// EXPECTED RESULT 7
			// Starred queries appear in My Starred Reports section
			
			// tested implicitly in previous step
			
			// TEST STEP 8
			// Open a shared (view only) report.
			reportsPage.actionBar.clickFindReports();
			reportsPage.reportFinder.loadSavedReportFromFirstPage("SharedWithBondRead");

			// EXPECTED RESULT 8
			// Results appear, user see the view result page. Page has the following links:
			// * New report
			// * Find Reports
			// * Export to Office
			// Context menu has the following elements:
			// * Save as...
			// * Star it
			List<String> expectedLinks = new ArrayList<String>();
			expectedLinks.add("New Report");
			expectedLinks.add("Find Reports");
			expectedLinks.add("Send to Review");
			expectedLinks.add("New Job");
			expectedLinks.add("Manage Jobs");
			expectedLinks.add("Export to Office");
			assertTrue(reportsPage.actionBar.getActionBarLinks().containsAll(expectedLinks));
			
			List<String> expectedContextMenuItems = new ArrayList<String>();
			expectedContextMenuItems.add("Save as...");
			expectedContextMenuItems.add("Star it");
			assertTrue(reportsPage.reportEditor.getReportContextMenuItems().containsAll(expectedContextMenuItems));
			
			// TEST STEP 9
			// Open a shared (full access) report.
			reportsPage.actionBar.clickFindReports();
			reportsPage.reportFinder.loadSavedReportFromFirstPage("SharedWithBondWrite");

			// EXPECTED RESULT 9
			// Results appears, user see the view result page. Page has the following links:
			// * Edit
			// * New report
			// * Find Reports
			// * Export to Office
			// Context menu has the following elements:
			// * Edit
			// * Save as...
			// * Delete
			// * Star it
			expectedLinks.clear();
			expectedLinks.add("Edit");
			expectedLinks.add("New Report");
			expectedLinks.add("Find Reports");
			expectedLinks.add("Send to Review");
			expectedLinks.add("New Job");
			expectedLinks.add("Manage Jobs");
			expectedLinks.add("Export to Office");
			assertTrue(reportsPage.actionBar.getActionBarLinks().containsAll(expectedLinks));
			
			expectedContextMenuItems.clear();
			expectedContextMenuItems.add("Edit");
			expectedContextMenuItems.add("Save as...");
			expectedContextMenuItems.add("Delete");
			expectedContextMenuItems.add("Star it");
			assertTrue(reportsPage.reportEditor.getReportContextMenuItems().containsAll(expectedContextMenuItems));
			
			// Not test step, kind of post-action: unstar report for next execution
			reportsPage.actionBar.clickFindReports();
			reportsPage.reportFinder.loadSavedReportFromFirstPage("Report1");
			reportsPage.reportEditor.clickReportContextMenuItem("Unstar it");
		} finally {
			open("/query/new", ReportsPage.class);
			reportsPage.clickOnLogout();
		}
	}
	
	@Test
	public void testReportErrorMessages() {
		// PreAction
		Helper.loginWithSystemAdmin();

		// TEST STEP 1
		// Open Reports page
		ReportsPage reportsPage = open("/query/new", ReportsPage.class);

		// EXPECTED RESULT 1
		// Reports page opens.
		assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");
		try {
			// TEST STEP 2
			// Leave all widgets empty, click on GO button
			reportsPage.reportEditor.clickOnGoButton();

			// EXPECTED RESULT 2
			// Report is not executed, information message is displayed: 
			// Please select some conditions or enter cbQL string!
			assertTrue(reportsPage.resultTable.isInformationMessageDisplayed());
			
			// TEST STEP 3
			// Change to Advanced mode and write a wrong report. Try to execute it.
			String cbqlString = "project.id IN (1) AND tracker.id IN (570965)" +
					" AND ('1.570965.status' = 'In progress' OR '1.570965.status' = 'New')";
			reportsPage.reportEditor.clickOnAdvancedButton();
			reportsPage.reportEditor.setCbqlStringToAdvancedEditor(cbqlString + "invalid");
			reportsPage.reportEditor.clickOnGoButton();
			
			// EXPECTED RESULT 3
			// Change done, report is not executed, an error message appears.
			assertTrue(reportsPage.resultTable.IsExpectedErrorMessageDisplayed());
			
			// TEST STEP 4
			// Fix the report and execute it again.
			reportsPage.reportEditor.setCbqlStringToAdvancedEditor(cbqlString);
			reportsPage.reportEditor.clickOnGoButton();

			// EXPECTED RESULT 4
			// Error message disappears, report executes, results appear.
			assertTrue(reportsPage.resultTable.isResultTableDisplayed());
		} finally {
			open("/query/new", ReportsPage.class);
			reportsPage.clickOnLogout();
		}
	}
	
	@Test
	public void testDeleteReport() {
		// PreAction
		Helper.loginWithSystemAdmin();

		// TEST STEP 1
		// Open Reports page
		ReportsPage reportsPage = open("/query/new", ReportsPage.class);

		// EXPECTED RESULT 1
		// Reports page opens.
		assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");
		try {
			// TEST STEP 2
			// Create a report, run it and save it
			List<String> projectNames = new ArrayList<String>();
			projectNames.add("test-project-sel-526861927 1");
			List<String> trackerNames = new ArrayList<String>();
			trackerNames.add("New User Stories");

			reportsPage.reportEditor.selectProjectsByName(projectNames);
			reportsPage.reportEditor.selectTrackersByName(trackerNames);
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen());
			assertTrue(reportsPage.fieldTree.isSelectedTrackerFoldersDisplayed());
			reportsPage.fieldTree.dragAndDropFieldToFilterArea("Summary");
			reportsPage.reportEditor.setDefaultFieldFilterByType(FieldType.Text, filterValues.new TextFilterValue("%Story 1%"));
			
			reportsPage.reportEditor.clickOnGoButton();
			assertTrue(reportsPage.resultTable.isResultTableDisplayed());

			String reportName = "ReportToDelete";
			reportsPage.reportEditor.saveReportAs(reportName, null);
			// EXPECTED RESULT 2
			// Report is saved
			assertTrue(reportsPage.reportEditor.isSavedReportDisplayed(reportName));
			
			// TEST STEP 3
			// Click on Find Reports
			reportsPage.actionBar.clickFindReports();

			// EXPECTED RESULT 3
			// Report Finder overlay appears
			
			// tested implicitly in next step
			
			// TEST STEP 4
			// Load the newly created report
			reportsPage.reportFinder.loadSavedReportFromFirstPage(reportName);

			// EXPECTED RESULT 4
			// Report is loaded
			assertEquals(reportsPage.reportEditor.getReportName(), reportName);
			
			// TEST STEP 5
			// In the left upper corner, below New Report link, open the context menu of the loaded report
			reportsPage.reportEditor.cancelDeletionOfCurrentlyLoadedSavedReport();

			// EXPECTED RESULT 5
			// Context menu opens
			
			// tested implicitly in previous step
			
			// TEST STEP 6
			// Click on Delete in the context menu
			
			// tested implicitly in previous step

			// EXPECTED RESULT 6
			// Delete report overlay appears
			
			// tested implicitly in previous step
			
			// TEST STEP 7
			// Click on Cancel
			
			// tested implicitly in previous step

			// EXPECTED RESULT 7
			// Delete report overlay disappears, report is not deleted
			assertEquals(reportsPage.reportEditor.getReportName(), reportName);
			
			// TEST STEP 8
			// In the left upper corner, below New Report link, open the context menu of the loaded report
			reportsPage.reportEditor.deleteCurrentlyLoadedSavedReportByContextMenu();

			// EXPECTED RESULT 8
			// Context menu opens
			
			// TEST STEP 9
			// Click on Delete in the context menu
			
			// tested implicitly in previous step

			// EXPECTED RESULT 9
			// Delete report overlay appears
			
			// tested implicitly in previous step
			
			// TEST STEP 10
			// Click on Yes
			
			// tested implicitly in previous step
			
			// EXPECTED RESULT 10
			// * Report is deleted
			// * Criteria stays in the criteria area
			// * Report name changed to New Report
			// * There is no context menu
			assertTrue(reportsPage.reportEditor.getSelectedProjectNames().contains("test-project-sel-526861927 1"));
			assertTrue(reportsPage.reportEditor.getSelectedTrackerNames().contains("New User Stories"));
			assertTrue(reportsPage.reportEditor.getTextFilterValue().equalsIgnoreCase("%Story 1%"));
			assertEquals(reportsPage.reportEditor.getReportName(), "New Report");
			assertFalse(reportsPage.reportEditor.isContextMenuVisible());
		} finally {
			open("/query/new", ReportsPage.class);
			reportsPage.clickOnLogout();
		}
	}
	
	@Test
	public void testModifyReport() {
		// PreAction
		Helper.loginWithSystemAdmin();

		// TEST STEP 1
		// Open Reports page
		ReportsPage reportsPage = open("/query/new", ReportsPage.class);

		// EXPECTED RESULT 1
		// Reports page opens.
		assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");
		try {
			// TEST STEP 2
			// Create a new report, and save it
			List<String> projectNames = new ArrayList<String>();
			projectNames.add("test-project-sel-526861927 1");
			List<String> trackerNames = new ArrayList<String>();
			trackerNames.add("New User Stories");

			reportsPage.reportEditor.selectProjectsByName(projectNames);
			reportsPage.reportEditor.selectTrackersByName(trackerNames);
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen());
			assertTrue(reportsPage.fieldTree.isSelectedTrackerFoldersDisplayed());
			reportsPage.fieldTree.dragAndDropFieldToFilterArea("Summary");
			reportsPage.reportEditor.setDefaultFieldFilterByType(FieldType.Text, filterValues.new TextFilterValue("%Story 1%"));
			
			reportsPage.reportEditor.clickOnGoButton();
			assertTrue(reportsPage.resultTable.isResultTableDisplayed());

			String reportName = "ReportToModify";
			reportsPage.reportEditor.saveReportAs(reportName, null);

			// EXPECTED RESULT 2
			// Report is saved
			assertTrue(reportsPage.reportEditor.isSavedReportDisplayed(reportName));
			
			// TEST STEP 3
			// Open Find Reports overlay and select the newly created report
			reportsPage.actionBar.clickFindReports();
			reportsPage.reportFinder.loadSavedReportFromFirstPage(reportName);

			// EXPECTED RESULT 3
			// Report is loaded, and context menu of report is accessible in the left upper corner, beside the report name
			assertEquals(reportsPage.reportEditor.getReportName(), reportName);
			assertTrue(reportsPage.reportEditor.isContextMenuVisible());
			
			// TEST STEP 4
			// Click on Edit
			reportsPage.actionBar.clickEdit();

			// EXPECTED RESULT 4
			// Report is opened in edit mode
			assertEquals(reportsPage.reportEditor.getReportName(), reportName);
			assertTrue(reportsPage.reportEditor.isContextMenuVisible());
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen());
			
			// TEST STEP 5
			// In the context menu of the report, click on Properties menu item
			reportsPage.reportEditor.clickReportContextMenuItem("Properties");

			// EXPECTED RESULT 5
			// Properties overlay appears
			
			// tested implicitly in next step
			
			// TEST STEP 6
			// In the Properties overlay, modify the name, description, and permissions, save the report
			String reportNameModified = "ReportModified";
			HashMap<String, List<String>> projectRolesMap = new HashMap<String, List<String>>();
			List<String> roleNames = new ArrayList<String>();
			roleNames.add("Tester");
			projectRolesMap.put(projectNames.get(0), roleNames);
			// must handle through ReportPoperties class as overlay is already opened by context menu click
			reportsPage.reportProperties.changeDriverToFrameContent();
			reportsPage.reportProperties.saveReport(reportNameModified, "Some description", projectRolesMap, true);
			// in case of overwrite (forced save), closing the dialog is not necessary, it is done by saving
			
			// EXPECTED RESULT 6
			// * Report is saved and modified
			// * Another report with the original name does not exist
			assertEquals(reportsPage.reportEditor.getReportName(), reportNameModified);
			reportsPage.actionBar.clickFindReports();
			reportsPage.reportFinder.changeDriverToFrameContent();
			assertFalse(reportsPage.reportFinder.isReportsListContains(reportName));
			reportsPage.reportFinder.closeFindReports();
			
			// TEST STEP 7
			// Try to rename the report to an existing name
			reportsPage.reportEditor.clickReportContextMenuItem("Properties");
			String existingReportName = "Report1";
			// must handle through ReportProperties class as we will not overwrite
			// reportEditor.saveAs... method overwrites by default
			reportsPage.reportProperties.changeDriverToFrameContent();
			reportsPage.reportProperties.saveReport(existingReportName, "Some Description", projectRolesMap, false);
			reportsPage.reportProperties.closeReportProperties();
			
			// EXPECTED RESULT 7
			// Confirmation dialog appears about existing name (click cancel)
			
			// tested implicitly in previous step
		} finally {
			open("/query/new", ReportsPage.class);
			reportsPage.clickOnLogout();
		}
	}
	
	@Test
	public void testSpecialCharactersAsAliases() {
		// PreAction
		Helper.loginWithSystemAdmin();

		// TEST STEP 1
		// Open Reports page
		ReportsPage reportsPage = open("/query/new", ReportsPage.class);

		// EXPECTED RESULT 1
		// Reports page opens.
		assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");
		try {
			// TEST STEP 2
			// Compose a report using the graphical widgets that returns results
			List<String> projectNames = new ArrayList<String>();
			projectNames.add("test-project-sel-526861927 1");
			List<String> trackerNames = new ArrayList<String>();
			trackerNames.add("New Tasks");

			reportsPage.reportEditor.selectProjectsByName(projectNames);
			reportsPage.reportEditor.selectTrackersByName(trackerNames);
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen());
			assertTrue(reportsPage.fieldTree.isSelectedTrackerFoldersDisplayed());
			reportsPage.fieldTree.dragAndDropFieldToGroupByArea("Country");
			reportsPage.fieldTree.dragAndDropFieldToGroupByArea("Priority");
			
			reportsPage.reportEditor.clickOnGoButton();
			
			// EXPECTED RESULT 2
			// Report is ready
			assertTrue(reportsPage.resultTable.isResultTableDisplayed());
			assertTrue(reportsPage.resultTable.isResultTableGroupedByField("Country"));
			assertTrue(reportsPage.resultTable.isResultTableGroupedByField("Priority"));
			
			// TEST STEP 3
			// Switch to Advanced mode
			reportsPage.reportEditor.clickOnAdvancedButton();
			
			// EXPECTED RESULT 3
			// Report text area appears
			String cbqlString = reportsPage.reportEditor.getCbqlStringFromAdvancedEditor();
			
			// TEST STEP 4
			// * Replace an alias in the report to a German accented string
			// * Execute report
			cbqlString = cbqlString.replace("Country", "CöüntríßÄä");
			cbqlString = cbqlString.replace("Priority", "PríóritűßÄä");
			reportsPage.reportEditor.setCbqlStringToAdvancedEditor(cbqlString);
			reportsPage.reportEditor.clickOnGoButton();
			
			// EXPECTED RESULT 4
			// Report is executed, same result list appears as before advanced mode
			assertTrue(reportsPage.resultTable.isResultTableDisplayed());
			sleep(500);
			assertTrue(reportsPage.resultTable.isResultTableGroupedByField("CöüntríßÄä"));
			sleep(500);
			assertTrue(reportsPage.resultTable.isResultTableGroupedByField("PríóritűßÄä"));
			
			// TEST STEP 5
			// * Replace an alias in the report to a Chinese accented string
			// * Execute report
			cbqlString = cbqlString.replace("CöüntríßÄä", "話小制文日木話");
			cbqlString = cbqlString.replace("PríóritűßÄä", "百直貢夜注記人");
			reportsPage.reportEditor.setCbqlStringToAdvancedEditor(cbqlString);
			reportsPage.reportEditor.clickOnGoButton();
			
			// EXPECTED RESULT 5
			// Report is executed, same result list appears as before advanced mode
			assertTrue(reportsPage.resultTable.isResultTableDisplayed());
			sleep(500);
			assertTrue(reportsPage.resultTable.isResultTableGroupedByField("話小制文日木話"));
			sleep(500);
			assertTrue(reportsPage.resultTable.isResultTableGroupedByField("百直貢夜注記人"));
		} finally {
			open("/query/new", ReportsPage.class);
			reportsPage.clickOnLogout();
		}
	}
	
	@Test
	public void testHiddenTrackers() {
		// PreAction
		Helper.loginWithSystemAdmin();
		ReportsPage reportsPage = null;
		try {
			// TEST STEP 1
			// Customize a non empty tracker, set Visible property to false in the General tab
			String projectName = "test-project-sel-526861927 1";
			String trackerName = "HiddenRisks";
			ProjectsPage projectsPage = open("/projects/browse.spr", ProjectsPage.class);
			TrackersPage trackersPage = projectsPage.clickOnProject(projectName).clickOnTrackers();
			String trackerId = trackersPage.getTrackerId(trackerName);
			TrackerConfigurationPage trackerConfigPage = trackersPage.navigateToTrackerConfigurationPage(trackerName);
			assertTrue(trackerConfigPage.generalTab.isVisible());
			trackerConfigPage.generalTab.clickVisibleCheckBox();
			
			// EXPECTED RESULT 1
			// Tracker is hidden
			assertFalse(trackerConfigPage.generalTab.isVisible());
			trackerConfigPage.clickSave();
			
			// TEST STEP 2
			// Open Reports page
			reportsPage = trackerConfigPage.clickOnReports();

			// EXPECTED RESULT 2
			// Reports page opens.
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");
			
			// TEST STEP 3
			// Click on Advanced link
			reportsPage.reportEditor.clickOnAdvancedButton();
			
			// EXPECTED RESULT 3
			// Report UI disappears from report field, advanced report text area appears
			
			// tested implicitly in next step
			
			// TEST STEP 4
			// Compose an advanced report like this:
			// (project.id = 123) AND (tracker.id = 456)
			// Replace 123 with the id of test project, replace 456 with the id of hidden tracker
			// Execute the report
			String cbqlString = String.format("(project.id = 1) AND (tracker.id = %1$s)", trackerId);
			reportsPage.reportEditor.setCbqlStringToAdvancedEditor(cbqlString);
			reportsPage.reportEditor.clickOnGoButton();
			
			// EXPECTED RESULT 4
			// No results are returned
			assertTrue(reportsPage.resultTable.isNothingFound());
			
			// TEST STEP 5
			// Customize the hidden tracker again, set Visible property to true and run the same report again
			projectsPage = open("/projects/browse.spr", ProjectsPage.class);
			trackersPage = projectsPage.clickOnProject(projectName).clickOnTrackers();
			trackersPage.navigateToTrackerConfigurationPage(trackerName);
			assertFalse(trackerConfigPage.generalTab.isVisible());
			trackerConfigPage.generalTab.clickVisibleCheckBox();
			assertTrue(trackerConfigPage.generalTab.isVisible());
			trackerConfigPage.clickSave();
			
			reportsPage = trackerConfigPage.clickOnReports();
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");
			reportsPage.reportEditor.clickOnAdvancedButton();
			reportsPage.reportEditor.setCbqlStringToAdvancedEditor(cbqlString);
			reportsPage.reportEditor.clickOnGoButton();
			
			// EXPECTED RESULT 5
			// Result list is displayed
			assertTrue(reportsPage.resultTable.isResultTableDisplayed());
		} finally {
			open("/query/new", ReportsPage.class);
			reportsPage.clickOnLogout();
		}
	}
	
	@Test
	public void testDropSameNameCustomFieldsAsFilters() {
		// PreAction
		Helper.loginWithSystemAdmin();

		// TEST STEP 1
		// Open Reports page
		ReportsPage reportsPage = open("/query/new", ReportsPage.class);

		// EXPECTED RESULT 1
		// Reports page opens.
		assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen(), "Reports page with field tree is not visible!");
		try {
			// TEST STEP 2
			// Select a project, and 2 trackers both having a custom field with same name
			List<String> projectNames = new ArrayList<String>();
			projectNames.add("test-project-sel-526861927 1");
			List<String> trackerNames = new ArrayList<String>();
			trackerNames.add("Tasks");
			trackerNames.add("New Tasks");

			reportsPage.reportEditor.selectProjectsByName(projectNames);
			reportsPage.reportEditor.selectTrackersByName(trackerNames);
			
			// EXPECTED RESULT 2
			// Project selected, trackers are selected, same name field is visible under project names in 2 places in left field tree
			assertTrue(reportsPage.fieldTree.isDefaultFieldsNodeOpen());
			assertTrue(reportsPage.fieldTree.isSelectedTrackerFoldersDisplayed());
			
			// TEST STEP 3
			// 	Drop the first field to the criteria area
			
			// tested implicitly in next step
			
			// EXPECTED RESULT 3
			// Field is dropped, appears as a line in the criteria area (Depending on type, editor overlay can appear)
			
			// tested implicitly in next step
			
			// TEST STEP 4
			// Drop the 2nd field with same name to criteria area
			List<String> valuesToSet = new ArrayList<String>();
			valuesToSet.add("Any");
			valuesToSet.add("Any");
			reportsPage.fieldTree.dragAndDropAllSameNameCustomFieldsToFilters("Country", valuesToSet);

			// EXPECTED RESULT 4
			// Field is dropped, appears as a line in the criteria area (Depending on type, editor overlay can appear)
			
			// tested implicitly in previous step
			
			// TEST STEP 5
			// Click on GO button
			reportsPage.reportEditor.clickOnGoButton();
			
			// EXPECTED RESULT 5
			// Results are displayed
			assertTrue(reportsPage.resultTable.isResultTableDisplayed());
			
		} finally {
			open("/query/new", ReportsPage.class);
			reportsPage.clickOnLogout();
		}
	}
}
