package test_classes; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; import org.testng.ITestResult; import org.testng.SkipException; import org.testng.annotations.AfterClass; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeClass; import org.testng.annotations.Optional; import org.testng.annotations.Parameters; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import abstract_classes.BaseTest; import qsf_page_object_pattern.BackEnd.BackEnd_SettingsPage; import tools.DynamicDataProvider; public class be_settings_test extends BaseTest{ public Map testResults = new HashMap(); @DataProvider(name = "Settings") public Object[][] createData5() { DynamicDataProvider dp = new DynamicDataProvider("BE_Settings.json"); return dp.GenerateFullEditCheck(); } @DataProvider(name = "ActionLog") public Object[][] createData6() { DynamicDataProvider dp = new DynamicDataProvider("BE_Settings_ActionLog.json"); return dp.GenerateFullEditCheck(); } @DataProvider(name = "OrderTemplates") public Object[][] createData2() { DynamicDataProvider dp = new DynamicDataProvider("BE_Settings_OrderTemplates.json"); return dp.GenerateFullEditCheck(); } @DataProvider(name = "OrderSettings") public Object[][] createData1() { DynamicDataProvider dp = new DynamicDataProvider("BE_Settings_OrderSettings.json"); return dp.GenerateFullEditCheck(); } @DataProvider(name = "EmailTemplates") public Object[][] createData3() { DynamicDataProvider dp = new DynamicDataProvider("BE_Settings_EmailTemplates.json"); return dp.GenerateFullEditCheck(); } @DataProvider(name = "AccountEmailTemplates") public Object[][] createData4() { DynamicDataProvider dp = new DynamicDataProvider("BE_Settings_AccountEmailTemplates.json"); return dp.GenerateFullEditCheck(); } @Parameters({"browser"}) @BeforeClass public void SetUp(@Optional("Firefox") String browser){ SetDriver(browser); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.manage().window().maximize(); loginToAdmin(); } @Test(dataProvider = "Settings", priority=1, enabled=true, description = "") public void TestIncorrectSettings(Map> fieldsData, Map> expectedErrors) throws InterruptedException{ if(!testResults.containsKey("TestIncorrectSettings")||testResults.get("TestIncorrectSettings")){ driver.get(settings.http + settings.adminUrl + "settings"); BackEnd_SettingsPage be_settingsPage = new BackEnd_SettingsPage(driver); be_settingsPage.expandFckEditorFields(); be_settingsPage = be_settingsPage.submitIncorrectData(fieldsData); Map>realFormErrors = be_settingsPage.getFieldsAlerts(); compareFormErrors(realFormErrors, expectedErrors); be_settingsPage.clickCancel(); } else{ throw new SkipException("Something wrong with form. Test was skiped to avoid damage."); } } @Test(dataProvider = "EmailTemplates", priority=2, enabled=true, description = "") public void TestIncorrectEmailTemplates(Map> fieldsData, Map> expectedErrors) throws InterruptedException{ if(!testResults.containsKey("TestIncorrectEmailTemplates")||testResults.get("TestIncorrectEmailTemplates")){ driver.get(settings.http + settings.adminUrl + "settings"); BackEnd_SettingsPage be_settingsPage = new BackEnd_SettingsPage(driver); be_settingsPage = be_settingsPage.openTab("Email Templates"); be_settingsPage.expandFckEditorFields(); be_settingsPage = be_settingsPage.submitIncorrectData(fieldsData); Map>realFormErrors = be_settingsPage.getFieldsAlerts(); compareFormErrors(realFormErrors, expectedErrors); be_settingsPage.clickCancel(); } else{ throw new SkipException("Something wrong with form. Test was skiped to avoid damage."); } } @Test(dataProvider = "AccountEmailTemplates", priority=3, enabled=true, description = "") public void TestIncorrectAccountEmailTemplates(Map> fieldsData, Map> expectedErrors) throws InterruptedException{ if(!testResults.containsKey("TestIncorrectAccountEmailTemplates")||testResults.get("TestIncorrectAccountEmailTemplates")){ driver.get(settings.http + settings.adminUrl + "settings"); BackEnd_SettingsPage be_settingsPage = new BackEnd_SettingsPage(driver); be_settingsPage = be_settingsPage.openTab("Account Email Templates"); be_settingsPage.expandFckEditorFields(); be_settingsPage = be_settingsPage.submitIncorrectData(fieldsData); Map>realFormErrors = be_settingsPage.getFieldsAlerts(); compareFormErrors(realFormErrors, expectedErrors); be_settingsPage.clickCancel(); } else{ throw new SkipException("Something wrong with form. Test was skiped to avoid damage."); } } @Test(dataProvider = "OrderSettings", priority=3, enabled=true, description = "") public void TestIncorrectOrderSettings(Map> fieldsData, Map> expectedErrors) throws InterruptedException{ if(!testResults.containsKey("TestIncorrectOrderSettings")||testResults.get("TestIncorrectOrderSettings")){ driver.get(settings.http + settings.adminUrl + "settings"); BackEnd_SettingsPage be_settingsPage = new BackEnd_SettingsPage(driver); be_settingsPage = be_settingsPage.openTab("Order Settings"); be_settingsPage.expandFckEditorFields(); be_settingsPage = be_settingsPage.submitIncorrectData(fieldsData); Map>realFormErrors = be_settingsPage.getFieldsAlerts(); compareFormErrors(realFormErrors, expectedErrors); be_settingsPage.clickCancel(); } else{ throw new SkipException("Something wrong with form. Test was skiped to avoid damage."); } } @Test(dataProvider = "OrderTemplates", priority=3, enabled=true, description = "") public void TestIncorrectOrderTemplates(Map> fieldsData, Map> expectedErrors) throws InterruptedException{ if(!testResults.containsKey("TestIncorrectOrderTemplates")||testResults.get("TestIncorrectOrderTemplates")){ driver.get(settings.http + settings.adminUrl + "settings"); BackEnd_SettingsPage be_settingsPage = new BackEnd_SettingsPage(driver); be_settingsPage = be_settingsPage.openTab("Order Templates"); be_settingsPage.expandFckEditorFields(); be_settingsPage = be_settingsPage.submitIncorrectData(fieldsData); Map>realFormErrors = be_settingsPage.getFieldsAlerts(); compareFormErrors(realFormErrors, expectedErrors); be_settingsPage.clickCancel(); } else{ throw new SkipException("Something wrong with form. Test was skiped to avoid damage."); } } @Test(dataProvider = "ActionLog", priority=3, enabled=true, description = "") public void TestIncorrectActionLog(Map> fieldsData, Map> expectedErrors) throws InterruptedException{ if(!testResults.containsKey("TestIncorrectActionLog")||testResults.get("TestIncorrectActionLog")){ driver.get(settings.http + settings.adminUrl + "settings"); BackEnd_SettingsPage be_settingsPage = new BackEnd_SettingsPage(driver); be_settingsPage = be_settingsPage.openTab("Action Log"); be_settingsPage.expandFckEditorFields(); be_settingsPage = be_settingsPage.submitIncorrectData(fieldsData); Map>realFormErrors = be_settingsPage.getFieldsAlerts(); compareFormErrors(realFormErrors, expectedErrors); be_settingsPage.clickCancel(); } else{ throw new SkipException("Something wrong with form. Test was skiped to avoid damage."); } } @AfterMethod public void afterTest(ITestResult result){ if(!result.isSuccess()){ System.out.println(); } testResults.put(result.getName(), result.isSuccess()); } @AfterClass public void tearDown(){ driver.quit(); //driver.close(); } }