CASE WHEN in PostgreSQL

Yash Sanghvi
Updated on 02-Feb-2021 12:55:49

2K+ Views

If you are a programmer, you may be very familiar with IF-ELSE statements. The equivalent in PostgreSQL is CASE WHEN.Let’s understand with an example. If you have table marks containing percentage marks of a student, and you want to find out whether the students have passed or failed. An example table is given below.nameperc_marksAnil24Joy65Ron42Reena87Say the passing marks are 40. Now, if the student has scored above 40 marks, we want to print ‘PASS’ against that student’s name, otherwise ‘FAIL’. This is how you can do it −SELECT name, CASE WHEN perc_marks >= 40 THEN 'PASS' ELSE 'FAIL' END status from ... Read More

Get Current Timestamp and Relative Timestamps in PostgreSQL

Yash Sanghvi
Updated on 02-Feb-2021 12:54:56

3K+ Views

Quite often, you need the current timestamp in PostgreSQL. You do that as follows −SELECT current_timestampIt will output the current time. The output will look like the following −2021-01-30 15:52:14.738867+00Now, what if you want the relative time instead of the current time? For example, if you want the time corresponding to 5 hours prior to the current time, you can get it using intervals.SELECT current_timestamp - interval '5 hours'The output will be different every time. At the time of writing this, the output was −2021-01-30 10:57:13.28955+00 You can also do these operations on date instead of timestampsSELECT current_dateOutput2021-01-30SELECT current_date + ... Read More

Stop Page Loading in Firefox Programmatically using Selenium

Debomita Bhattacharjee
Updated on 02-Feb-2021 12:41:38

484 Views

We can stop the page loading in Firefox programmatically. This can be done by first setting page load time with the help of the pageLoadTimeout method.The time to wait for the page load is passed as a parameter to that method.Syntaxdriver.manage().timeouts().pageLoadTimeout(10, TimeUnit.MILLISECONDS);The page is forced to stop from loading with the help of the Javascript Executor. Selenium executes JavaScript command (window.stop() to stop page load) with the help of the executeScript method.Syntax((JavascriptExecutor)driver).executeScript("window.stop();");Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; public class StopPageLdWait{    public static void main(String[] args) {       System.setProperty("webdriver.gecko.driver",       "C:\Users\ghs6kor\Desktop\Java\geckodriver.exe");       ... Read More

Google Chrome Support in Selenium IDE

Debomita Bhattacharjee
Updated on 02-Feb-2021 12:31:11

455 Views

Initially Selenium IDE was used as a Firefox plugin. But the latest Selenium IDE version supports both Chrome and Firefox. For installation in Chrome, navigate to the below link −ttps://chrome.google.com/webstore/detail/seleniumide/mooikfkahbdckldjjndioackbalphokdThen click on Add to Chrome.Click on Add extension.Once installed, we shall get the below message as shown in the image −Also an icon gets created in the menu bar.Click on that icon, and the Selenium IDE gets launched with the below welcome screen.

Insert Values from One Table into Another in PostgreSQL

Yash Sanghvi
Updated on 02-Feb-2021 12:30:41

2K+ Views

Suppose you have two tables: marks and student_info. Examples are given below for the two respectivelynameroll_noperc_marksAniket1224Siddhi4565Yash2642Isha5687nameroll_noagegenderAniket1226MIsha5625FSiddhi4523FYash2625MNow, suppose your manager at work looks at the two tables and tells you, “Why do we have two tables? Simplify things, shift everything to one table!”So you decide to add the perc_marks column to the student_info table.ALTER TABLE student_info ADD COLUMN perc_marks integerNow, how will you populate this column? Will you manually add the marks for each column? That will leave the room open for a lot of errors and will also be very time-consuming. Instead, this is what you could do −UPDATE student_info ... Read More

Create Nested Test Suites for Selenium IDE

Debomita Bhattacharjee
Updated on 02-Feb-2021 12:26:38

431 Views

We can create nested test suites for Selenium IDE. A group of tests constitutes a test suite. First, to create a test suite we have to follow the below steps as listed below −Step1: Launch Selenium IDE. Then click on Create a new project link.Step2 − Provide the PROJECT NAME. Then click on OK.Step3 − Select Test Suites from the dropdown under the Project name. Then click on + button.Step4 − Add SUITE NAME, then click on ADD.Step5 − The new suite Test_Suite1 gets created. Click on it and select the option Add tests.Repeat the steps 3 and 4, to ... Read More

Manual Input from User in Selenium IDE Script

Debomita Bhattacharjee
Updated on 02-Feb-2021 12:26:19

2K+ Views

We can give manual input from the user while running Selenium IDE script. This can be done with the help of the Command, Target and Value steps given below −Step 1Command −execute scriptTarget −return prompt("Subject","");Value −InputStep 2Command −echoTarget −${Input}Click on Run current test as highlighted in the below image.OutputA prompt for user input comes up.The text Selenium Java is entered within the prompt.Selenium IDE log captures the text entered.

Handle Firefox Not Responding with Selenium WebDriver in Python

Debomita Bhattacharjee
Updated on 02-Feb-2021 12:25:36

726 Views

We can handle the situation in which the Firefox is not responding with the help of the Selenium webdriver in Python. This can be achieved with the help of the FirefoxProfile class.We shall create an object of this class and apply the set_preference method on it. Then pass these preferences − dom.max_script_run_time and dom.max_chrome_script_run_time with their values set to 0 as parameters to that method.Finally, this information shall be sent to the webdriver object.Syntaxf = webdriver.FirefoxProfile() f.set_preference("dom.max_chrome_script_run_time", 0) f.set_preference("dom.max_script_run_time", 0)We can get the above parameters of the browser by following the below steps −Open the Firefox browser.Type about:config in browser ... Read More

Define and Query JSON Columns in PostgreSQL

Yash Sanghvi
Updated on 02-Feb-2021 12:22:41

1K+ Views

The ability to define JSON columns in PostgreSQL makes it very powerful and helps PostgreSQL users experience the best of both worlds: SQL and NoSQL.Creating JSON columns is quite straightforward. You just have to create/ define it like any other column and use the data type as JSON.Let us create a new table in PostgreSQL, called json_test −CREATE TABLE json_test(    serial_no SERIAL PRIMARY KEY,    name VARCHAR,    metadata JSON );Now, let us populate it with some data −INSERT INTO json_test(name, metadata) VALUES ('Yash', '{"marks_scored":{"science":50, "maths":65}}'), ('Isha', '{"marks_scored":{"science":70, "maths":45}}');As you can see, the JSON values are added within single ... Read More

Save a Web Page with Python Selenium

Debomita Bhattacharjee
Updated on 02-Feb-2021 12:19:00

13K+ Views

We can save a webpage with Selenium webdriver in Python. To save a page we shall first obtain the page source behind the webpage with the help of the page_source method.We shall open a file with a particular encoding with the codecs.open method. The file has to be opened in the write mode represented by w and encoding type as utf−8. Then use the write method to write the content obtained from the page_source method.Syntaxn = os.path.join("C:\Users\ghs6kor\Downloads\Test", "PageSave.html") f = codecs.open(n, "w", "utf−8") h = driver.page_source f.write(h)Let us make an attempt to save the below webpage −Examplefrom selenium import webdriver ... Read More

Advertisements