Hana Juali

Hana Juali

1601342380

How to capture/take Selenium Screenshot as Full Page or Element?

When we write automation tests, we execute the test scenarios on the application under test to reduce the manual effort to perform regression testing. If you have a huge regression suite and tests are failed, you need to check and analyze the test flow to identify where it failed and why it failed. Wouldn’t it be good if the Selenium tests capture the screenshot at the time of execution so that you have a look at the screenshot to view the state of the application at that particular time? Automation testing helps us achieve that so that we can save our time to re-run an entire test every time a script fails.

We can take screenshots at run time using the test script that helps us bug analysis by viewing the state of the application at the time of failure. In this tutorial, we will discuss in detail the need for screenshots and how we can use _Selenium Screenshot _of a webpage.

  • Why is Screenshot required in Automation testing?
  • How to take a screenshot in Selenium?
  • How to take a screenshot of the full page in Selenium?
  • And, how to take a screenshot of a particular element in Selenium?

#selenium-webdriver #selenium

What is GEEK

Buddha Community

How to capture/take Selenium Screenshot as Full Page or Element?

How to Bash Read Command

Bash has no built-in function to take the user’s input from the terminal. The read command of Bash is used to take the user’s input from the terminal. This command has different options to take an input from the user in different ways. Multiple inputs can be taken using the single read command. Different ways of using this command in the Bash script are described in this tutorial.

Syntax

read [options] [var1, var2, var3…]

The read command can be used without any argument or option. Many types of options can be used with this command to take the input of the particular data type. It can take more input from the user by defining the multiple variables with this command.

Some Useful Options of the Read Command

Some options of the read command require an additional parameter to use. The most commonly used options of the read command are mentioned in the following:

OptionPurpose
-d <delimiter>It is used to take the input until the delimiter value is provided.
-n <number>It is used to take the input of a particular number of characters from the terminal and stop taking the input earlier based on the delimiter.
-N <number>It is used to take the input of the particular number of characters from the terminal, ignoring the delimiter.
-p <prompt>It is used to print the output of the prompt message before taking the input.
-sIt is used to take the input without an echo. This option is mainly used to take the input for the password input.
-aIt is used to take the input for the indexed array.
-t <time>It is used to set a time limit for taking the input.
-u <file descriptor>It is used to take the input from the file.
-rIt is used to disable the backslashes.

 

Different Examples of the Read Command

The uses of read command with different options are shown in this part of this tutorial.

Example 1: Using Read Command without Any Option and variable

Create a Bash file with the following script that takes the input from the terminal using the read command without any option and variable. If no variable is used with the read command, the input value is stored in the $REPLY variable. The value of this variable is printed later after taking the input.

#!/bin/bash  
#Print the prompt message
echo "Enter your favorite color: "  
#Take the input
read  
#Print the input value
echo "Your favorite color is $REPLY"

Output:

The following output appears if the “Blue” value is taken as an input:

Example 2: Using Read Command with a Variable

Create a Bash file with the following script that takes the input from the terminal using the read command with a variable. The method of taking the single or multiple variables using a read command is shown in this example. The values of all variables are printed later.

#!/bin/bash  
#Print the prompt message
echo "Enter the product name: "  
#Take the input with a single variable
read item

#Print the prompt message
echo "Enter the color variations of the product: "  
#Take three input values in three variables
read color1 color2 color3

#Print the input value
echo "The product name is $item."  
#Print the input values
echo "Available colors are $color1, $color2, and $color3."

Output:

The following output appears after taking a single input first and three inputs later:

Example 3: Using Read Command with -p Option

Create a Bash file with the following script that takes the input from the terminal using the read command with a variable and the -p option. The input value is printed later.

#!/bin/bash  
#Take the input with the prompt message
read -p "Enter the book name: " book
#Print the input value
echo "Book name: $book"

Output:

The following output appears after taking the input:

Example 4: Using Read Command with -s Option

Create a Bash file with the following script that takes the input from the terminal using the read command with a variable and the -s option. The input value of the password will not be displayed for the -s option. The input values are checked later for authentication. A success or failure message is also printed.

#!/bin/bash  
#Take the input with the prompt message
read -p "Enter your email: " email
#Take the secret input with the prompt message
read -sp "Enter your password: " password

#Add newline
echo ""

#Check the email and password for authentication
if [[ $email == "admin@example.com" && $password == "secret" ]]
then
   #Print the success message
   echo "Authenticated."
else
   #Print the failure message
   echo "Not authenticated."
fi

Output:

The following output appears after taking the valid and invalid input values:

Example 5: Using Read Command with -a Option

Create a Bash file with the following script that takes the input from the terminal using the read command with a variable and the -a option. The array values are printed later after taking the input values from the terminal.

#!/bin/bash  
echo "Enter the country names: "  
#Take multiple inputs using an array  
read -a countries

echo "Country names are:"
#Read the array values
for country in ${countries[@]}
do
    echo $country
done

Output:

The following output appears after taking the array values:

Example 6: Using Read Command with -n Option

Create a Bash file with the following script that takes the input from the terminal using the read command with a variable and the -n option.

#!/bin/bash  
#Print the prompt message
echo "Enter the product code: "  
#Take the input of five characters
read -n 5 code
#Add newline
echo ""
#Print the input value
echo "The product code is $code"

Output:

The following output appears if the “78342” value is taken as input:

Example 7: Using Read Command with -t Option

Create a Bash file with the following script that takes the input from the terminal using the read command with a variable and the -t option.

#!/bin/bash  
#Print the prompt message
echo -n "Write the result of 10-6: "  
#Take the input of five characters
read -t 3 answer

#Check the input value
if [[ $answer == "4" ]]
then
   echo "Correct answer."
else
   echo "Incorrect answer."
fi

Output:

The following output appears after taking the correct and incorrect input values:

Conclusion

The uses of some useful options of the read command are explained in this tutorial using multiple examples to know the basic uses of the read command.

Original article source at: https://linuxhint.com/

#bash #command 

Recherche linéaire en Python

Dans cet article Python, vous apprendrez ce qui suit :

  • Qu'est-ce qu'une recherche linéaire ?
  • Algorithme de recherche linéaire
  • Écrire un programme Python pour la recherche linéaire à l'aide de la boucle While
  • Écrire un programme Python pour la recherche linéaire à l'aide de la boucle For
  • Recherche linéaire dans le programme Python à l'aide de la récursion

Qu'est-ce qu'une recherche linéaire ?

Tout d'abord, une recherche linéaire, également appelée recherche séquentielle, cette méthode est utilisée pour rechercher un élément dans une liste ou un tableau. Il vérifie chaque élément de la liste un par un / séquentiellement jusqu'à ce qu'une correspondance soit trouvée ou que toute la liste ait été recherchée.

Algorithme de recherche linéaire

Implémentez la recherche linéaire en suivant les étapes ci-dessous :

  • Parcourez la liste/le tableau à l'aide d'une boucle.
  • À chaque itération, associez la  target valeur à la valeur donnée de la liste/du tableau.
    • Si les valeurs correspondent, renvoie l'index actuel de la liste/du tableau.
    • Sinon, passez à l'élément de tableau/liste suivant.
  • Si aucune correspondance n'est trouvée, retournez  -1.

Écrire un programme Python pour la recherche linéaire à l'aide de la boucle While

# python program for linear search using while loop

#define list
lst = []

#take input list size
num = int(input("Enter size of list :- "))

for n in range(num):
    #append element in list/array
    numbers = int(input("Enter the array of %d element :- " %n))
    lst.append(numbers)

#take input number to be find in list   
x = int(input("Enter number to search in list :- "))

i = 0
flag = False

while i < len(lst):
	if lst[i] == x:
		flag = True
		break

	i = i + 1

if flag == 1:
	print('{} was found at index {}.'.format(x, i))
else:
	print('{} was not found.'.format(x))

Après l'exécution du programme, la sortie sera :

Enter size of list :-  5
Enter the array of 0 element :-  10
Enter the array of 1 element :-  23
Enter the array of 2 element :-  56
Enter the array of 3 element :-  89
Enter the array of 4 element :-  200
Enter number to search in list :-  89
89 was found at index 3.

Écrire un programme Python pour la recherche linéaire à l'aide de la boucle For

# python program for linear search using for loop

#define list
lst = []

#take input list size
num = int(input("Enter size of list :- "))

for n in range(num):
    #append element in list/array
    numbers = int(input("Enter the array of %d element :- " %n))
    lst.append(numbers)

#take input number to be find in list   
x = int(input("Enter number to search in list :- "))

i = 0
flag = False

for i in range(len(lst)):
    if lst[i] == x:
        flag = True
        break

if flag == 1:
	print('{} was found at index {}.'.format(x, i))
else:
	print('{} was not found.'.format(x))

Après l'exécution du programme, la sortie sera :

Enter size of list :-  6
Enter the array of 0 element :-  25
Enter the array of 1 element :-  50
Enter the array of 2 element :-  100
Enter the array of 3 element :-  200
Enter the array of 4 element :-  250
Enter the array of 5 element :-  650
Enter number to search in list :-  200
200 was found at index 3.

Recherche linéaire dans le programme Python à l'aide de la récursion

# python program for linear search using for loop

#define list
lst = []

#take input list size
num = int(input("Enter size of list :- "))

for n in range(num):
    #append element in list/array
    numbers = int(input("Enter the array of %d element :- " %n))
    lst.append(numbers)

#take input number to be find in list   
x = int(input("Enter number to search in list :- "))

# Recursive function to linear search x in arr[l..r]  
def recLinearSearch( arr, l, r, x): 
    if r < l: 
        return -1
    if arr[l] == x: 
        return l 
    if arr[r] == x: 
        return r 
    return recLinearSearch(arr, l+1, r-1, x) 

res = recLinearSearch(lst, 0, len(lst)-1, x) 

if res != -1:
	print('{} was found at index {}.'.format(x, res))
else:
	print('{} was not found.'.format(x))

Après l'exécution du programme, la sortie sera :

Enter size of list :-  5
Enter the array of 0 element :-  14
Enter the array of 1 element :-  25
Enter the array of 2 element :-  63
Enter the array of 3 element :-  42
Enter the array of 4 element :-  78
Enter number to search in list :-  78
78 was found at index 4.

Линейный поиск в Python

В этом посте на Python вы узнаете следующее:

  • Что такое линейный поиск?
  • Алгоритм линейного поиска
  • Напишите программу на Python для линейного поиска с использованием цикла while
  • Напишите программу на Python для линейного поиска с использованием цикла For
  • Линейный поиск в программе Python с использованием рекурсии

Что такое линейный поиск?

Прежде всего, линейный поиск, также известный как последовательный поиск, этот метод используется для поиска элемента в списке или массиве. Он проверяет каждый элемент списка один за другим / последовательно, пока не будет найдено совпадение или пока не будет выполнен поиск по всему списку.

Алгоритм линейного поиска

Реализуйте линейный поиск, выполнив следующие шаги:

  • Просмотрите список / массив, используя цикл.
  • На каждой итерации связывайте  target значение с заданным значением списка / массива.
    • Если значения совпадают, вернуть текущий индекс списка / массива.
    • В противном случае перейдите к следующему элементу массива / списка.
  • Если совпадений не найдено, вернитесь  -1.

Напишите программу на Python для линейного поиска с использованием цикла while

# python program for linear search using while loop

#define list
lst = []

#take input list size
num = int(input("Enter size of list :- "))

for n in range(num):
    #append element in list/array
    numbers = int(input("Enter the array of %d element :- " %n))
    lst.append(numbers)

#take input number to be find in list   
x = int(input("Enter number to search in list :- "))

i = 0
flag = False

while i < len(lst):
	if lst[i] == x:
		flag = True
		break

	i = i + 1

if flag == 1:
	print('{} was found at index {}.'.format(x, i))
else:
	print('{} was not found.'.format(x))

После выполнения программы вывод будет:

Enter size of list :-  5
Enter the array of 0 element :-  10
Enter the array of 1 element :-  23
Enter the array of 2 element :-  56
Enter the array of 3 element :-  89
Enter the array of 4 element :-  200
Enter number to search in list :-  89
89 was found at index 3.

Напишите программу на Python для линейного поиска с использованием цикла For

# python program for linear search using for loop

#define list
lst = []

#take input list size
num = int(input("Enter size of list :- "))

for n in range(num):
    #append element in list/array
    numbers = int(input("Enter the array of %d element :- " %n))
    lst.append(numbers)

#take input number to be find in list   
x = int(input("Enter number to search in list :- "))

i = 0
flag = False

for i in range(len(lst)):
    if lst[i] == x:
        flag = True
        break

if flag == 1:
	print('{} was found at index {}.'.format(x, i))
else:
	print('{} was not found.'.format(x))

После выполнения программы вывод будет:

Enter size of list :-  6
Enter the array of 0 element :-  25
Enter the array of 1 element :-  50
Enter the array of 2 element :-  100
Enter the array of 3 element :-  200
Enter the array of 4 element :-  250
Enter the array of 5 element :-  650
Enter number to search in list :-  200
200 was found at index 3.

Линейный поиск в программе Python с использованием рекурсии

# python program for linear search using for loop

#define list
lst = []

#take input list size
num = int(input("Enter size of list :- "))

for n in range(num):
    #append element in list/array
    numbers = int(input("Enter the array of %d element :- " %n))
    lst.append(numbers)

#take input number to be find in list   
x = int(input("Enter number to search in list :- "))

# Recursive function to linear search x in arr[l..r]  
def recLinearSearch( arr, l, r, x): 
    if r < l: 
        return -1
    if arr[l] == x: 
        return l 
    if arr[r] == x: 
        return r 
    return recLinearSearch(arr, l+1, r-1, x) 

res = recLinearSearch(lst, 0, len(lst)-1, x) 

if res != -1:
	print('{} was found at index {}.'.format(x, res))
else:
	print('{} was not found.'.format(x))

После выполнения программы вывод будет:

Enter size of list :-  5
Enter the array of 0 element :-  14
Enter the array of 1 element :-  25
Enter the array of 2 element :-  63
Enter the array of 3 element :-  42
Enter the array of 4 element :-  78
Enter number to search in list :-  78
78 was found at index 4.
CODE VN

CODE VN

1637563159

Tìm kiếm tuyến tính bằng Python

Trong bài đăng python này, bạn sẽ tìm hiểu những điều sau:

  • Tìm kiếm tuyến tính là gì?
  • Thuật toán tìm kiếm tuyến tính
  • Viết chương trình Python để tìm kiếm tuyến tính bằng While Loop
  • Viết chương trình Python để tìm kiếm tuyến tính bằng For Loop
  • Tìm kiếm tuyến tính trong Chương trình Python sử dụng Đệ quy

Tìm kiếm tuyến tính là gì?

Trước hết, Tìm kiếm tuyến tính, còn được gọi là tìm kiếm tuần tự, phương pháp này được sử dụng để tìm một phần tử trong danh sách hoặc mảng. Nó kiểm tra từng phần tử của danh sách một / tuần tự cho đến khi tìm thấy một kết quả phù hợp hoặc toàn bộ danh sách đã được tìm kiếm.

Thuật toán tìm kiếm tuyến tính

Triển khai tìm kiếm tuyến tính theo các bước sau:

  • Duyệt qua danh sách / mảng bằng cách sử dụng một vòng lặp.
  • Trong mỗi lần lặp, hãy liên kết  target giá trị với giá trị đã cho của danh sách / mảng.
    • Nếu các giá trị khớp, trả về chỉ mục hiện tại của danh sách / mảng.
    • Nếu không, hãy chuyển sang phần tử mảng / danh sách tiếp theo.
  • Nếu không tìm thấy kết quả phù hợp, hãy quay lại  -1.

Viết chương trình Python để tìm kiếm tuyến tính bằng While Loop

# python program for linear search using while loop

#define list
lst = []

#take input list size
num = int(input("Enter size of list :- "))

for n in range(num):
    #append element in list/array
    numbers = int(input("Enter the array of %d element :- " %n))
    lst.append(numbers)

#take input number to be find in list   
x = int(input("Enter number to search in list :- "))

i = 0
flag = False

while i < len(lst):
	if lst[i] == x:
		flag = True
		break

	i = i + 1

if flag == 1:
	print('{} was found at index {}.'.format(x, i))
else:
	print('{} was not found.'.format(x))

Sau khi thực hiện chương trình, kết quả đầu ra sẽ là:

Enter size of list :-  5
Enter the array of 0 element :-  10
Enter the array of 1 element :-  23
Enter the array of 2 element :-  56
Enter the array of 3 element :-  89
Enter the array of 4 element :-  200
Enter number to search in list :-  89
89 was found at index 3.

Viết chương trình Python để tìm kiếm tuyến tính bằng For Loop

# python program for linear search using for loop

#define list
lst = []

#take input list size
num = int(input("Enter size of list :- "))

for n in range(num):
    #append element in list/array
    numbers = int(input("Enter the array of %d element :- " %n))
    lst.append(numbers)

#take input number to be find in list   
x = int(input("Enter number to search in list :- "))

i = 0
flag = False

for i in range(len(lst)):
    if lst[i] == x:
        flag = True
        break

if flag == 1:
	print('{} was found at index {}.'.format(x, i))
else:
	print('{} was not found.'.format(x))

Sau khi thực hiện chương trình, kết quả đầu ra sẽ là:

Enter size of list :-  6
Enter the array of 0 element :-  25
Enter the array of 1 element :-  50
Enter the array of 2 element :-  100
Enter the array of 3 element :-  200
Enter the array of 4 element :-  250
Enter the array of 5 element :-  650
Enter number to search in list :-  200
200 was found at index 3.

Tìm kiếm tuyến tính trong Chương trình Python sử dụng Đệ quy

# python program for linear search using for loop

#define list
lst = []

#take input list size
num = int(input("Enter size of list :- "))

for n in range(num):
    #append element in list/array
    numbers = int(input("Enter the array of %d element :- " %n))
    lst.append(numbers)

#take input number to be find in list   
x = int(input("Enter number to search in list :- "))

# Recursive function to linear search x in arr[l..r]  
def recLinearSearch( arr, l, r, x): 
    if r < l: 
        return -1
    if arr[l] == x: 
        return l 
    if arr[r] == x: 
        return r 
    return recLinearSearch(arr, l+1, r-1, x) 

res = recLinearSearch(lst, 0, len(lst)-1, x) 

if res != -1:
	print('{} was found at index {}.'.format(x, res))
else:
	print('{} was not found.'.format(x))

Sau khi thực hiện chương trình, kết quả đầu ra sẽ là:

Enter size of list :-  5
Enter the array of 0 element :-  14
Enter the array of 1 element :-  25
Enter the array of 2 element :-  63
Enter the array of 3 element :-  42
Enter the array of 4 element :-  78
Enter number to search in list :-  78
78 was found at index 4.

Lineare Suche in Python

In diesem Python-Beitrag erfahren Sie Folgendes:

  • Was ist eine lineare Suche?
  • Linearer Suchalgorithmus
  • Schreiben Sie ein Python-Programm für die lineare Suche mit While-Schleife
  • Schreiben Sie ein Python-Programm für die lineare Suche mit der For-Schleife
  • Lineare Suche im Python-Programm mit Rekursion

Was ist eine lineare Suche?

Eine lineare Suche, auch bekannt als sequentielle Suche, diese Methode wird verwendet, um ein Element innerhalb einer Liste oder eines Arrays zu finden. Es überprüft jedes Element der Liste nacheinander / sequentiell, bis eine Übereinstimmung gefunden wird oder die gesamte Liste durchsucht wurde.

Linearer Suchalgorithmus

Implementieren Sie die lineare Suche mit den folgenden Schritten:

  • Durchlaufen Sie die Liste/das Array mit einer Schleife.
  • Verknüpfen Sie in jeder Iteration den  target Wert mit dem angegebenen Wert der Liste/des Arrays.
    • Wenn die Werte übereinstimmen, geben Sie den aktuellen Index der Liste/des Arrays zurück.
    • Fahren Sie andernfalls mit dem nächsten Array-/Listenelement fort.
  • Wenn keine Übereinstimmung gefunden wird, geben Sie zurück  -1.

Schreiben Sie ein Python-Programm für die lineare Suche mit While-Schleife

# python program for linear search using while loop

#define list
lst = []

#take input list size
num = int(input("Enter size of list :- "))

for n in range(num):
    #append element in list/array
    numbers = int(input("Enter the array of %d element :- " %n))
    lst.append(numbers)

#take input number to be find in list   
x = int(input("Enter number to search in list :- "))

i = 0
flag = False

while i < len(lst):
	if lst[i] == x:
		flag = True
		break

	i = i + 1

if flag == 1:
	print('{} was found at index {}.'.format(x, i))
else:
	print('{} was not found.'.format(x))

Nach der Ausführung des Programms lautet die Ausgabe:

Enter size of list :-  5
Enter the array of 0 element :-  10
Enter the array of 1 element :-  23
Enter the array of 2 element :-  56
Enter the array of 3 element :-  89
Enter the array of 4 element :-  200
Enter number to search in list :-  89
89 was found at index 3.

Schreiben Sie ein Python-Programm für die lineare Suche mit der For-Schleife

# python program for linear search using for loop

#define list
lst = []

#take input list size
num = int(input("Enter size of list :- "))

for n in range(num):
    #append element in list/array
    numbers = int(input("Enter the array of %d element :- " %n))
    lst.append(numbers)

#take input number to be find in list   
x = int(input("Enter number to search in list :- "))

i = 0
flag = False

for i in range(len(lst)):
    if lst[i] == x:
        flag = True
        break

if flag == 1:
	print('{} was found at index {}.'.format(x, i))
else:
	print('{} was not found.'.format(x))

Nach der Ausführung des Programms lautet die Ausgabe:

Enter size of list :-  6
Enter the array of 0 element :-  25
Enter the array of 1 element :-  50
Enter the array of 2 element :-  100
Enter the array of 3 element :-  200
Enter the array of 4 element :-  250
Enter the array of 5 element :-  650
Enter number to search in list :-  200
200 was found at index 3.

Lineare Suche im Python-Programm mit Rekursion

# python program for linear search using for loop

#define list
lst = []

#take input list size
num = int(input("Enter size of list :- "))

for n in range(num):
    #append element in list/array
    numbers = int(input("Enter the array of %d element :- " %n))
    lst.append(numbers)

#take input number to be find in list   
x = int(input("Enter number to search in list :- "))

# Recursive function to linear search x in arr[l..r]  
def recLinearSearch( arr, l, r, x): 
    if r < l: 
        return -1
    if arr[l] == x: 
        return l 
    if arr[r] == x: 
        return r 
    return recLinearSearch(arr, l+1, r-1, x) 

res = recLinearSearch(lst, 0, len(lst)-1, x) 

if res != -1:
	print('{} was found at index {}.'.format(x, res))
else:
	print('{} was not found.'.format(x))

Nach der Ausführung des Programms lautet die Ausgabe:

Enter size of list :-  5
Enter the array of 0 element :-  14
Enter the array of 1 element :-  25
Enter the array of 2 element :-  63
Enter the array of 3 element :-  42
Enter the array of 4 element :-  78
Enter number to search in list :-  78
78 was found at index 4.