Exemplo n.º 1
0
        public void FileUpload_ElementWrapperByA()
        {
            RunInAllBrowsers(browser =>
            {
                browser.NavigateToUrl("/FileUpload");

                var tempPath = Path.GetTempFileName();
                File.WriteAllBytes(tempPath, Enumerable.Range(0, 255).Select(i => (byte)i).ToArray());

                DotVVMAssert.UploadFile(browser.First(".dotvvm-upload-button a"), tempPath);

                browser.WaitFor(() =>
                {
                    browser.First("#FUpload .dotvvm-upload-files").CheckIfInnerTextEquals("1 files", false);
                }, 4000, "File upload failed.");
            });
        }
Exemplo n.º 2
0
        public void Control_FileUpload_FileUpload()
        {
            RunInAllBrowsers(browser =>
            {
                browser.NavigateToUrl(SamplesRouteUrls.ControlSamples_FileUpload_FileUpload);
                browser.Wait(1000);

                // get existing files
                var existingFiles = browser.FindElements("li").Select(e => e.GetText()).ToList();
                browser.Wait(1000);

                // generate a sample file to upload
                var tempFile = Path.GetTempFileName();
                File.WriteAllText(tempFile, string.Join(",", Enumerable.Range(1, 100000)));

                // write the full path to the dialog

                DotVVMAssert.UploadFile((ElementWrapper)browser.First(".dotvvm-upload-button a"), tempFile);

                // wait for the file to be uploaded

                browser.WaitFor(() => browser.First(".dotvvm-upload-files").GetText() == "1 files", 60000,
                                "File was not uploaded in 1 min interval.");

                //TODO: TestContext.WriteLine("The file was uploaded.");

                // submit
                browser.Click("input[type=button]");

                // verify the file is there present
                browser.WaitFor(
                    () =>
                    browser.First("ul").FindElements("li").FirstOrDefault(t => !existingFiles.Contains(t.GetText())) !=
                    null, 60000, "File was not uploaded correctly.");

                // delete the file
                var firstLi =
                    browser.First("ul").FindElements("li").FirstOrDefault(t => !existingFiles.Contains(t.GetText()));
                browser.NavigateToUrl(SamplesRouteUrls.ControlSamples_FileUpload_FileUpload + "?delete=" + firstLi.GetText());

                // delete the temp file
                File.Delete(tempFile);
            });
        }
Exemplo n.º 3
0
        public void Complex_FileUploadInRepeater_FileUploadInRepeater()
        {
            RunInAllBrowsers(browser =>
            {
                browser.NavigateToUrl(SamplesRouteUrls.ComplexSamples_FileUploadInRepeater_FileUploadInRepeater);
                browser.Wait(1000);


                var tempPath = Path.GetTempFileName();
                File.WriteAllBytes(tempPath, Enumerable.Range(0, 255).Select(i => (byte)i).ToArray());

                AssertUI.InnerTextEquals(browser.ElementAt(".files-count", 0), "0");
                DotVVMAssert.UploadFile((ElementWrapper)browser.ElementAt(".dotvvm-upload-button a", 0), tempPath);

                browser.WaitFor(() => browser.ElementAt(".files-count", 0).GetInnerText() == "1", 10000, "FileCount is not updated to '1'.");

                AssertUI.InnerTextEquals(browser.ElementAt(".files-count", 1), "0");
                AssertUI.InnerTextEquals(browser.ElementAt(".files-count", 2), "0");

                DotVVMAssert.UploadFile((ElementWrapper)browser.ElementAt(".dotvvm-upload-button a", 2), tempPath);
                browser.Wait(6000);

                AssertUI.InnerTextEquals(browser.ElementAt(".files-count", 0), "1");
                AssertUI.InnerTextEquals(browser.ElementAt(".files-count", 1), "0");
                AssertUI.InnerTextEquals(browser.ElementAt(".files-count", 2), "1");

                DotVVMAssert.UploadFile((ElementWrapper)browser.ElementAt(".dotvvm-upload-button a", 0), tempPath);
                browser.Wait(6000);

                AssertUI.InnerTextEquals(browser.ElementAt(".files-count", 0), "2");
                AssertUI.InnerTextEquals(browser.ElementAt(".files-count", 1), "0");
                AssertUI.InnerTextEquals(browser.ElementAt(".files-count", 2), "1");

                try
                {
                    File.Delete(tempPath);
                }
                catch
                {
                    //TODO log
                }
            });
        }
Exemplo n.º 4
0
        public void Control_FileUpload_FileSize()
        {
            RunInAllBrowsers(browser =>
            {
                browser.NavigateToUrl(SamplesRouteUrls.ControlSamples_FileUpload_FileSize);
                browser.Wait(1000);

                var fileSize = browser.Single("span.fileSize");

                var file = CreateTempFile("txt", 2);
                DotVVMAssert.UploadFile((ElementWrapper)browser.First(".dotvvm-upload-button a"), file);

                browser.WaitFor(() => browser.First(".dotvvm-upload-files").GetText() == "1 files", 60000,
                                "File was not uploaded in 1 min interval.");

                AssertUI.TextEquals(fileSize, "2 MB");

                File.Delete(file);
            });
        }
Exemplo n.º 5
0
        public void Control_FileUpload_IsFileNotAllowed()
        {
            RunInAllBrowsers(browser =>
            {
                browser.NavigateToUrl(SamplesRouteUrls.ControlSamples_FileUpload_IsAllowedOrNot);
                browser.Wait(1000);

                var isFileTypeAllowed = browser.Single("span.isFileTypeAllowed");
                var isMaxSizeExceeded = browser.Single("span.isMaxSizeExceeded");

                var mdFile = CreateTempFile("md", 1);
                DotVVMAssert.UploadFile((ElementWrapper)browser.First(".dotvvm-upload-button a"), mdFile);

                browser.WaitFor(() => browser.First(".dotvvm-upload-files").GetText() == "1 files", 60000,
                                "File was not uploaded in 1 min interval.");

                AssertUI.TextEquals(isFileTypeAllowed, "false");
                AssertUI.TextEquals(isMaxSizeExceeded, "false");

                File.Delete(mdFile);
            });
        }