SHASHANK Balaganchi Ответов: 2

Поле ввода не отображается


Поле ввода не отображается, и я перепробовал все варианты. Даже после добавления необходимых рефренов он не отображается

Что я уже пробовал:

using Microsoft.Office.Interop.Excel;
using Microsoft.VisualBasic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
using System;
using System.Drawing.Imaging;
using System.IO;
using System.Threading;
using System.Windows.Forms;
namespace Selenium
{
    [TestClass]
    public class Assignment
    {
        public static String baseURL = "http://10.207.182.108:81/opencart/";
        public IWebDriver driver;
        Workbook excelworkbook;
        Microsoft.Office.Interop.Excel.Application excelApp;
        Sheets excelsheets;
        Worksheet excelWorksheet;

        [TestMethod]
        public void TC_01_Registration()
        {

            IWebDriver driver = new ChromeDriver();
            //Launch Browser
            driver.Manage().Window.Maximize();
            driver.Navigate().GoToUrl(baseURL);
            //Click on Create an Account
            driver.FindElement(By.LinkText("create an account")).Click();
            string workbookPath = "C:\\Users\\Admin\\Documents\\Visual Studio 2015\\Projects\\UnitTestProject1\\CreateAccount.xlsx";
            excelApp = new Microsoft.Office.Interop.Excel.Application();
            excelworkbook = excelApp.Workbooks.Add(workbookPath);
            excelsheets = excelworkbook.Sheets;
            excelWorksheet = excelsheets.get_Item("CreateAccount");
            Range frstnameBinder = excelWorksheet.get_Range("A2", "A2");
            string frstname = frstnameBinder.Value.ToString();
            driver.FindElement(By.Name("firstname")).SendKeys(frstname);
            Range lastnameBinder = excelWorksheet.get_Range("B2", "B2");
            string lstname = lastnameBinder.Value.ToString();
            driver.FindElement(By.Name("lastname")).SendKeys(lstname);
            Range emailBinder = excelWorksheet.get_Range("C2", "C2");
            string mail = emailBinder.Value.ToString();
            driver.FindElement(By.Name("email")).SendKeys(mail);
            Range teleBinder = excelWorksheet.get_Range("D2", "D2");
            string phnum = teleBinder.Value.ToString();
            driver.FindElement(By.Name("telephone")).SendKeys(phnum);
            Range addBinder = excelWorksheet.get_Range("E2", "E2");
            string address = addBinder.Value.ToString();
            driver.FindElement(By.Name("address_1")).SendKeys(address);
            Range cityBinder = excelWorksheet.get_Range("F2", "F2");
            string cty = cityBinder.Value.ToString();
            driver.FindElement(By.Name("city")).SendKeys(cty);
            Range postBinder = excelWorksheet.get_Range("G2", "G2");
            string zipcode = postBinder.Value.ToString();
            driver.FindElement(By.Name("postcode")).SendKeys(zipcode);
            var dropdown = new SelectElement(driver.FindElement(By.Name("country_id")));
            Range countryBinder = excelWorksheet.get_Range("H2", "H2");
            string country = countryBinder.Value.ToString();
            dropdown.SelectByText(country);
            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(15));
            var dropdown1 = new SelectElement(driver.FindElement(By.Name("zone_id")));
            Range zoneBinder = excelWorksheet.get_Range("I2", "I2");
            string zone = zoneBinder.Value.ToString();
            dropdown1.SelectByText(zone);
            Range passBinder = excelWorksheet.get_Range("J2", "J2");
            string passwrd = passBinder.Value.ToString();
            driver.FindElement(By.Name("password")).SendKeys(passwrd);
            driver.FindElement(By.Name("confirm")).SendKeys(passwrd);
            //checkpoint to check whether checkbox is checked or not
            if (!driver.FindElement(By.Name("agree")).Selected)
            {
                driver.FindElement(By.Name("agree")).Click();
                driver.FindElement(By.ClassName("button")).Click();
            }
            string expectedvalue = "Your Account Has Been Created!";
            Assert.AreEqual("Your Account Has Been Created!", expectedvalue);
            driver.FindElement(By.LinkText("contact us")).Click();
            string name = driver.FindElement(By.Name("name")).GetAttribute("value");
            Assert.AreEqual(name, frstname);
            string emails = driver.FindElement(By.Name("email")).GetAttribute("value");
            Assert.AreEqual(emails, mail);
            driver.FindElement(By.Name("enquiry")).SendKeys("This is to change of Address/Phone Number");
            // string t = Prompt("Enter the Captcha image Text");
            Thread.Sleep(9000);
            string text = Interaction.InputBox("Enter the Captcha Image Text","prompt", "default", -1, -1);
            Thread.Sleep(9000);
            driver.FindElement(By.Name("captcha")).SendKeys(text);
            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(45));
            driver.FindElement(By.ClassName("button")).Click();
            string success = "Your enquiry has been successfully sent to the store owner!";
            Assert.AreEqual("Your enquiry has been successfully sent to the store owner!", success);
            driver.FindElement(By.LinkText("Continue")).Click();
            driver.FindElement(By.XPath("//div[@id='slideshow0']/a")).Click();
            driver.FindElement(By.XPath("//div[@id='tabs']/a[2]")).Click();
            excelworkbook.Close();
            excelApp.Quit();
            string reviewworkbookpath = "C:\\Users\\Admin\\Documents\\Visual Studio 2015\\Projects\\UnitTestProject1\\Review.xlsx";
            excelApp = new Microsoft.Office.Interop.Excel.Application();
            excelworkbook = excelApp.Workbooks.Add(reviewworkbookpath);
            excelsheets = excelworkbook.Sheets;
            excelWorksheet = excelsheets.get_Item("Review");
            Range nameBinder = excelWorksheet.get_Range("A2", "A2");
            string reviewname = nameBinder.Value.ToString();
            driver.FindElement(By.Name("name")).SendKeys(reviewname);
            Range textBinder = excelWorksheet.get_Range("B2", "B2");
            string textname = textBinder.Value.ToString();
            driver.FindElement(By.Name("text")).SendKeys(textname);
            driver.FindElement(By.XPath("//input[@value='5']")).Click();
           // Thread.Sleep(9000);
            string text2 = Interaction.InputBox("Enter the Captcha Image Text"); 
            //Thread.Sleep(9000);
            driver.FindElement(By.Name("captcha")).SendKeys(text2);
            Screenshot ss = ((ITakesScreenshot)driver).GetScreenshot();
            string screenshot = ss.AsBase64EncodedString;
            byte[] screenshotAsByteArray = ss.AsByteArray;
            ss.SaveAsFile("filename", ImageFormat.Png);
            ss.ToString();
            Range name1Binder = excelWorksheet.get_Range("A3", "A3");
            string reviewname1 = name1Binder.Value.ToString();
            driver.FindElement(By.Name("name")).Clear();
            driver.FindElement(By.Name("name")).SendKeys(reviewname1);
            Range text1Binder = excelWorksheet.get_Range("B3", "B3");
            string textname1 = text1Binder.Value.ToString();
            driver.FindElement(By.Name("text")).Clear();
            driver.FindElement(By.Name("text")).SendKeys(textname1);
            excelworkbook.Close();
            excelApp.Quit();
            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(45));
            driver.FindElement(By.LinkText("Add to Wish List")).Click();
            driver.FindElement(By.XPath("//img[contains(@src, 'catalog/view/theme/default/image/close.png')]")).Click();
            driver.FindElement(By.Id("wishlist-total")).Click();
            driver.FindElement(By.LinkText("€")).Click();
            //display in flatfile
            int row_count = driver.FindElements(By.XPath("//*[@id='content']/div[2]/table/tbody/tr")).Count;
            int col_count = driver.FindElements(By.XPath("//*[@id='content']/div[2]/table/tbody/tr/td[1]")).Count;
            string table_data = driver.FindElement(By.XPath("//*[@id='content']/div[2]/table/tbody/tr/td[5]")).ToString();
            StreamWriter file2 = new StreamWriter("C:\\Users\\Admin\\Documents\\Visual Studio 2015\\Projects\\UnitTestProject1\\ReviewTotal.txt", true);
            file2.WriteLine(table_data + Environment.NewLine);
            driver.FindElement(By.LinkText("£")).Click();
            string table_data2 = driver.FindElement(By.XPath("//*[@id='content']/div[2]/table/tbody/tr/td[5]")).ToString();
            file2.WriteLine(table_data2 + Environment.NewLine);
            driver.FindElement(By.LinkText("$")).Click();
            string table_data3 = driver.FindElement(By.XPath("//*[@id='content']/div[2]/table/tbody/tr/td[5]")).ToString();
            file2.WriteLine(table_data3 + Environment.NewLine);
            file2.Close();
            //click on cart , close and remove button
            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(45));
            driver.FindElement(By.XPath("//img[contains(@src,'catalog/view/theme/default/image/cart-add.png')]")).Click();
            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(45));
            driver.FindElement(By.XPath("//img[cotains(@src,'catalog/view/theme/default/image/close.png')]")).Click();
            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(45));
            driver.FindElement(By.XPath("//img[cotains(@src,'catalog/view/theme/default/image/remove.png')]")).Click();
            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(45));
            driver.FindElement(By.ClassName("button")).Click();
            //logout of application
            driver.FindElement(By.LinkText("Logout")).Click();
            //checkpoint for login
            string logout_message = "You have been logged off your account. It is now safe to leave the computer.";
            Assert.AreEqual("You have been logged off your account. It is now safe to leave the computer.", logout_message);
            if (driver.FindElement(By.LinkText("login")).Displayed)
            {
                MessageBox.Show("Login link is displayed");
            }
            
             driver.Quit();
         }
    }
}

NotPolitcallyCorrect

Чем эта публикация отличается от других http://www.codeproject.com/Questions/1147137/Inputbox-is-not-dispalying-even-after-all-referenc?

2 Ответов

Рейтинг:
1

Harpreet05Kaur

ПРИВЕТ,

Попробуйте создать простой веб-сайт, а затем попробуйте свой код без testcase.

Это сработает.


Рейтинг:
0

Dave Kreskowiak

Модульные тесты никогда не должны иметь пользовательского интерфейса, потому что тест, который никогда не должен иметь изменяющихся входных данных для тестируемого кода. Я действительно сомневаюсь, что вы думаете, что делаете с InputBox в этом случае.