Selenium automated testing framework

Introduction to Selenium automation framework Selenium is a tool for web application testing. Selenium tests run directly in the browser, simulating real users to interact with the browser. Supports most mainstream browsers (IE, Google Chrome, Firefox, Safari, etc.) and their versions. You can use Selenium to test the compatibility of the project with different browsers […]

Python+Selenium automatically uploads watermelon videos on Mac

Background Let’s study the Python + Selenium automated testing framework, and simply implement automated batch uploading and publishing of videos on Mac, and share them with students who need them (without doing too much exception handling). Script implementation First log in with your manual mobile phone number and save the cookie file of the Xigua […]

[Automated Testing] Java+Selenium automated testing environment construction

This article mainly introduces the process of building Selenium automated testing environment based on Java and implementing code writing. 1. Introduction to Selenium Selenium 1.0 consists of four parts: core, IDE, RC, and grid. Selenium 2.0 is a new tool formed after two experts met and communicated with each other by chance and decided to […]

Selenium – Automate anything you want with this framework!

IntroductiontoChromeDevTools ChromeDevToolsisasetoftoolsbuiltdirectlyintoChromium-basedbrowserssuchasChrome,Opera,andMicrosoftEdgetohelpdevelopersdebugandstudywebsites. WithChromeDevTools,developerscangaindeeperaccesstowebsitesandbeableto: InspectelementsintheDOM EditelementsandCSSonthefly Checkandmonitorwebsiteperformance Simulatetheuser’sgeographiclocation Simulatefaster/slowernetworkspeeds ExecuteanddebugJavaScript Viewconsolelog etc. Selenium4ChromeDevToolsAPI Seleniumisacomprehensivesetoftoolsandlibrariesthatsupportwebbrowserautomation.Selenium4addsnativesupportfortheChromeDevToolsAPI.WiththesenewAPIs,ourtestscannow: Captureandmonitornetworktrafficandperformance Simulatedgeolocationforlocation-awaretesting,localizationandinternationalizationtesting Changedevicemodesandtestyourapp’sresponsiveness Thisisjustthetipoftheiceberg! Selenium4introducesthenewChromiumDriverclass,whichincludestwomethodsforaccessingChromeDevTools:getDevTools()andexecuteCdpCommand(). ThegetDevTools()methodreturnsanewDevToolsobjectthatallowsyoutosendbuilt-inSeleniumcommandsforCDPusingthesend()method.ThesecommandsarewrappermethodsthatmakecallingCDPfunctionsclearerandeasier. TheexecuteCdpCommand()methodalsoallowsyoutoexecuteCDPmethods,butismoreprimitive.InsteadofusingawrappedAPI,itallowsyoutodirectlypassinaChromeDevToolscommandandtheargumentstothatcommand.IfthereisnoSeleniumwrapperAPIforaCDPcommand,oryouwanttocallitdifferentlythantheSeleniumAPI,youcanuseexecuteCdpCommand(). Chromium-baseddriverslikeChromeDriverandEdgeDrivernowinheritfromChromiumDriver,soyoucanaccesstheSeleniumCDPAPIfromthesedriversaswell. Let’sexplorehowyoucanleveragethesenewSelenium4APIstosolvevarioususecases. Emulateddevicemode Mostoftheappswebuildtodayareresponsivetomeettheneedsofendusersfromavarietyofplatforms,devices(e.g.mobile,tablet,wearables,desktop)andscreenorientations. Astesters,wemaywanttoplaceourappsindifferentsizestotriggerresponsivenessintheapp. HowcanweachievethisusingSelenium’snewCDPfunctionality? TheCDPcommandformodifyingdevicemetricsisEmulation.setDeviceMetricsOverride,andthiscommandrequiresinputofwidth,height,mobiledeviceflag,anddevicescalingfactor.Thesefourkeysarerequiredinthisscenario,buttherearesomeoptionalkeys. InourSeleniumtests,wecanusetheDevTools::send()methodandusethebuilt-insetDeviceMetricsOverride()command,butthisSeleniumAPIaccepts12parameters-inadditiontothe4requiredparameters,thereare8optionalonesparameter.Foranyofthese8optionalparametersthatwedon’tneedtosend,wecanpassOptional.empty(). However,tosimplifythisprocessandonlypasstherequiredparameters,IwillusetheoriginalexecuteCdpCommand()methodinthecodebelow. packagecom.devtools; importorg.openqa.selenium.chrome.ChromeDriver; importorg.openqa.selenium.devtools.DevTools; importjava.util.HashMap; importjava.util.Map; publicclassSetDeviceMode{ finalstaticStringPROJECT_PATH=System.getProperty(“user.dir”); publicstaticvoidmain(String[]args){ System.setProperty(“webdriver.chrome.driver”,PROJECT_PATH+”/src/main/resources/chromedriver”); ChromeDriverdriver; driver=newChromeDriver(); DevToolsdevTools=driver.getDevTools(); devTools.createSession(); MapdeviceMetrics=newHashMap() {<!—->{ put(“width”,600); put(“height”,1000); put(“mobile”,true); put(“deviceScaleFactor”,50); }}; driver.executeCdpCommand(“Emulation.setDeviceMetricsOverride”,deviceMetrics); driver.get(“https://www.google.com”); } } Online19,Icreateamapcontainingthekeysrequiredforthiscommand. Thenonline26,IcalltheexecuteCdpCommand()method,passingtwoparameters:thecommandname”Emulation.setDeviceMetricsOverride”,andthedevicemetricsmapcontainingtheparameters. […]

Selenium + Nightwatch automated testing environment construction

Start building 1. Create project Let’s find a place to create a new directory, name it “my-test-toolkit”, and then use the terminal in the directory to run npm init -y to generate the project configuration file< strong>package.json. 2. Installation tools Then we will install Selenium and Nightwatch. Install selenium-standalone: npm install selenium-standalone –save-dev Install Nightwatch: […]

[Automated Testing] Java+Selenium automated testing environment construction!

This article mainly introduces the process of building Selenium automated testing environment based on Java and implementing code writing. 1. Introduction to Selenium Selenium 1.0 consists of four parts: core, IDE, RC, and grid. Selenium 2.0 is a new tool formed after two experts met and communicated with each other by chance and decided to […]

It’s 2023, why is Selenium still so popular?

The topic brought to you today is the automated testing framework Selenium. Without further ado, let’s get started! 1. What is Selenium automated testing Jason Huggins created a JavaScript framework in 2004 to free it from repetitive manual testing. Originally named JavaScriptTestRunner, the product can execute tests directly in the browser, drive interactions on the […]

[Automated Testing] Java+Selenium operates page elements (collection)

This article is based on the Java language, relies on the Eclipse tool, and uses the Selenium framework. It mainly introduces how to operate various elements in the Web page in Selenium. Eclipse build 1.1, Eclipse configuration 1.2. Introducing dependency packages Modify pom.xml file Under the dependencies node, add the following content, save and it […]