|
| 1 | +package com.ericsson.ei.frontend; |
| 2 | + |
| 3 | +import static org.junit.Assert.assertEquals; |
| 4 | + |
| 5 | +import java.io.File; |
| 6 | +import java.nio.file.Files; |
| 7 | +import java.nio.file.Paths; |
| 8 | +import java.util.concurrent.TimeUnit; |
| 9 | + |
| 10 | +import org.junit.Test; |
| 11 | +import org.openqa.selenium.support.ui.WebDriverWait; |
| 12 | + |
| 13 | +import com.ericsson.ei.config.SeleniumConfig; |
| 14 | +import com.ericsson.ei.frontend.pageobjects.IndexPage; |
| 15 | +import com.ericsson.ei.frontend.pageobjects.TestRulesPage; |
| 16 | + |
| 17 | +public class TestRulesFunctionality extends SeleniumBaseClass { |
| 18 | + |
| 19 | + private static final String DOWNLOADEDRULESTEMPLATEFILEPATH = String.join( |
| 20 | + File.separator, SeleniumConfig.getTempDownloadDirectory().getPath(), "rulesTemplate.json"); |
| 21 | + |
| 22 | + private static final String RULESTEMPLATEFILEPATH = String.join( |
| 23 | + File.separator, "src", "functionaltest", "resources", "responses", "RulesTemplateObject.json"); |
| 24 | + private static final String DOWNLOADEDRULESFILEPATH = String.join(File.separator, SeleniumConfig.getTempDownloadDirectory().getPath(), "rules.json"); |
| 25 | + |
| 26 | + private static final String DOWNLOADEDEVENTSTEMPLATEFILEPATH = String.join( |
| 27 | + File.separator, SeleniumConfig.getTempDownloadDirectory().getPath(), "eventsTemplate.json"); |
| 28 | + private static final String EVENTSTEMPLATEFILEPATH = String.join( |
| 29 | + File.separator, "src", "functionaltest", "resources", "responses", "EventsTemplateObject.json"); |
| 30 | + |
| 31 | + private static final String AGGREGATEDOBJECTFILEPATH = String.join( |
| 32 | + File.separator, "src", "functionaltest", "resources", "responses", "AggregatedObjectResponse.json"); |
| 33 | + @Test |
| 34 | + public void testJourneyToFindAggregatedObjectButton() throws Exception { |
| 35 | + // Load index page and wait for it to load |
| 36 | + IndexPage indexPageObject = new IndexPage(mockedHttpClient, driver, baseUrl); |
| 37 | + indexPageObject.loadPage(); |
| 38 | + TimeUnit.SECONDS.sleep(3); |
| 39 | + |
| 40 | + // Verify that we can navigate to test rules page |
| 41 | + TestRulesPage testRulesPage = indexPageObject.clickTestRulesPage(); |
| 42 | + new WebDriverWait(driver, 10).until((webdriver) -> testRulesPage.presenceOfTestRulesHeader()); |
| 43 | + |
| 44 | + // Verify that "download rules template" button works |
| 45 | + String mockedResponse = this.getJSONStringFromFile(RULESTEMPLATEFILEPATH); |
| 46 | + new WebDriverWait(driver, 10).until((webdriver) -> testRulesPage.presenceOfClickDownloadRulesTemplateButton()); |
| 47 | + testRulesPage.clickDownloadRulesTemplate(mockedResponse); |
| 48 | + new WebDriverWait(driver, 10).until((webdriver) -> Files.exists(Paths.get(DOWNLOADEDRULESTEMPLATEFILEPATH))); |
| 49 | + String downloadedRulesTemplate = this.getJSONStringFromFile(DOWNLOADEDRULESTEMPLATEFILEPATH); |
| 50 | + assertEquals(mockedResponse, downloadedRulesTemplate); |
| 51 | + |
| 52 | + // Verify that uploading the downloaded template file works. |
| 53 | + testRulesPage.uploadRulesTemplate(DOWNLOADEDRULESTEMPLATEFILEPATH); |
| 54 | + new WebDriverWait(driver, 10).until((webdriver) -> testRulesPage.presenceOfRuleNumber(2)); |
| 55 | + String firstRule = testRulesPage.getFirstRuleText(); |
| 56 | + assertEquals(true, downloadedRulesTemplate.contains(firstRule)); |
| 57 | + |
| 58 | + // Verify that it is possible to download rules |
| 59 | + testRulesPage.clickDownloadRulesButton(); |
| 60 | + new WebDriverWait(driver, 10).until((webdriver) -> Files.exists(Paths.get(DOWNLOADEDRULESFILEPATH))); |
| 61 | + String downloadedRules = this.getJSONStringFromFile(DOWNLOADEDRULESFILEPATH); |
| 62 | + assertEquals(downloadedRulesTemplate, downloadedRules); |
| 63 | + |
| 64 | + // Verify that add rule button works |
| 65 | + testRulesPage.clickAddRuleButton(); |
| 66 | + new WebDriverWait(driver, 10).until((webdriver) -> testRulesPage.presenceOfRuleNumber(3)); |
| 67 | + |
| 68 | + // Verify that removing a rule works |
| 69 | + testRulesPage.clickRemoveRuleNumber(3); |
| 70 | + new WebDriverWait(driver, 10).until((webdriver) -> testRulesPage.presenceOfRuleNumber(3) == false); |
| 71 | + |
| 72 | + // Verify that "download events template" button works |
| 73 | + String downloadEventsTemplateMockedResponse = this.getJSONStringFromFile(EVENTSTEMPLATEFILEPATH); |
| 74 | + testRulesPage.clickDownloadEventsTemplate(downloadEventsTemplateMockedResponse); |
| 75 | + new WebDriverWait(driver, 10).until((webdriver) -> Files.exists(Paths.get(DOWNLOADEDEVENTSTEMPLATEFILEPATH))); |
| 76 | + String downloadedEventsTemplate = this.getJSONStringFromFile(DOWNLOADEDEVENTSTEMPLATEFILEPATH); |
| 77 | + assertEquals(downloadEventsTemplateMockedResponse, downloadedEventsTemplate); |
| 78 | + |
| 79 | + // Verify that uploading the downloaded template file works. |
| 80 | + testRulesPage.uploadEventsTemplate(DOWNLOADEDEVENTSTEMPLATEFILEPATH); |
| 81 | + new WebDriverWait(driver, 10).until((webdriver) -> testRulesPage.presenceOfEventNumber(2)); |
| 82 | + String firstEvent = testRulesPage.getFirstEventText(); |
| 83 | + assertEquals(true, downloadedEventsTemplate.contains(firstEvent)); |
| 84 | + |
| 85 | + // Verify that add rule button works |
| 86 | + testRulesPage.clickAddEventButton(); |
| 87 | + new WebDriverWait(driver, 10).until((webdriver) -> testRulesPage.presenceOfEventNumber(3)); |
| 88 | + |
| 89 | + // Verify that removing a rule works |
| 90 | + testRulesPage.clickRemoveEventNumber(3); |
| 91 | + new WebDriverWait(driver, 10).until((webdriver) -> testRulesPage.presenceOfEventNumber(3) == false); |
| 92 | + |
| 93 | + // Verify that find aggregated object button works |
| 94 | + String findAggregatedObjectResponse = this.getJSONStringFromFile(AGGREGATEDOBJECTFILEPATH); |
| 95 | + testRulesPage.clickFindAggregatedObject(findAggregatedObjectResponse); |
| 96 | + assertEquals(findAggregatedObjectResponse, testRulesPage.getAggregatedResultData()); |
| 97 | + } |
| 98 | +} |
0 commit comments