Get Android Emulator's IP Address Using Kotlin

Azhar
Updated on 30-Nov-2020 04:20:53

429 Views

This example demonstrates how to get the Android Emulator's IP address using Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.             Step 3 − Add the following code to src/MainActivity.ktimport android.net.wifi.WifiManager import android.os.Bundle import android.widget.Button import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import android.text.format.Formatter class MainActivity : AppCompatActivity() {    lateinit var button: Button    lateinit var textView: TextView    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)     ... Read More

Pick Image from Gallery on Android Using Kotlin

Azhar
Updated on 30-Nov-2020 04:15:19

10K+ Views

This example demonstrates how to pick an image from an image gallery on Android using Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.         Step 3 − Add the following code to src/MainActivity.ktimport android.content.Intent import android.net.Uri import android.os.Bundle import android.provider.MediaStore import android.widget.Button import android.widget.ImageView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    lateinit var imageView: ImageView    lateinit var button: Button    private val pickImage = 100    private var ... Read More

Open Website in Android's Web Browser Using Kotlin

Azhar
Updated on 30-Nov-2020 04:12:09

970 Views

This example demonstrates how to open a website in Android's web browser from my application using Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.         Step 3 − Add the following code to src/MainActivity.ktimport android.content.Intent import android.net.Uri import android.os.Bundle import android.widget.Button import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)       title = "KotlinApp" ... Read More

Create Scrollable TextView on Android Using Kotlin

Azhar
Updated on 30-Nov-2020 03:53:23

2K+ Views

This example demonstrates how to create scrollable TextView on Android using Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.     Step 3 − Add the following code to src/MainActivity.ktimport androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.text.method.ScrollingMovementMethod import android.widget.TextView class MainActivity : AppCompatActivity() {    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)       title = "KotlinApp"       val textView: TextView = findViewById(R.id.textView)   ... Read More

Create Multiple Styles Inside a TextView on Android Using Kotlin

Azhar
Updated on 30-Nov-2020 03:48:01

932 Views

This example demonstrates how to create multiple styles inside a TextView on Android using Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.             Step 3 − Add the following code to src/MainActivity.ktimport android.os.Bundle import android.text.Html import android.widget.TextView import androidx.appcompat.app.AppCompatActivity @Suppress("DEPRECATION") class MainActivity : AppCompatActivity() {    private lateinit var textView: TextView    private lateinit var textView2: TextView    lateinit var textView3: TextView    override fun onCreate(savedInstanceState: Bundle?) { ... Read More

Connect to Wi-Fi Network on Android Using Kotlin

Azhar
Updated on 30-Nov-2020 03:41:30

2K+ Views

This example demonstrates how to connect to a Wi-Fi network on Android programmatically using Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.             Step 3 − Add the following code to src/MainActivity.ktimport android.content.Context import android.net.wifi.WifiManager import android.os.Bundle import android.widget.Switch import android.widget.TextView import android.widget.Toast import androidx.appcompat.app.AppCompatActivity @Suppress("DEPRECATION") class MainActivity : AppCompatActivity() {    private lateinit var wifiButton: Switch    lateinit var textView: TextView    lateinit var wifiManager: ... Read More

Best Way to Take Screenshot of a Web Page in Selenium

Debomita Bhattacharjee
Updated on 28-Nov-2020 13:58:03

325 Views

We can take screenshots of a web page with Selenium. It is a three way process. Taking a screenshot is one of the most essential steps towards defect and failure analysis.First, we have to convert the driver object to the TakeScreenshot interface.SyntaxTakesScreenshot s = (TakesScreenshot)driver;Next, we have to take the help of the getScreenshotAs method to have an image file and finally copy the file to a location with FileUtils.copyFile method.SyntaxFile src=s.getScreenshotAs(OutputType.FILE); FileUtils.copyFile(src, new File("file path"));Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; import org.apache.commons.io.FileUtils; import java.io.File; public class ScreenshotCapture{    public static void ... Read More

Execute JavaScript within a Frame using Selenium

Debomita Bhattacharjee
Updated on 28-Nov-2020 13:55:57

773 Views

We can use Javascript within a frame with Selenium. It can run Javascript commands by the executeScript method. The command to be executed is passed as an argument to the method.Next, we have to return the values from the Javascript command with the return keyword. We have to take the help of the window.length command in Javascript to count the number of frames in a page.SyntaxJavascriptExecutor j = (JavascriptExecutor) driver; int i = Integer.parseInt(j.executeScript("return window.length").toString());Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import org.openqa.selenium.JavascriptExecutor; public class FramesJS{    public static void main(String[] args) {         ... Read More

Record a Video in Selenium WebDriver

Debomita Bhattacharjee
Updated on 28-Nov-2020 13:54:20

1K+ Views

We can record a video with Selenium. There is no default technique in Selenium to record videos. The videos can be captured in the below processes−ATUTestRecorder.jar and ATUReporter_Selenium_testNG.jar files need to be downloaded and saved within the project folder.Next, add the above two jars to the project Build path. Right-click on project−> Click on Properties−> Choose Java Build Path−> Click on the Libraries tab−> Click on Add External Jars−> Browser and select the ATUTestRecorder.jar and ATUReporter_Selenium_testNG.jar−> Click on Apply−> Click OK.Have a folder to hold the videos within the project.Example@BeforeMethod public void bmethod(Method m){    // format of the date ... Read More

Select Date Picker in Selenium WebDriver

Debomita Bhattacharjee
Updated on 28-Nov-2020 13:52:45

7K+ Views

We can select the date picker in Selenium. It is slightly difficult to handle calendar controls as the day, month and year selection can be represented via different UI.Sometimes they are represented by the dropdown or by forward and backward controls. Let us select the date picker as shown below.From Date −To Date −Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import org.openqa.selenium.support.ui.Select; public class DatePicker{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver",       "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       String frdate = "20";     ... Read More

Advertisements