Exemple #1
0
        private void Button1_Click(object sender, EventArgs e)
        {
            var chromeDriverService = ChromeDriverService.CreateDefaultService();

            chromeDriverService.HideCommandPromptWindow = true;
            ChromeOptions options = new ChromeOptions();

            var perfLogPrefs      = new ChromePerformanceLoggingPreferences();
            var tracingCategories = "toplevel,disabled-by-default-devtools.timeline.frame,blink.console,disabled-by-default-devtools.timeline,benchmark";

            perfLogPrefs.AddTracingCategories(new string[] { tracingCategories });
            options.PerformanceLoggingPreferences = perfLogPrefs;
            options.SetLoggingPreference("performance", LogLevel.All);
            chromeDriver = new ChromeDriver(chromeDriverService, options);
            chromeDriver.Navigate().GoToUrl("https://www.facebook.com/");
            chromeDriver.FindElementByClassName("inputtext").Click();
            //get bz file
            var    logs = chromeDriver.Manage().Logs.GetLog("performance");
            object s;

            File.WriteAllText("result/json.txt", "");

            foreach (var item in logs)
            {
                if (item.Message.ToString().Contains("https://www.facebook.com/ajax/bz") && item.Message.ToString().Contains("postData"))
                {
                    s = JsonConvert.SerializeObject(item);
                    File.AppendAllText("result/json.txt", s.ToString() + "\r\n\r\n");
                }
            }
            MessageBox.Show(File.ReadAllText("result/json.txt"));
        }
Exemple #2
0
        private static IWebDriver CreateChromDriver(string chromeDriverPath)
        {
            IWebDriver driver;
            var        arrayList = new ArrayList {
                "--disable-glsl-translator --start-maximized --automation-reinitialize-on-channel-error --bwsi --assert-test --test-type --disable-logging --disable-plugins --disable-translate --disable-web-security"
            };
            var desiredCapabilities = DesiredCapabilities.Chrome();
            var chromeOptions       = new ChromeOptions();

            chromeOptions.AddArguments("test-type");
            chromeOptions.AddArgument("--start-maximized");
            chromeOptions.AddArguments("disable-infobars");

            var perfLogPrefs = new ChromePerformanceLoggingPreferences();

            perfLogPrefs.AddTracingCategories(new string[] { "devtools.network" });

            chromeOptions.AddAdditionalCapability(CapabilityType.EnableProfiling, true, true);
            //chromeOptions.PerformanceLoggingPreferences = perfLogPrefs;
            chromeOptions.SetLoggingPreference("performance", LogLevel.All);
            chromeOptions.AddUserProfilePreference("intl.accept_languages", "en-AU");
            desiredCapabilities.SetCapability("download.prompt_for_download", false);
            //desiredCapabilities.SetCapability("download.default_directory", browserDownloadDir);
            desiredCapabilities.SetCapability("disable-extensions", true);
            desiredCapabilities.SetCapability("chrome.switches", arrayList);

            var baseExecutingAssemblyDir = Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath);
            var commandTimeout           = new TimeSpan(0, 0, 60);

            driver = new ChromeDriver(Path.Combine(baseExecutingAssemblyDir ?? string.Empty, chromeDriverPath), chromeOptions, commandTimeout);

            return(driver);
        }
Exemple #3
0
        private void MapPerformanceLoggingPreferences(DriverPerformanceLoggingPreferencesJsonSection section, ChromePerformanceLoggingPreferences preferences)
        {
            ObjectMapper.Map(section.ExtraPropertiesMap, preferences);

            if (section.TracingCategories?.Any() ?? false)
            {
                preferences.AddTracingCategories(section.TracingCategories);
            }
        }
Exemple #4
0
        private void SetBrowserLoggingCapabilities(ref ChromeOptions options)
        {
            var perfLogPrefs      = new ChromePerformanceLoggingPreferences();
            var tracingCategories = "toplevel,disabled-by-default-devtools.timeline.frame,blink.console,disabled-by-default-devtools.timeline,benchmark";

            perfLogPrefs.AddTracingCategories(new string[] { tracingCategories });
            options.PerformanceLoggingPreferences = perfLogPrefs;
            options.SetLoggingPreference("performance", LogLevel.All);
        }
Exemple #5
0
        private void btnmoweb_Click(object sender, EventArgs e)
        {
            ChromePerformanceLoggingPreferences perfLogPrefs = new ChromePerformanceLoggingPreferences();

            perfLogPrefs.AddTracingCategories(new string[] { "devtools.timeline" });
            ChromeOptions options = new ChromeOptions();

            options.AddArguments("--disable-notifications");
            options.AddArgument("--window-size=1500,900");
            options.AddArgument("--disable-infobars");
            options.PerformanceLoggingPreferences = perfLogPrefs;
            options.SetLoggingPreference(LogType.Driver, LogLevel.All);
            options.SetLoggingPreference("performance", LogLevel.All);
            options.AddAdditionalCapability(CapabilityType.EnableProfiling, true, true);
            PropretiesCollection.driver = new ChromeDriver(options);
            PropretiesCollection.driver.Navigate().GoToUrl("https://thuthapdiachi.vnpost.vn/");
        }
Exemple #6
0
        private void btnlaythongtinchatluong_Click(object sender, EventArgs e)
        {
            Thread chay = new Thread(() =>
            {
                hamxoafile(@"C:\TempExcel");
                #region     // lay thông tin phát
                ChromePerformanceLoggingPreferences perfLogPrefs = new ChromePerformanceLoggingPreferences();
                perfLogPrefs.AddTracingCategories(new string[] { "devtools.timeline" });
                ChromeOptions options = new ChromeOptions();
                var downloadDirectory = @"C:\TempExcel";
                options.AddUserProfilePreference("download.default_directory", downloadDirectory);
                options.AddUserProfilePreference("download.prompt_for_download", false);
                options.AddUserProfilePreference("disable-popup-blocking", "true");

                options.AddArguments("--disable-notifications");
                options.PerformanceLoggingPreferences = perfLogPrefs;
                options.SetLoggingPreference(LogType.Driver, LogLevel.All);
                options.SetLoggingPreference("performance", LogLevel.All);
                options.AddAdditionalCapability(CapabilityType.EnableProfiling, true, true);
                PropretiesCollection.driver = new ChromeDriver(options);
                PropretiesCollection.driver.Navigate().GoToUrl("https://chatluong.vnpost.vn");
                ChatLuong cl = new ChatLuong();
                cl.XuLy(txttaikhoanchatluong.Text, txtpasschatluong.Text, txtngaychatluong.Text, txtngaychatluong.Text, 1);
                //chạy xong tắt chome
                PropretiesCollection.driver.Close();

                #region         //xử lý luôn file excel down về lưu vào csdl
                string fileexcel   = @"C:\TempExcel\" + "Chat Luong cong doan phat theo buu cuc phat.xlsx";
                DuLieuExcel dExcel = new DuLieuExcel();
                DataTable DuLieu   = new DataTable();
                dExcel.TenFile     = fileexcel;
                DuLieu             = dExcel.Doc().Tables[0];
                if (DuLieu.Rows.Count > 0)
                {
                }
                hamxoafile(@"C:\TempExcel");
                #endregion

                #endregion
            }
                                     );

            chay.Start();
        }
Exemple #7
0
        private void button1_Click(object sender, EventArgs e)
        {
            ChromePerformanceLoggingPreferences perfLogPrefs = new ChromePerformanceLoggingPreferences();

            perfLogPrefs.AddTracingCategories(new string[] { "devtools.timeline" });
            ChromeOptions options = new ChromeOptions();

            options.AddArguments("--disable-notifications");
            options.AddArguments("--incognito");
            options.PerformanceLoggingPreferences = perfLogPrefs;
            options.SetLoggingPreference(LogType.Driver, LogLevel.All);
            options.SetLoggingPreference("performance", LogLevel.All);
            options.AddAdditionalCapability(CapabilityType.EnableProfiling, true, true);
            PropretiesCollection.driver = new ChromeDriver(options);
            PropretiesCollection.driver.Navigate().GoToUrl("http://facebook.com/");
            Test a = new Test();

            a.DangKy("tran", "Linh", "*****@*****.**", "*****@*****.**");
        }
        private static IWebDriver GetDriver(string browserType)
        {
            IWebDriver curDriver = null;

            switch (browserType)
            {
            case "chrome":
                DesiredCapabilities capabilites = DesiredCapabilities.Chrome();
                capabilites.SetCapability("navtiveEvents", true);
                ChromePerformanceLoggingPreferences logPrefs = new ChromePerformanceLoggingPreferences();
                logPrefs.AddTracingCategories(LogType.Profiler);
                ChromeOptions options = new ChromeOptions();
                options.SetLoggingPreference(LogType.Browser, LogLevel.Warning);
                curDriver = new ChromeDriver(options);
                Reporter.SetReporter();
                Reporter.StartTestReporting("Test Started");
                break;
            }
            return(curDriver);
        }
Exemple #9
0
        private void btnganbuucucthugom_Click(object sender, EventArgs e)
        {
            Thread chay = new Thread(() =>
            {
                ChromePerformanceLoggingPreferences perfLogPrefs = new ChromePerformanceLoggingPreferences();
                perfLogPrefs.AddTracingCategories(new string[] { "devtools.timeline" });
                ChromeOptions options = new ChromeOptions();
                options.AddArguments("--disable-notifications");
                options.PerformanceLoggingPreferences = perfLogPrefs;
                options.SetLoggingPreference(LogType.Driver, LogLevel.All);
                options.SetLoggingPreference("performance", LogLevel.All);
                options.AddAdditionalCapability(CapabilityType.EnableProfiling, true, true);
                PropretiesCollection.driver = new ChromeDriver(options);
                PropretiesCollection.driver.Navigate().GoToUrl("https://pns.vnpost.vn/tin/thiet-lap-buu-cuc-thu-gom-tu-dong.html");
                PNS login = new PNS();
                login.login(txttaikhoanpns.Text, txtpasspns.Text);

                da_dmkhachhangmcs mcs = new da_dmkhachhangmcs();
                DataTable dt          = new DataTable();
                dt = mcs.DanhSachkhachhangmcs(Cl_KetNoi.hamketnoisqlhtkh2015());
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow r in dt.Rows)
                    {
                        string macrm     = r["MaCRM"].ToString();
                        string dienthoai = r["DienThoai"].ToString();
                        string trungtam  = r["IDCapTren"].ToString();
                        string mabuucuc  = r["MaBuuCuc"].ToString();
                        PNS them         = new PNS();
                        int kq           = them.GanTuDong(macrm, dienthoai, trungtam, mabuucuc);
                        if (kq == 1)
                        {
                            da_dmkhachhangmcs xacnhan = new da_dmkhachhangmcs();
                            xacnhan.DaTruyen(Cl_KetNoi.hamketnoisqlhtkh2015(), macrm, dienthoai);
                        }
                    }
                }
            });

            chay.Start();
        }
        protected virtual DriverOptions CreateChromeDriverOptions()
        {
            var options = new ChromeOptions();

            options.LeaveBrowserRunning = true;
            options.AddArgument("bwsi");
            options.AddArgument("ignore-certificate-errors");
            //options.AddArgument("disable-extensions");
            options.AddArgument("window-size=1920,1080");
            options.AddArgument("start-maximized");
            options.AddArgument("allow-insecure-localhost");
            options.AddArgument("no-sandbox");
            options.AddAdditionalCapability("useAutomationExtension", false);


            if (string.Equals(_configurationReader.GetConfigurationValue(Constants.Configuration.EnableDetailedLogging).ToLower(), Generic.TrueValue))
            {
                var perfLogPrefs = new ChromePerformanceLoggingPreferences();
                perfLogPrefs.AddTracingCategories("devtools.network");
                options.PerformanceLoggingPreferences = perfLogPrefs;
                options.AddAdditionalCapability(CapabilityType.EnableProfiling, true, true);
                options.SetLoggingPreference("performance", LogLevel.All);
            }

            if (string.Equals(_configurationReader.GetConfigurationValue(Constants.Configuration.HeadlessKey).ToLower(), Generic.TrueValue))
            {
                options.AddArguments("headless");
                options.AddArgument("verbose");
                options.AddArgument("disable-gpu");
                options.AddArgument("allow-running-insecure-content");
                options.AddAdditionalCapability(CapabilityType.AcceptSslCertificates, true, true);
                options.AddAdditionalCapability(CapabilityType.AcceptInsecureCertificates, true, true);

                /*options.AddArgument("disable-extensions");
                 * options.AddArgument("disable-gpu");
                 * options.AddArgument("disable-infobars");*/
            }

            return(options);
        }
Exemple #11
0
        private void btnchaylaithongtinphat_Click(object sender, EventArgs e)
        {
            Thread chay = new Thread(() =>
            {
                txtlog.Text               = "";
                da_dmbclay bc             = new da_dmbclay();
                DataTable tablebuucuc     = new DataTable();
                tablebuucuc               = bc.DanhSachBuuCucKhongsoLieu(Cl_KetNoi.hamketnoisql(), txttungay.Text);
                DataTable tbc             = (DataTable)listbuucuc.DataSource;
                lblbuucuckhongsolieu.Text = "Số lượng bưu cục không số liệu :" + tablebuucuc.Rows.Count.ToString() + "/" + tbc.Rows.Count.ToString();

                if (tablebuucuc.Rows.Count > 0)
                {
                    #region // lay thông tin phát
                    ChromePerformanceLoggingPreferences perfLogPrefs = new ChromePerformanceLoggingPreferences();
                    perfLogPrefs.AddTracingCategories(new string[] { "devtools.timeline" });
                    ChromeOptions options = new ChromeOptions();
                    options.AddArguments("--disable-notifications");
                    options.PerformanceLoggingPreferences = perfLogPrefs;
                    options.SetLoggingPreference(LogType.Driver, LogLevel.All);
                    options.SetLoggingPreference("performance", LogLevel.All);
                    options.AddAdditionalCapability(CapabilityType.EnableProfiling, true, true);
                    PropretiesCollection.driver = new ChromeDriver(options);
                    PropretiesCollection.driver.Navigate().GoToUrl("http://thongtinphat.vnpost.vn/Security/SignIn");
                    // PropretiesCollection.driver.Manage().Window.Size = new Size(480, 720);
                    ThongTinPhat t = new ThongTinPhat();
                    t.login(txttaikhoan.Text, txtmatkhau.Text, txttungay.Text.Trim(), txttungay.Text.Trim());
                    txtlog.Text  = txtlog.Text + "\r\n" + "Login thành công bắt đầu quét dữ liệu" + "-->" + DateTime.Now.ToString();
                    lblxuly.Text = "0";
                    int i        = 1;
                    foreach (DataRow r in tablebuucuc.Rows)
                    {
                        string mabuucuc  = r["mabuucuc"].ToString();
                        string tenbuucuc = r["buucuc"].ToString();
                        txtlog.Text      = txtlog.Text + "\r\n" + "Bắt đầu đọc dữ liệu bưu cục " + mabuucuc + "-" + tenbuucuc + "-->" + DateTime.Now.ToString();;
                        DataTable dt     = new DataTable();
                        dt          = t.ThongTin(mabuucuc, int.Parse(txttimernghi.Value.ToString()));
                        txtlog.Text = txtlog.Text + "\r\n" + "Bưu cục " + tenbuucuc + " Có số lượng bản ghi là:" + dt.Rows.Count.ToString() + "-->" + DateTime.Now.ToString();
                        if (dt.Rows.Count > 0)
                        {
                            #region // ghi dữ liệu vào csdl SMP
                            da_smp_mau ghi = new da_smp_mau();
                            ghi.CapNhat(Cl_KetNoi.hamketnoisql(), dt, txttungay.Text, mabuucuc);
                            txtlog.Text = txtlog.Text + "\r\n" + "Ghi thành công dữ liệu cho bưu cục :" + tenbuucuc + "-->" + DateTime.Now.ToString();

                            #endregion
                        }
                        lblxuly.Text = "Xử lý :" + i.ToString() + "/" + tablebuucuc.Rows.Count.ToString();
                        i++;
                        ScrollToBottom(txtlog);
                    }
                    txtlog.Text = txtlog.Text + "\r\n" + "Đã Xong!" + "-->" + DateTime.Now.ToString();

                    da_smp_mau dlngay     = new da_smp_mau();
                    DataTable tableBC     = new DataTable();
                    tableBC               = dlngay.DanhSachSoLieu(Cl_KetNoi.hamketnoisql(), txttungay.Text);
                    listbuucuc.DataSource = tableBC;
                    //chạy xong tắt chome
                    PropretiesCollection.driver.Close();
                    #endregion
                }
                else
                {
                    MessageBox.Show("Lỗi không có danh sách bưu cục cần lấy dữ liệu");
                    return;
                }
            }
                                     );

            chay.Start();
        }