Hướng dẫn selenium cheat sheet javascript - bảng cheat selen javascript

Như bạn đã biết, tôi là một fan hâm mộ lớn của & nbsp; selenium webdriver. Bạn có thể tìm thấy hàng tấn mã Java hữu ích trong loạt Java tự động hóa web của tôi. Tôi dẫn đầu các khóa học kiểm tra tự động và đào tạo mọi người cách viết bài kiểm tra mọi lúc. Điều còn thiếu trong các tài liệu là một tờ chứa tất cả các đoạn mã Java có liên quan nhất. Vì vậy, tôi quyết định lấp đầy khoảng trống đó. Vì vậy, tôi đã tạo ra tờ cheat selenium java selenium hoàn chỉnh nhất. Tôi hy vọng rằng bạn sẽ thấy nó hữu ích. Vui thích!

Ban đầu, tôi đã tạo bảng Cheat C# trong khi chúng tôi phát triển các phiên bản đầu tiên của khung thử nghiệm tự động & nbsp; Bellatrix. Đây là phiên bản Java của nó, được xem xét lại vào năm 2021.BELLATRIX automated testing framework. Here is a Java version of it, revisited in 2021.

// sử dụng một hồ sơ firefox cụ thể hồ sơ firefox = newProfilesini (); Firefoxprofile firefoxprofile = aborg.getProfile ("perfilename"); Firefoxoptions firefoxoptions = newfirefoxoptions (); Firefoxoptions.SetProfile (Firefoxprofile); trình điều khiển = newfirefoxDriver (Firefoxoptions); // Đặt hồ sơ proxy firefoxprofilesini của http = newProfilesini (); Firefoxprofile firefoxprofile = newfirefoxprofile (); firefoxprofile.setpreference ("network.proxy.type", 1); firefoxprofile.setpreference ("network.proxy.http", "myproxy.com"); firefoxprofile.setpreference ("network.proxy.http_port", 3239); Firefoxoptions firefoxoptions = newfirefoxoptions (); Firefoxoptions.SetProfile (Firefoxprofile); trình điều khiển = newfirefoxDriver (Firefoxoptions); // Đặt proxy chromevar proxy = newProxy (); proxy.setProxyType (proxy.proxyType.manual); proxy.setAutodetect (sai); proxy.setsslProxy ("127.0.0.1:3239"); Chromeoptions Chromeoptions = newChromeoptions (); Chromeoptions.SetProxy (proxy); trình điều khiển = newChromedriver (Chromeoptions); // Chấp nhận tất cả các chứng chỉ firefoxfirefoxprofile firefoxprofile = newfirefoxprofile (); firefoxprofile.setacceptunTrustedCerT (đúng); firefoxprofile.setassumeunTrustedCerTectateissuer (false); Firefoxoptions firefoxoptions = newfirefoxoptions (); Firefoxoptions.SetProfile (Firefoxprofile); trình điều khiển = newfirefoxDriver (Firefoxoptions); // Chấp nhận tất cả các chứng chỉ ChromeChRomeoptions Chromeoptions = newChromeoptions (); chromeoptions.addargument ("-bỏ qua chứng thực-errors"); trình điều khiển = newChromedriver (Chromeoptions); // Đặt các tùy chọn chromeChrOpeoptions Chromeoptions = newChromeoptions (); Chromeoptions.AddArgument ("DATA-DATA-DIR = C: Dữ liệu PathTouser"); trình điều khiển = newChromedriver (Chromeoptions); // Tắt hồ sơ JavaScript firefoxprofilesini = newProfilesini (); Firefoxprofile firefoxprofile = aborg.getProfile ("perfilename"); firefoxprofile.setPreference ("javascript.enables", false); Firefoxoptions firefoxoptions = newfirefoxoptions (); Firefoxoptions.SetProfile (Firefoxprofile); trình điều khiển = newfirefoxDriver (Firefoxoptions); // Đặt trình điều khiển thời gian tải trang mặc định. // Bắt đầu firefox với pluginsfirefoxprofile hồ sơ = newfirefoxprofile (); firefoxprofile.addextension (newfile ("c: extensionsLocationExtension.xpi")); Firefoxoptions firefoxoptions = newfirefoxoptions (); Firefoxoptions.SetProfile (Firefoxprofile); trình điều khiển = newfirefoxDriver (Firefoxoptions); // Bắt đầu chrome với một extensionChromeoptions chromeoptions = newChromeoptions (); chromeoptions.addargument ("tải-extension =/path/to/extension"); trình điều khiển = newChromedriver (Chromeoptions); // Bắt đầu chrome với một exentchromeoptions chromeoptions = newchromeoptions (); chromeoptions.addextensions (newFile ("local/path/to/extension.crx")); trình điều khiển = newChromedriver (Chromeoptions); // Thay đổi các tệp mặc định, Lưu vị trí firefoxprofile firefoxprofile = newfirefoxprofile (); Chuỗi Tải xuốngFilePath = "C: TEMP"; firefoxprofile.setPreference ("Browser.doLoad.FolderList", 2); firefoxprofile.setPreference ("Browser.doad.dir", downloadFilePath); firefoxprofile.setPreference ("Browser.doad.Manager.AlerTonExeopen", false); firefoxprofile.setPreference ("Browser.HelperApps.Neverask.Savetodisk", "Ứng dụng/MSWORD, Ứng dụng/nhị phân, Ứng dụng/RIS, Text/CSV, Image/PNG, Ứng dụng/PDF, Text/HTML, Text/Plain, ứng dụng/ZIP . Firefoxoptions firefoxoptions = newfirefoxoptions (); Firefoxoptions.SetProfile (Firefoxprofile); trình điều khiển = newfirefoxDriver (Firefoxoptions); Use a specific Firefox profile ProfilesIni profile = new ProfilesIni(); FirefoxProfile firefoxProfile = profile.getProfile("ProfileName"); FirefoxOptions firefoxOptions = new FirefoxOptions(); firefoxOptions.setProfile(firefoxProfile); driver = new FirefoxDriver(firefoxOptions); // Set a HTTP proxy Firefox ProfilesIni profile = new ProfilesIni(); FirefoxProfile firefoxProfile = new FirefoxProfile(); firefoxProfile.setPreference("network.proxy.type", 1); firefoxProfile.setPreference("network.proxy.http", "myproxy.com"); firefoxProfile.setPreference("network.proxy.http_port", 3239); FirefoxOptions firefoxOptions = new FirefoxOptions(); firefoxOptions.setProfile(firefoxProfile); driver = new FirefoxDriver(firefoxOptions); // Set a HTTP proxy Chrome var proxy = new Proxy(); proxy.setProxyType(Proxy.ProxyType.MANUAL); proxy.setAutodetect(false); proxy.setSslProxy("127.0.0.1:3239"); ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions.setProxy(proxy); driver = new ChromeDriver(chromeOptions); // Accept all certificates Firefox FirefoxProfile firefoxProfile = new FirefoxProfile(); firefoxProfile.setAcceptUntrustedCertificates(true); firefoxProfile.setAssumeUntrustedCertificateIssuer(false); FirefoxOptions firefoxOptions = new FirefoxOptions(); firefoxOptions.setProfile(firefoxProfile); driver = new FirefoxDriver(firefoxOptions); // Accept all certificates Chrome ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions.addArguments("--ignore-certificate-errors"); driver = new ChromeDriver(chromeOptions); // Set Chrome options ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions.addArguments("user-data-dir=C:PathToUser Data"); driver = new ChromeDriver(chromeOptions); // Turn off the JavaScript Firefox ProfilesIni profile = new ProfilesIni(); FirefoxProfile firefoxProfile = profile.getProfile("ProfileName"); firefoxProfile.setPreference("javascript.enabled", false); FirefoxOptions firefoxOptions = new FirefoxOptions(); firefoxOptions.setProfile(firefoxProfile); driver = new FirefoxDriver(firefoxOptions); // Set the default page load timeout driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS); // Start Firefox with plugins FirefoxProfile profile = new FirefoxProfile(); firefoxProfile.addExtension(new File("C:extensionsLocationextension.xpi")); FirefoxOptions firefoxOptions = new FirefoxOptions(); firefoxOptions.setProfile(firefoxProfile); driver = new FirefoxDriver(firefoxOptions); // Start Chrome with an unpacked extension ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions.addArguments("load-extension=/path/to/extension"); driver = new ChromeDriver(chromeOptions); // Start Chrome with a packed extension ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions.addExtensions(new File("local/path/to/extension.crx")); driver = new ChromeDriver(chromeOptions); // Change the default files’ save location FirefoxProfile firefoxProfile = new FirefoxProfile(); String downloadFilepath = "c:temp"; firefoxProfile.setPreference("browser.download.folderList", 2); firefoxProfile.setPreference("browser.download.dir", downloadFilepath); firefoxProfile.setPreference("browser.download.manager.alertOnEXEOpen", false); firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/msword, application/binary, application/ris, text/csv, image/png, application/pdf, text/html, text/plain, application/zip, application/x-zip, application/x-zip-compressed, application/download, application/octet-stream")); FirefoxOptions firefoxOptions = new FirefoxOptions(); firefoxOptions.setProfile(firefoxProfile); driver = new FirefoxDriver(firefoxOptions);