public void AddButton() { // /**********************Buttons********************************************* //Creating ButtonsName String //populating the test data to collections ExcelLib.PopulateInCollection(@"C:\Users\ReshNikesh\Desktop\Study\Testing\SeleniumPrac\FirstProj\TestData1.xlsx", "ButtonsPage"); //Create Webelement for UserInterface //IWebElement Uinterface = GlobalDef.driver.FindElement(By.XPath("/ html / body / div[1] / div / div[2] / ul / li[5] / a")); //Uinterface.Click(); //Page Factory Definition Uinterface.Click(); //Create Webelement for Buttons //IWebElement UButtons = GlobalDef.driver.FindElement(By.XPath("/html/body/div[1]/div/div[2]/ul/li[5]/ul/li[3]/a")); //UButtons.Click(); //PF UButtons.Click(); Thread.Sleep(1000); // Buttons Page Verification //buttonHdr = GlobalDef.driver.FindElement(By.XPath("/html/body/div[2]/h2")); if (buttonHdr.Text == "Buttons") { //Console.WriteLine("Login Successfully, Test Passed"); //Console.WriteLine("Navigate to Buttons Page Successful"); Thread.Sleep(1000); //Create Webelement for AddNewRecord //IWebElement addNew = GlobalDef.driver.FindElement(By.XPath("/html/body/div[2]/div/div[1]/a")); //addNew.Click(); //PF AddNew button Click addNew.Click(); //Create Webelement for Create Option Thread.Sleep(1000); //IWebElement createNew = GlobalDef.driver.FindElement(By.XPath("/html/body/div[6]/div[1]/span")); //Create Page Open verification if (createNew.Text == "Create") { //Create Webelement for ButtonName //IWebElement bName = GlobalDef.driver.FindElement(By.XPath("/html/body/div[6]/div[2]/div/div[2]/input")); //bName.SendKeys(Buttonsname); bName.SendKeys(ExcelLib.ReadData(2, "Buttonsname")); //Create Webelement for ButtonDisplayTitle //IWebElement bDisplayTitle = GlobalDef.driver.FindElement(By.XPath("/html/body/div[6]/div[2]/div/div[4]/input")); // bDisplayTitle.SendKeys(BDispValue); bDisplayTitle.SendKeys(ExcelLib.ReadData(2, "BDispValue")); Thread.Sleep(1000); //Create Webelement for ButtonLogo // GlobalDef.driver.FindElement(By.XPath("/html/body/div[6]/div[2]/div/div[6]/span/span/span[2]/span")).Click(); bLogo.Click(); //Explicit Wait //Thread.Sleep(2000); //driver.FindElement(By.XPath("/html/body/div[7]/div/ul/li[3]/table/tbody/tr/td[1]/div")).Click(); //Implicit Wait //IList<IWebElement> cbl = GlobalDef.driver.FindElements(By.XPath("/html/body/div[7]/div/ul/li")); try { foreach (IWebElement e in cbl) { if (e.Text.Contains(ExcelLib.ReadData(2, "BLogo"))) { e.Click(); break; } } } catch { throw new NoSuchElementException("Can't find camera in Button Logo dropdown"); } //Create Webelement for PreCondition // IWebElement bPreCondition = GlobalDef.driver.FindElement(By.XPath("/html/body/div[6]/div[2]/div/div[8]/input")); // bPreCondition.SendKeys(BPreCValue); bPreCondition.SendKeys(ExcelLib.ReadData(2, "BPreCValue")); //Create Webelement for NextScreen // IWebElement bNextScreen = GlobalDef.driver.FindElement(By.XPath("/html/body/div[6]/div[2]/div/div[10]/span/span/span[2]/span")); //var selectElement = new SelectElement(bNextScreen); //selectElement.SelectByIndex(2); bNextScreen.Click(); Thread.Sleep(1000); //GlobalDef.driver.FindElement(By.XPath(".//*[@id='NEXT_SCREEN_DBID_listbox']/li[6]")).Click(); //PF bNextScreenList.Click(); //Create Webelement for ValueUpdate //IWebElement bValueUpdate = GlobalDef.driver.FindElement(By.XPath("/html/body/div[6]/div[2]/div/div[12]/input")); //bValueUpdate.SendKeys(BValue); bValueUpdate.SendKeys(ExcelLib.ReadData(2, "BValue")); //Create Webelement for NextState //IWebElement bNextState = GlobalDef.driver.FindElement(By.XPath("/html/body/div[6]/div[2]/div/div[14]/span/span/span[1]")); //selectElement = new SelectElement(bNextState); //selectElement.SelectByIndex(2); bNextState.Click(); Thread.Sleep(1000); //GlobalDef.driver.FindElement(By.XPath("//*[@id='NEXT_STATE_DBID_listbox']/li[3]")).Click(); //PF bNextStateList.Click(); //Create Webelement for PendingState //IWebElement bPendingState = GlobalDef.driver.FindElement(By.XPath("/html/body/div[6]/div[2]/div/div[16]/span/span/span[2]")); Thread.Sleep(1000); bPendingState.Click(); Thread.Sleep(2000); //GlobalDef.driver.FindElement(By.XPath("//*[@id='PENDING_STATE_DBID_listbox']/li[3]")).Click(); //PF bPendingStateList.Click(); //Create Webelement for Entity Type //IWebElement bEntityType = GlobalDef.driver.FindElement(By.XPath("html/body/div[6]/div[2]/div/div[18]/span/span/span[2]")); // selectElement = new SelectElement(bEntityType); //selectElement.SelectByIndex(3); Thread.Sleep(1000); bEntityType.Click(); Thread.Sleep(2000); //GlobalDef.driver.FindElement(By.XPath("//*[@id='ETT_DBID_listbox']/li[3]")).Click(); //PF bEntityTypeList.Click(); //Create Webelement for Override theme //IWebElement bOverride = GlobalDef.driver.FindElement(By.XPath("/html/body/div[6]/div[2]/div/div[20]/span[1]/span/span[1]")); bOverride.Click(); Thread.Sleep(2000); //GlobalDef.driver.FindElement(By.XPath("/html/body/div[12]/div/ul/li[1]")).Click(); //PF bOverrideList.Click(); /**************************Web element not identified, NOT WORKING*********************/ ////Create Webelement for BG Color //IWebElement bBGColor = driver.FindElement(By.XPath("/html/body/div[6]/div[2]/div/div[22]/span/span/span[2]/span")); //bBGColor.Click(); //System.Threading.Thread.Sleep(1000); //Actions action = new Actions(driver); //System.Threading.Thread.Sleep(1000); //IWebElement slider = driver.FindElement(By.XPath("/html/body/div[6]/div[2]/div/div[22]/span/span/span[1]")); //System.Threading.Thread.Sleep(1000); //action.MoveToElement(slider, 200, 100).Click().Build().Perform(); // //MoveToElement(slider,100,16).Click().Build().Perform(); //System.Threading.Thread.Sleep(1000); //AddNew Screenshot GlobalDef.SaveScreenshot(GlobalDef.driver, "AddNewPage"); //Create Webelement for Create button //IWebElement CreateButton = GlobalDef.driver.FindElement(By.XPath("/html/body/div[6]/div[2]/div/div[27]/a[1]")); CreateButton.Click(); Thread.Sleep(2500); string ststr1r; IAlert alert = GlobalDef.driver.SwitchTo().Alert(); ststr1r = alert.Text; alert.Accept(); //Verifying the Newly Added record if (buttonHdr.Text == "Buttons" && ststr1r.ToLowerInvariant().Contains("create record is success")) { //Explicit Wait for 2 sec Thread.Sleep(2000); /********PF to be done from here*/ //Filter button using Buttons Name GlobalDef.driver.FindElement(By.XPath(".//*[@id='grid']/div[3]/div/table/thead/tr/th[1]/a[1]/span")).Click(); Thread.Sleep(1000); //Enter the filter value GlobalDef.Textbox(GlobalDef.driver, "XPath", "/html/body/div[5]/form/div[1]/input[1]", ExcelLib.ReadData(2, "Buttonsname")); //Click on Filter button GlobalDef.ActionButton(GlobalDef.driver, "XPath", "html/body/div[5]/form/div[1]/div[2]/button[1]"); //Create Webelement for Edit button in the grid //editbGrid = GlobalDef.driver.FindElement(By.XPath(".//*[@id='grid']/div[4]/table/tbody/tr[1]/td[14]/a[1]")); //Create Webelement for Delete button in the grid //deletebGrid = GlobalDef.driver.FindElement(By.XPath(".//*[@id='grid']/div[4]/table/tbody/tr[1]/td[14]/a[2]")); //Create Webelement for Buttonname in the grid // buttonNameGrid = GlobalDef.driver.FindElement(By.XPath(".//*[@id='grid']/div[4]/table/tbody/tr/td[1]")); if (buttonNameGrid.Text.ToLowerInvariant() == ExcelLib.ReadData(2, "Buttonsname").ToLowerInvariant() && editbGrid.Text == "Edit" && deletebGrid.Text == "Delete") { //AddNew Successful Screenshot GlobalDef.SaveScreenshot(GlobalDef.driver, "AddNewSuccessfulPage"); Console.WriteLine("Navigate to Buttons Page Successful"); Console.WriteLine("Create Page Open successfully"); Console.WriteLine("Created new record successfully"); //Logging Status in Test Report //ButtonsPageTests.test.Log(RelevantCodes.ExtentReports.LogStatus.Pass, "Button Added, Test Passed"); SpecFlow.ButtonsSpecFlowFeatureSteps.test.Log(RelevantCodes.ExtentReports.LogStatus.Pass, "Button Added, Test Passed"); } else { Console.WriteLine("Login Successfully, Test Passed"); Console.WriteLine("Navigate to Buttons Page Successful"); Console.WriteLine("Create Page Open successfully"); Console.WriteLine("Button Name is not correct"); //Logging Status in Test Report // ButtonsPageTests. for NUnit SpecFlow.ButtonsSpecFlowFeatureSteps.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "Button Name not added correctly, Test Failed"); } } else { Console.WriteLine("Login Successfully, Test Passed"); Console.WriteLine("Navigate to Buttons Page Successful"); Console.WriteLine("Create Page Open successfully"); Console.WriteLine("Record not created successfully, Record was already present. Please check"); //Logging Status in Test Report // ButtonsPageTests. for Nunit SpecFlow.ButtonsSpecFlowFeatureSteps.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "Button not created, it was already present, Test Failed"); } } else { Console.WriteLine("Create Page not available, Test Fail"); //Logging Status in Test Report // ButtonsPageTests. SpecFlow.ButtonsSpecFlowFeatureSteps.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "Create Page not available, Test Failed"); } } else { Console.WriteLine("Buttons Page not available, Test Fail"); //Logging Status in Test Report // ButtonsPageTests. SpecFlow.ButtonsSpecFlowFeatureSteps.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "Buttons Page not available, Test Failed"); } }
//POM Def //public IWebElement editbGrid; //public IWebElement deletebGrid; //public IWebElement buttonNameGrid; // public IWebElement buttonHdr; public void AddMultipleButton(int count) { //populating the test data to collections ExcelLib.PopulateInCollection(@"C:\Users\ReshNikesh\Desktop\Study\Testing\SeleniumPrac\FirstProj\TestData1.xlsx", "ButtonsPage"); //Create Webelement for UserInterface //IWebElement Uinterface = GlobalDef.driver.FindElement(By.XPath("/ html / body / div[1] / div / div[2] / ul / li[5] / a")); //Uinterface.Click(); //Adding Multiple Records for (int row = 2; row <= count + 1; row++) { //Page Factory Definition Uinterface.Click(); //Create Webelement for Buttons //IWebElement UButtons = GlobalDef.driver.FindElement(By.XPath("/html/body/div[1]/div/div[2]/ul/li[5]/ul/li[3]/a")); //UButtons.Click(); //PF UButtons.Click(); Thread.Sleep(1000); // Buttons Page Verification //buttonHdr = GlobalDef.driver.FindElement(By.XPath("/html/body/div[2]/h2")); if (buttonHdr.Text == "Buttons") { //Console.WriteLine("Login Successfully, Test Passed"); //Console.WriteLine("Navigate to Buttons Page Successful"); Thread.Sleep(500); //Create Webelement for AddNewRecord //IWebElement addNew = GlobalDef.driver.FindElement(By.XPath("/html/body/div[2]/div/div[1]/a")); //addNew.Click(); //PF AddNew button Click addNew.Click(); //Create Webelement for Create Option Thread.Sleep(1000); //IWebElement ButtonNameLabel = GlobalDef.driver.FindElement(By.XPath("/html/body/div[7]/div[2]")); //IWebElement ButtonNameLabel1 = GlobalDef.driver.FindElement(By.XPath("/html/body/div[6]/div[2]")); //Create Page Open verification if (bName.Displayed || createNew.Text == "Create") { //Create Webelement for ButtonName //IWebElement bName = GlobalDef.driver.FindElement(By.XPath("/html/body/div[6]/div[2]/div/div[2]/input")); //bName.SendKeys(Buttonsname); bName.SendKeys(ExcelLib.ReadData(row, "Buttonsname")); //Create Webelement for ButtonDisplayTitle //IWebElement bDisplayTitle = GlobalDef.driver.FindElement(By.XPath("/html/body/div[6]/div[2]/div/div[4]/input")); // bDisplayTitle.SendKeys(BDispValue); bDisplayTitle.SendKeys(ExcelLib.ReadData(row, "BDispValue")); Thread.Sleep(1000); //Create Webelement for ButtonLogo // GlobalDef.driver.FindElement(By.XPath("/html/body/div[6]/div[2]/div/div[6]/span/span/span[2]/span")).Click(); //PF bLogo.Click(); //Explicit Wait //Thread.Sleep(2000); //driver.FindElement(By.XPath("/html/body/div[7]/div/ul/li[3]/table/tbody/tr/td[1]/div")).Click(); //Implicit Wait //IList<IWebElement> cbl = GlobalDef.driver.FindElements(By.XPath("/html/body/div[7]/div/ul/li")); try { foreach (IWebElement e in cbl) { if ((e.Text.ToLowerInvariant()).Contains(ExcelLib.ReadData(row, "BLogo").ToLowerInvariant())) { e.Click(); break; } } } catch { throw new NoSuchElementException("Can't find camera in Button Logo dropdown"); } //Create Webelement for PreCondition // IWebElement bPreCondition = GlobalDef.driver.FindElement(By.XPath("/html/body/div[6]/div[2]/div/div[8]/input")); // bPreCondition.SendKeys(BPreCValue); bPreCondition.SendKeys(ExcelLib.ReadData(row, "BPreCValue")); //Create Webelement for NextScreen bNextScreen.Click(); IList <IWebElement> nS1 = GlobalDef.driver.FindElements(By.XPath("//*[@id='NEXT_SCREEN_DBID_listbox']/li")); try { foreach (IWebElement e in nS1) { if ((ExcelLib.ReadData(row, "NextScreen").ToLowerInvariant()).Equals(e.Text.ToLowerInvariant())) { e.Click(); break; } } } catch { throw new NoSuchElementException("Can't find" + ExcelLib.ReadData(row, "NextScreen") + " in NextScreen dropdown"); } // IWebElement bNextScreen = GlobalDef.driver.FindElement(By.XPath("/html/body/div[6]/div[2]/div/div[10]/span/span/span[2]/span")); //var selectElement = new SelectElement(bNextScreen); //selectElement.SelectByIndex(2); //PF// bNextScreen.Click(); //PF Thread.Sleep(1000); //GlobalDef.driver.FindElement(By.XPath(".//*[@id='NEXT_SCREEN_DBID_listbox']/li[6]")).Click(); //PF // bNextScreenList.Click(); //Create Webelement for ValueUpdate //IWebElement bValueUpdate = GlobalDef.driver.FindElement(By.XPath("/html/body/div[6]/div[2]/div/div[12]/input")); //bValueUpdate.SendKeys(BValue); bValueUpdate.SendKeys(ExcelLib.ReadData(row, "BValue")); //Create Webelement for NextState bNextState.Click(); IList <IWebElement> nS = GlobalDef.driver.FindElements(By.XPath("//*[@id='NEXT_STATE_DBID_listbox']/li")); try { foreach (IWebElement e in nS) { if ((ExcelLib.ReadData(row, "NextState").ToLowerInvariant()).Equals(e.Text.ToLowerInvariant())) { e.Click(); break; } } } catch { throw new NoSuchElementException("Can't find" + ExcelLib.ReadData(row, "NextState") + " in NextState dropdown"); } //IWebElement bNextState = GlobalDef.driver.FindElement(By.XPath("/html/body/div[6]/div[2]/div/div[14]/span/span/span[1]")); //selectElement = new SelectElement(bNextState); //selectElement.SelectByIndex(2); //PF //bNextState.Click(); Thread.Sleep(1000); //GlobalDef.driver.FindElement(By.XPath("//*[@id='NEXT_STATE_DBID_listbox']/li[3]")).Click(); //PF // bNextStateList.Click(); //Create Webelement for PendingState bPendingState.Click(); IList <IWebElement> pS = GlobalDef.driver.FindElements(By.XPath("//*[@id='PENDING_STATE_DBID_listbox']/li")); try { foreach (IWebElement e in pS) { if ((ExcelLib.ReadData(row, "PendingState").ToLowerInvariant()).Equals(e.Text.ToLowerInvariant())) { e.Click(); break; } } } catch { throw new NoSuchElementException("Can't find" + ExcelLib.ReadData(row, "PendingState") + " in PendingState dropdown"); } //IWebElement bPendingState = GlobalDef.driver.FindElement(By.XPath("/html/body/div[6]/div[2]/div/div[16]/span/span/span[2]")); //Thread.Sleep(1000); //PF //bPendingState.Click(); Thread.Sleep(2000); //GlobalDef.driver.FindElement(By.XPath("//*[@id='PENDING_STATE_DBID_listbox']/li[3]")).Click(); //PF // bPendingStateList.Click(); //Create Webelement for Entity Type GlobalDef.driver.FindElement(By.XPath("/html/body/div[6]/div[2]/div/div[18]/span/span/span[2]/span")).Click(); IList <IWebElement> eT = GlobalDef.driver.FindElements(By.XPath("//*[@id='ETT_DBID_listbox']/li")); try { foreach (IWebElement e in eT) { if ((ExcelLib.ReadData(row, "Entity Type").ToLowerInvariant()).Equals(e.Text.ToLowerInvariant())) { e.Click(); break; } } } catch { throw new NoSuchElementException("Can't find" + ExcelLib.ReadData(row, "Entity Type") + " in Entity type dropdown"); } Thread.Sleep(1000); //bEntityType.Click(); //Thread.Sleep(2000); //GlobalDef.driver.FindElement(By.XPath("//*[@id='ETT_DBID_listbox']/li[3]")).Click(); //PF //bEntityTypeList.Click(); //Create Webelement for Override theme //IWebElement bOverride = GlobalDef.driver.FindElement(By.XPath("/html/body/div[6]/div[2]/div/div[20]/span[1]/span/span[1]")); //PF // bOverride.Click(); IList <IWebElement> oD = GlobalDef.driver.FindElements(By.XPath("/html/body/div[12]/div/ul/li")); try { foreach (IWebElement e in oD) { if ((ExcelLib.ReadData(row, "Override").ToLowerInvariant()).Equals(e.Text.ToLowerInvariant())) { e.Click(); break; } } } catch { throw new NoSuchElementException("Can't find" + ExcelLib.ReadData(row, "Override") + " in Override dropdown"); } // Thread.Sleep(2000); //GlobalDef.driver.FindElement(By.XPath("/html/body/div[12]/div/ul/li[1]")).Click(); //PF // bOverrideList.Click(); //Create Webelement for Create button //IWebElement CreateButton = GlobalDef.driver.FindElement(By.XPath("/html/body/div[6]/div[2]/div/div[27]/a[1]")); CreateButton.Click(); Thread.Sleep(2500); string ststr1r; IAlert alert = GlobalDef.driver.SwitchTo().Alert(); ststr1r = alert.Text; alert.Accept(); //Verifying the Newly Added record if (buttonHdr.Text == "Buttons" && ststr1r.ToLowerInvariant().Contains("create record is success")) { //Explicit Wait for 2 sec Thread.Sleep(2000); //Filter button using Buttons Name GlobalDef.driver.FindElement(By.XPath(".//*[@id='grid']/div[3]/div/table/thead/tr/th[1]/a[1]/span")).Click(); Thread.Sleep(1000); //Enter the filter value GlobalDef.Textbox(GlobalDef.driver, "XPath", "/html/body/div[5]/form/div[1]/input[1]", ExcelLib.ReadData(row, "Buttonsname")); //Click on Filter button GlobalDef.ActionButton(GlobalDef.driver, "XPath", "html/body/div[5]/form/div[1]/div[2]/button[1]"); GlobalDef.driver.FindElement(By.XPath("//*[@id='grid']/div[5]/a[5]")).Click(); //string test = ExcelLib.ReadData(row, "Buttonsname"); //string bg = GlobalDef.driver.FindElement(By.XPath("//*[@id='grid']/div[4]/table/tbody/tr/td[1]")).Text; ////buttonNameGrid.Text.Contains(test) if (buttonNameGrid.Text.Equals(ExcelLib.ReadData(row, "Buttonsname"))) { //AddNew Successful Screenshot GlobalDef.SaveScreenshot(GlobalDef.driver, ExcelLib.ReadData(row, "Buttonsname") + " AddNewSuccessfulPage"); Console.WriteLine("Created {0} Button record successfully", ExcelLib.ReadData(row, "Buttonsname")); } else { Console.WriteLine("Login Successfully, Test Passed"); Console.WriteLine("Navigate to Buttons Page Successful"); Console.WriteLine("Create Page Open successfully"); Console.WriteLine("Button Name {0} is not saved correctly", ExcelLib.ReadData(row, "Buttonsname")); } } else { Console.WriteLine("Login Successfully, Test Passed"); Console.WriteLine("Navigate to Buttons Page Successful"); Console.WriteLine("Create Page Open successfully"); Console.WriteLine("Record not created successfully, Record was already present. Please check"); } } else { Console.WriteLine("Create Page not available, Test Fail"); } } else { Console.WriteLine("Buttons Page not available, Test Fail"); } } }