<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sadaniruchee on Medium]]></title>
        <description><![CDATA[Stories by Sadaniruchee on Medium]]></description>
        <link>https://medium.com/@sadaniruchee?source=rss-97c87c7a8761------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*9hr-5cIFMQ_o9duP</url>
            <title>Stories by Sadaniruchee on Medium</title>
            <link>https://medium.com/@sadaniruchee?source=rss-97c87c7a8761------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 02:00:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sadaniruchee/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Playwright : Executing automation scripts in multiple environments using dotenv package]]></title>
            <link>https://sadaniruchee.medium.com/playwright-executing-automation-scripts-in-multiple-environments-using-dotenv-package-800d643c6c73?source=rss-97c87c7a8761------2</link>
            <guid isPermaLink="false">https://medium.com/p/800d643c6c73</guid>
            <category><![CDATA[dotenv]]></category>
            <category><![CDATA[multiple-environment]]></category>
            <category><![CDATA[playwright-test]]></category>
            <category><![CDATA[playwright-automation]]></category>
            <category><![CDATA[automation]]></category>
            <dc:creator><![CDATA[Sadaniruchee]]></dc:creator>
            <pubDate>Tue, 07 Mar 2023 09:44:59 GMT</pubDate>
            <atom:updated>2023-03-10T09:11:17.472Z</atom:updated>
            <content:encoded><![CDATA[<h3>Playwright : Executing automation scripts in multiple environments using dotenv package</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JXq1sXBuBCLI_-xNuW_Crg.png" /></figure><p>When you are working on a real time project their are multiple environments like dev, stage, regression, uat etc, . All of these environments are used in different context like dev is mostly used by dev team, stage is used by testing team to test the new features deployed by dev team, regression is used by testing team to perform regression testing once the code freeze is done and so on. Lets assume daily we run our automation scripts in stage environment but after code freeze when we are in regression phase and we need to run the same scripts in regression environment. You can change the url in your code each and every time but it is not feasible to change the links each and every time when you want to run your test in different environment. What if we define our environment in one place and load the environment variables at the run time based on the environment defined?</p><p>Note: Different companies have different environment setup for a project. And the environment in which we need to run our automation test can also vary.</p><p>So, in this blog, I will share how you can execute automation scripts in multiple environments using dotenv package.</p><p><strong>What is dotenv package?</strong></p><p><strong>Dotenv</strong> is a dependency that loads environment variables from a .env file into process.env. It helps to keep your env variables like url, username, password in a separate file and load it in the run time based on the env.</p><p><strong>Pre-requisite : </strong><br>Set up playwright project if not already done. You can check my previous article <a href="https://medium.com/@sadaniruchee/playwright-with-typescript-6a64c9a66b49">Automation using Playwright and TypeScript</a> to setup and create a Playwright project. After the setup is completed we are now ready to start configuring multiple environments.</p><p><strong>How to execute automation scripts in multiple environments?</strong></p><p><strong>Approach 1:</strong></p><ol><li>Add a sample test case <br>Create a file under the test folder of your project and add a test case. I am adding a very basic test case. I am not adding a very complex test case as this is for demo purpose.</li></ol><pre>import { test, expect } from ‘@playwright/test’;<br>test(‘test’, async ({ page }) =&gt; {<br>await page.goto(‘https://www.youtube.com/&#39;);<br>await page.getByRole(‘button’, { name: ‘Guide’ }).click();<br>await page.getByRole(‘tablist’, { name: ‘Library’ }).click();<br>await expect(page).toHaveTitle(‘Library — YouTube’)<br>});</pre><p>2. Download dotenv dependency:<br>Run below command in your VS Code Terminal<br><strong><em>npm install dotenv --save</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*HCQlyUatDHNdfjRCsdXh7w.png" /></figure><p>After the installation is complete you can see a dotenv dependency got added in your package.json file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/988/1*YF4tGzf1UrdEC_OeqClqYw.png" /></figure><p>3. Create separate .env files and for all the environments like stage, uat etc. (basically all the environments in which you are going to run your automation script) and name them as <strong><em>.env.{environment}</em></strong> (ex: .env.stage for stage env see screenshot for reference). Inside the file add the test data like BASE_URL, USERNAME, PASSWORD for that particular env. and make sure that the key is same for all the environments</p><p>Note: For demo purpose, I have added stage and dev links that does not exists, so the test in these environments are going to fail, but we will print the URL to know if the correct .env file is getting picked when running the scripts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tubonkh51Bq48k1oBLEXsQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oCvxF9F1UiDCjlFZ6MifxQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iYxDmaF4dX0wJhNCZd6O6Q.png" /></figure><p>4. Create a folder util and create a env.ts file under it. Add below code</p><pre>export class environment{<br>    public static BASE_URL = process.env.BASE_URL<br>}</pre><p>NOTE: Add all the variable that you have defined in the .env files created in step 3.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n9__DcYh6OGyw-bkdY8HcQ.png" /></figure><p>5. Now create a folder util under the project and create a file named globalSetup.ts and add below code</p><pre>import { FullConfig } from &quot;@playwright/test&quot;;<br>import dotenv from &quot;dotenv&quot;<br><br>async function globalSetup(config: FullConfig) {<br> if(process.env.test_env){<br>    dotenv.config({<br>        path: `.env.${process.env.test_env}`,<br>        override: true<br>    })<br> }<br>}<br>export default globalSetup;</pre><p>Explanation of the above code</p><p>Function globalSetup is async function which checks if there is a specific test environment set in the process.env object. If there is, it loads the corresponding environment variable file using the dotenv module&#39;s config function, to which it passes an object with the path property which specifies the path of the .env file. override is set to true to override existing environment variables.</p><p>Finally, the globalSetup function is exported, which can be used by other modules. It can be used as a setup function for tests to ensure that environment variables are loaded correctly before running tests.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RH2nx7p6d6swM4jx-bfN_A.png" /></figure><p>6. Now add the global.setup.ts file path in playwright.config.ts file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bsHLgoRSAYkFBWyQyAerpQ.png" /></figure><p><strong>7. Install below command </strong><br><strong><em>npm install --save-dev cross-env</em></strong></p><p>cross-env is used to set environment variables inline when running node commands</p><p>8. Under Package.json → inside scripts key, add below line of code to set the env in which we want to run the test and also execute the test<br><strong><em> “test” : “test_env=uat npx playwright test”<br></em></strong>So, when we run our test it will pick the test_env from package.json, in this case it is uat and it will pass it to globalSetup.ts file created above in step 5</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Bp78hVlAj6Edi8rJAkKwrg.png" /></figure><p>9. Open your test file that was created in step1. We need to read the url from the .env file that we have created in step3. So we will add import statement and import the variable from the env.ts file. Below is how your code will look like</p><pre>import { test, expect } from &#39;@playwright/test&#39;;<br>import ENV from &quot;../utils/env&quot;<br>test(&#39;test&#39;, async ({ page }) =&gt; {<br>console.log(ENV.BASE_URL);<br>await page.goto(ENV.BASE_URL);<br>await page.getByRole(&#39;button&#39;, { name: &#39;Guide&#39; }).click();<br>await page.getByRole(&#39;tablist&#39;, { name: &#39;Library&#39; }).click();<br>await expect(page).toHaveTitle(&#39;Library - YouTube&#39;)<br>});</pre><p>10 To run your script run the below command <br><strong><em>npm test</em></strong></p><p>Note: For now it will run in headless mode in all the browsers because we have set the value of test to <strong><em>npx playwright test </em></strong>(see step 8 above)<strong><em>. </em></strong>If you want to run your scripts in any particular<strong><em> </em></strong>browser or headed mode you can change the test variable in package.json to any of the below and run npm test in your terminal:</p><p><strong><em>npx playwright test</em></strong> : It will run your script in headless mode in all the browsers</p><p><strong><em>npx playwright test --project={chromium}</em></strong> : To run the script in chromium browser in headless mode</p><p><strong><em>npx playwright test --project={chromium} --headed </em></strong>: To run the script in headed chromium browser</p><p>11. When you run the test you can see that the uat env variables are getting picked from env.uat file.</p><p>If we change the test_env=stage in package.json it will run the test in stage environment.</p><pre>{<br>  &quot;name&quot;: &quot;website_automation&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;description&quot;: &quot;&quot;,<br>  &quot;main&quot;: &quot;index.js&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;test&quot; : &quot;test_env=stage npx playwright test&quot;<br>  },<br>  &quot;keywords&quot;: [],<br>  &quot;author&quot;: &quot;&quot;,<br>  &quot;license&quot;: &quot;ISC&quot;,<br>  &quot;devDependencies&quot;: {<br>    &quot;@playwright/test&quot;: &quot;^1.31.1&quot;<br>  },<br>  &quot;dependencies&quot;: {<br>    &quot;dotenv&quot;: &quot;^16.0.3&quot;<br>  }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x84p6VMQPf8Iyd1CMc79GA.png" /></figure><p>Now you can see the same tests are executing but this time in stage env. This is how you can setup multiple environments.</p><p>See how simple it is to run the test in multiple environment without a single thing in your code.</p><p><strong>2nd Approach:</strong></p><p>Instead of adding separate .env files for each environment we can add just 1 file where we add all the urls and load the urls based on the environment variable value. Below if the setup for the same.</p><p>1. Download dotenv dependency:<br>Run below command in your VS Code Terminal<br><strong><em>npm install dotenv --save</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*HCQlyUatDHNdfjRCsdXh7w.png" /></figure><p>After the installation is complete you can see a dotenv dependency got added in your package.json file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/988/1*YF4tGzf1UrdEC_OeqClqYw.png" /></figure><p>2. Add config.json file in the root directory of the project and add all the environment urls. I have added 2 environments uat and stg</p><pre>{<br>    &quot;uat&quot;: {<br>        &quot;baseUrl&quot;: &quot;https://example.com/&quot;<br>},<br>    &quot;stg&quot;: {<br>        &quot;baseUrl&quot;: &quot;https://stg.example.com/&quot;<br>}<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RXPjTlbqOtzI0-GzLsZpRg.png" /></figure><p>3. Add config.ts file in the root directory of the project and add below code</p><pre>import config from &#39;./config.json&#39;;<br>import dotenv from &#39;dotenv&#39;;<br><br>dotenv.config();<br><br>export function getBaseUrl(): string {<br>    const env = process.env.environment || &#39;stg&#39;;<br>    return config[env].baseUrl;<br>}</pre><p>So basically what this code will do is it imports the dotenv module and then calls its config method to load environment variables either from a .env file in the root directory of the project or you can add the environment variable directly in package.json file. The dotenv module allows to store configuration data in environment variables rather than hard-coding them into the code, which makes it easier to manage sensitive data and to configure the application for different environments.</p><p>Then the code exports a function called getBaseUrl(). This function reads the value of an environment variable called environment using the process.env object. If the environment variable is not set, the default value is stg. The function then returns the value of the baseUrl property.</p><p>As mentioned above you can either create a separate .env file and save the environment their like below screenshot</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ul6dVbbsmK5JmxC3QJKydw.png" /></figure><p>Or you can add the environment directly in package.json like below screenshot. In this case you don’t have to add a separate .env file for storing the environment value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VzglWyKf2SGKEBDXTD8Nyg.png" /></figure><p>4. Now, in your test case you can add a import statement for config.ts file and you can call the getBaseUrl method created above in step 3</p><pre>import { test, expect } from &#39;@playwright/test&#39;;<br>import { getBaseUrl}  from &#39;../../config.ts&#39;;<br><br>export class LoginPage{<br>test(&#39;test&#39;, async ({ page }) =&gt; {<br>await page.goto(getBaseUrl());<br>await page.getByRole(&#39;button&#39;, { name: &#39;Guide&#39; }).click();<br>await page.getByRole(&#39;tablist&#39;, { name: &#39;Library&#39; }).click();<br>await expect(page).toHaveTitle(&#39;Library - YouTube&#39;)<br>});</pre><p>Now we are done with the configuration. Run the test, you will see the stg environment url is loaded during test execution.</p><p>If you want to run the same test in uat environment using any of the above approach just replace stg with uat and that’s it when we run the script you will see the uat environment url is loaded.</p><p>See, how simple it is to run your test in multiple environments!!!</p><p>I hope you liked the article and thanks for reading!!</p><p>Pervious article: <a href="https://medium.com/@sadaniruchee/playwright-with-typescript-6a64c9a66b49">Automation using Playwright and TypeScript</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=800d643c6c73" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automation using Playwright and TypeScript]]></title>
            <link>https://sadaniruchee.medium.com/playwright-with-typescript-6a64c9a66b49?source=rss-97c87c7a8761------2</link>
            <guid isPermaLink="false">https://medium.com/p/6a64c9a66b49</guid>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[playwright-automation]]></category>
            <category><![CDATA[playwright-test]]></category>
            <category><![CDATA[automation-testing]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Sadaniruchee]]></dc:creator>
            <pubDate>Fri, 24 Feb 2023 12:54:24 GMT</pubDate>
            <atom:updated>2023-02-28T05:12:23.590Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k3Di9uoEgpeWrVR6YvbWxw.png" /></figure><p>Hello Friends, In this blog I will share what is Playwright and its features. We will also set up Playwright on our machine and we will use Playwright with Typescript.</p><ul><li>Playwright is free open-source framework developed by Microsoft.</li><li>It can be used to automate tests in web browser applications i.e. both desktop browsers as well as mobile browsers. And it also supports API testing.</li><li>Languages supported: JavaScript, TypeScript, Java, Python, .NET(C#).</li><li>Browsers supported: Chromium(Chrome, Edge, Opera and many more), WebKit(Safari), and Firefox. You can use these browsers in headless or headed mode</li><li>It supports multiple Operating System like Windows, MacOS, Linux</li><li>Supports CI/CD tools like GitHub Actions, Docker, Azure Pipelines, Jenkins, and many more</li></ul><p><strong>Features:</strong></p><ul><li>Easy setup and configuration</li><li>Test Execution is very fast</li><li>It can be used for Functional/API/Accessibility testing</li><li>It provides Built-in reporters like HTML reporter, JSON reporter, List reporter, Line reporter, and JUnit reporter or you can also create Custom Reporters like <a href="https://www.npmjs.com/package/allure-playwright">Allure</a> , <a href="https://github.com/cenfun/monocart-reporter">Monocart</a>, <a href="https://www.tesults.com/docs/playwright">Tesults</a>, <a href="https://github.com/reportportal/agent-js-playwright">ReportPortal</a></li><li>You can record your test and get your test scripts generated. Step by step Debugging is also possible. Also, we can capture the object locators from the screen.</li><li>We can perform Parallel testing. We can run test cases at the same time on different browsers which makes it even faster.</li><li>Auto wait and auto timeout of 5 seconds is provided by Playwright and we can change them as well. Also, it provides built-in assertions which altogether make tests less flaky or even no flaky tests.</li><li>It provides options to Retry failed tests, View and generate logs, options to take screenshots and videos.</li><li>It provides good support for Multi-tab and Multi-window test execution.</li><li>It supports iFrames/Shadow DOM objects</li><li>It can emulate mobile devices, and we can change the geolocations</li><li>We can parameterize our tests i.e. we can use variables, Data driven testing, also we can use an external file like a CSV file to get our test data</li></ul><p><strong>Setup Playwright with Typescript</strong></p><blockquote><strong><em>1. Download Node</em></strong></blockquote><p>Before starting to download node you can check if node is already installed in your system by running below commands in your terminal <br><strong><em>node -v<br>npm -v <br></em></strong>If you have node installed in your system it will return the version number.</p><p>If you don’t have node installed in your system, you can follow below steps. <br>You can download node from their official website <a href="https://nodejs.org/en/download/">https://nodejs.org/en/download/</a> based on the Operating system you are working on.</p><p>For mac install macOS Binary(.pkg)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PcjJRnoI_y7Y9g33" /></figure><p>For windows install Windows Installer (.msi) 32/64 bit based on your system configuration. After the download is done install node in your system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NTcOMOwyf1mqkXQ6" /></figure><p>Once the download is completed double click on the package and it will install the node in your system</p><p>To verify if node is successfully installed on your system open the terminal and run command <strong><em>node -v</em></strong>. You will be able to see the node version that was installed, in my case it is v18.14.0. To see the npm version run command <strong><em>npm -v </em></strong>You will be able to see the npm version that was installed, in my case it is 9.3.1</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/542/1*VTmrLWrartsWfgkmKkA4SA.png" /></figure><blockquote><strong><em>2. Download VS Code IDE</em></strong></blockquote><p>You can download VS Code from their official website:<br><a href="https://code.visualstudio.com/download">https://code.visualstudio.com/download</a> based on the Operating system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*buZiUL2SJUHTZfV5ZUTzGg.png" /></figure><blockquote><strong><em>3. Install Playwright</em></strong></blockquote><p><strong>You can install playwright in 2 ways:<br> </strong><br><strong><em>3.1 Install playwright as npm package</em></strong></p><ul><li>Create a new folder, in my case I have created a folder named Playwright although you can name it anything.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/470/1*SalAm19sjy1Z0MhV0DHynw.png" /></figure><ul><li>Now open this folder in Visual Studio Code. To open the folder click on File → Open Folder → Navigate to the folder that you created and Open the folder</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0PMCUIlF1CSWxtV4fwtCPQ.png" /></figure><ul><li>After you open this folder the alert box will be prompted click on “Yes, I trust the Authors”. You will see the folder will get opened on VS Code</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AxBbuWCsHQkHnrwieBWqqw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TQCk4OS191uIdQCUhC6xdQ.png" /></figure><ul><li>Open Terminal in VS Code. To Open the terminal click on Terminal in the top menu bar and click on New Terminal. A terminal will be opened at the bottom</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9UNLRzwbU5fqwTRoyiKLyg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z2H9Nsu_BM66VNRx52yLPw.png" /></figure><ul><li>Go to the terminal and run the command : <br><strong><em>npm init playwright@latest</em></strong></li></ul><p>After you run this command it will ask you 4 things:<br>1. Do you want to use Typescript or JavaScript? → I am using typescript. If you want to use Javascript press the arrow key and click Enter<br>2. Where to put your end-to-end tests? → Its a free-form text you can name it anything. I have named it tests<br>3. Add a GitHub Actions workflow? → Press y if you want to add it and enter<br>4. Install Playwright browsers (can be done manually via ‘npx playwright install’)? (Y/n) → Press Y if you want to install playwright browsers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YrAC7PzTyhHiEe8dlrFS2A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Iy4nSqgg6CyhzTN54188Mg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ycbg-CnqPcA4AHXTRGkmvw.png" /></figure><ul><li>Wait for the installations to get finished. After the installation is done on Explorer, on left-hand side, you can see the project structure/folders have been created</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QK3-oAQhxTdnoTjHGSo1lQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*6ZAU8OhnkZnsCw426PC2Xg.png" /></figure><ul><li>Check the playwright version by running the following command <br><strong><em>npm playwright -v</em></strong></li><li>You can also check all the options which we can use with playwright commands <br><strong><em>npx playwright --help</em></strong></li></ul><p><strong>How to run the test?</strong></p><p>To run the test run the below command in VS Code Terminal <br><strong><em>npx playwright test</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zPsj8AWMqCOJ31L8Uwfm7A.png" /></figure><p>After the run is successful you can view report using below command <br><strong><em>npx playwright show-report</em></strong></p><p><strong><em>3.2 Install playwright using VS Code extension:</em></strong></p><ul><li>Create a new folder, in my case I have created a folder named Playwright_VSCode_Extension although you can name it anything.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*GzKW5_0MVEO1F288PNorGQ.png" /></figure><ul><li>Open the folder in Visual studio code File → Open Folder → Navigate to the folder that you created and open the folder.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0PMCUIlF1CSWxtV4fwtCPQ.png" /></figure><ul><li>After you open this folder an alert box will be prompted click on “Yes, I trust the Authors”. You will see the folder will get opened on VS Code</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Eobuj08oVVcCn6iWUSt7kA.png" /></figure><ul><li>Go to the Extensions section and type Playwright and install the playwright extension from Microsoft</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HOv7_ESekwomfNoe0L7yYQ.png" /></figure><ul><li>Go to view → Command Palette</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8Jjxywh_XFwqqMo70eEPoQ.png" /></figure><ul><li>Type playwright test and select all the options that you need to install along with Playwright and click on “OK”. You can see in the terminal it is downloading all the commands that we downloaded through the terminal in the 3.1 section of this article.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HOv7_ESekwomfNoe0L7yYQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WcbYHSCCNMn3Wh2zCsP2Og.png" /></figure><ul><li>You can see that the project structure/folder has been created in Explorer</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tZRtg3PIzKstwe8u7i9xyg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/1*QHCDOHFuh7rQqPOhG9BQ8Q.png" /></figure><p>The main advantage of following 2nd approach i.e. <strong><em>installing</em></strong> <strong><em>playwright using VS Code extension </em></strong>is that we get nice UI to perform all the actions like run the test, debug the test, refresh options that we normally do from command line</p><p><strong>How to run the test ?</strong></p><ul><li>Go to view → Command Palette</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8Jjxywh_XFwqqMo70eEPoQ.png" /></figure><ul><li>Type <strong><em>Playwright</em></strong>, you will get an option for “Testing: Focus on Playwright view” a Test Explorer view will be opened with all the tests.</li><li>Now click on the “Go to Test” icon, the respective file will be opened on the left-hand side, and then click on the run icon, on the right-hand side you can see as the test runs each step is getting highlighted and you can also see the time taken to run that particular test.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x0nvk8kGciKk_kLd_0XnJA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*etVWcCMrAC9Yg2cEA9nZ-w.png" /></figure><p>Yay! Now we have successfully configured Playwright project in our system. In my next article, we will get started with writing our first Playwright script</p><p><strong>Note : You can run/debug your tests using Playwright VSCode Extension regardless of whether you have installed Playwright via extension or via command line.</strong></p><p>I hope you liked the article and thanks for reading!!</p><p><strong>Reference links:</strong></p><p><a href="https://playwright.dev/"><strong>https://playwright.dev/</strong></a></p><p><a href="https://github.com/microsoft/playwright"><strong>https://github.com/microsoft/playwright</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a64c9a66b49" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[iOS App Automation on Mac using Appium]]></title>
            <link>https://sadaniruchee.medium.com/ios-app-automation-on-mac-using-appium-60ab375bd08c?source=rss-97c87c7a8761------2</link>
            <guid isPermaLink="false">https://medium.com/p/60ab375bd08c</guid>
            <dc:creator><![CDATA[Sadaniruchee]]></dc:creator>
            <pubDate>Thu, 02 Feb 2023 09:13:21 GMT</pubDate>
            <atom:updated>2023-02-02T09:29:23.508Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bX1nvrEihm-m7ysvd-qyow.png" /></figure><p>In my previous article I have shared how we can create our mobile automation scripts for android apps, to check out the article <a href="https://medium.com/@sadaniruchee/run-your-1st-appium-script-b3352d0febbe">click here</a>. In this article, I will share how to automate iOS Apps on Mac.</p><blockquote><strong>1. Download the Appium server</strong></blockquote><ul><li>On your terminal run the below command :<br><strong><em>sudo</em></strong> <strong><em>npm install -g appium@next</em></strong></li><li>Provide your system password(if prompted) and this will help you to install appium.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G41K4I3VFjGVByRTs8bXjg.png" /></figure><ul><li>To make sure it is installed in your system type the below command<br><strong><em>appium<br></em></strong>This command will give you logs just like the below screenshot and that’s what confirms that your appium is installed correctly</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_YkW-vM6xGdRj21ONM-wBQ.png" /></figure><blockquote><strong>2. Install XCode</strong></blockquote><p>To download XCode go to their official website <a href="https://developer.apple.com/xcode/resources/">https://developer.apple.com/xcode/resources/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1XgxGKBZtdRbOIqenDkGHA.png" /></figure><p>Why do we need XCode ?</p><p>To automate app in iPhone you need to compile the app(.xcodeproj file) compatible to the iPhone and iOS version which you are using and then use that compiled app for automation. So, the role of XCode is to compile the app in the simulator suitable to the iPhone and iOS version.</p><blockquote><strong>3. Clone Sample project for iOS app automation</strong></blockquote><p>Clone uicatalog app from <a href="https://github.com/appium/ios-uicatalog">https://github.com/appium/ios-uicatalog</a> location. This is a simple test application for iOS, used by Appium for certain tests, we will use this app in this article.</p><blockquote><strong>4. Open the .xcodeproj file in your Xcode.</strong></blockquote><ul><li>So to find this file open the uicatalog app that we cloned in the above step, then open UIKitCatalog folder, and you will find UIKitCatalog.xcodeproj file inside it . Now go ahead and click on this file and it will be opened in Xcode.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L2Occ1mXhwZeEzf02A52nw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s4ErN9OeykefAPhfiOVyjw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bb6FKV568a1n8ukX6Y2BOA.png" /></figure><ul><li>Now, under your Products folder you will find the .<strong>app</strong> file. This file is the app that we need to install in our simulator for automation.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G-_Nn9fOpGymbSACcU0zlg.png" /></figure><ul><li>So, to get the compiled app for your respective simulator, click on UIKitCatalog on top and select the iPhone that you want the app to be automated into.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rYPxu55xlNjpTL8YW1M2Yg.png" /></figure><ul><li>In my case I am using iPhone12, iOS version 16.2. Then click on Run symbol.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r-H_0HH_-o5LmI0gd9WKaA.png" /></figure><ul><li>Once this app is compiled and installed it will open the iPhone simulator that you have selected in above steps.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*dD3GR2JfrDUZPWvReeSASQ.png" /></figure><blockquote><strong>5. Install xcuitest driver on your laptop</strong></blockquote><p>For iOS we need xcuitest driver. To install xcuitest driver run the below code in your terminal :<br><strong><em>appium driver install xcuitest </em></strong>— This command will install xcuitest<br><strong><em>appium driver list </em></strong>— This command will show you all the list of drivers and whether they are installed or not</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Sqo7EeuFHXqPkrHqNZj_FQ.png" /></figure><blockquote><strong>6. Setting Desired capabilities in your code</strong></blockquote><p>Below is the code snippet for the setting the desired capabilities</p><pre>public class IOSAutomation {<br>@Test<br>public void AppiumTest() throws MalformedURLException {<br>//Starting Appium server Programmatically<br>AppiumDriverLocalService service = new AppiumServiceBuilder().withAppiumJS(new File(&quot;//usr//local//lib//node_modules//appium//build//lib//main.js&quot;))<br>.withIPAddress(&quot;127.0.0.1&quot;).usingPort(4723).build();<br>service.start();<br>//Create object of XCUITestOptions<br>XCUITestOptions options = new XCUITestOptions();<br>//Device Name<br>options.setDeviceName(&quot;iPhone 12&quot;);<br>options.setApp(&quot;Location_of_UIKitCatalog.app&quot;);<br>//Version of iOS in which we are automating<br>options.setPlatformVersion(&quot;16.2&quot;);<br>//Wait - because in ios,webdriver agent will first install in your phone and this will further lets you automate ios apps, however in android it is not required<br>options.setAvdLaunchTimeout(Duration.ofSeconds(20));<br>//Create object of iOS driver<br>IOSDriver driver = new IOSDriver(new URL(&quot;http://127.0.0.1:4723&quot;), options);<br>//Stop the Appium Server<br>service.stop();<br>driver.quit();<br>}<br>}</pre><p>Now lets understand what exactly the above code is doing</p><ul><li>Before starting your execution you need to start appium, so this can be done in 2 ways :</li></ul><ol><li>You can manually start your server in terminal with command <strong><em>appium. </em></strong>However this will create an issue if you are running your scripts in CI/CD pipeline</li><li>Or you can start the server programatically. To trigger appium server programmatically, appium has provided AppiumServiceBuilder class, we need to give the path of main.js and tell the server on which IP and which port do we need to run the server. You can find main.js in below location:<br><strong><em>MAC:<br>/usr/local/lib/node_modules/appium/build/lib/main.js</em></strong></li></ol><pre>AppiumDriverLocalService service = new AppiumServiceBuilder().withAppiumJS(new File(“//usr//local//lib//node_modules//appium//build//lib//main.js”))<br>.withIPAddress(“127.0.0.1”).usingPort(4723).build();<br>service.start();</pre><ul><li>Create object of XCUITestOptions which is used for providing all the information related to device name, app, platform version to start automation of app in specified device and iOS version.<br><strong><em>XCUITestOptions options = new XCUITestOptions();</em></strong></li><li>Now we are passing all the information about app, device name, platform version in the object created above. The app location should be the location of the compiled file for the device that you are using. To get the compiled file first click on run, then click on UIKitCatalog file under products, on the right side you can see the location of the file. You can give this location in your setApp capabilities or you can copy this .app file and paste it under your project in resource folder.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b57uvw9yqjaqIu8IKUPvxA.png" /></figure><ul><li>We need to set the iOS version, and this version can be found at the top in the simulator opened. In my case it is <strong><em>16.2</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/1*JVkJNjgvT4P0nhZBD72cfg.png" /></figure><ul><li>We need to give wait because in iOS, Webdriver Agent will first get installed in your iPhone before running your script and this Webdriver Agent will then let you automate iOS apps.<br><strong><em>options.setAvdLaunchTimeout(Duration.ofSeconds(20));</em></strong></li><li>We will create object of IOSDriver, which is specifically used for automating IOS devices.<br><strong><em>IOSDriver driver = new IOSDriver(new URL(“http://127.0.0.1:4723&quot;), options);</em></strong></li><li>We will stop the appium server.<br><strong><em>service.stop();</em></strong></li></ul><blockquote><strong>6. Setting Desired capabilities in your Appium Inspector</strong></blockquote><ul><li>In order to locate the elements we need to download Appium Inspector which is developed by appium. Download Appium Inspector from <a href="https://github.com/appium/appium-inspector/releases">https://github.com/appium/appium-inspector/releases</a></li><li>Appium supports the following locators for IOS: id, accessibility Id, XPath, classname, IOS, iosClassChain, iosPredicateString.</li><li>Open a terminal and start the appium session by giving command <strong><em>appium</em></strong></li><li>Open Appium Inspector</li><li>Now in order for Appium Inspector to open the app we need to set the desired capabilities like location of the app, automation name, device name, platform name, platform Version in appium inspector as shown in below screenshot. Add Name and value of the capability. You can click on + to add more capabilities and then click on start session. Below are the screenshots for the same<br>Note: Make sure before before clicking on Start Session appium should be up and running in your terminal</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WyGfHdn0zIPXvsZx.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dd6gCLiikab1o1w5zaA1IQ.png" /></figure><ul><li>A window will open where you will see the app and on the right side, you will see the locators that the developer has defined.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V7N_ET66d_8lEebql4o-6w.png" /></figure><ul><li>In order to find locators of any WebElement, click on the WebElement and you will find all the locators defined for that WebElement on Right-hand side.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mWrmpxt2gxPd2TF8r7zhzQ.png" /></figure><blockquote>7. Run and verify if the above setup is working as expected</blockquote><p>Let&#39;s try to click on Buttons when we open this app. So, to click on Buttons we are using its accessibility id. Below is the code for the same</p><p><strong><em>driver.findElement(AppiumBy.accessibilityId(“Buttons”)).click();</em></strong></p><pre>public class IOSAutomation {<br>@Test<br>public void AppiumTest() throws MalformedURLException {<br>//Starting Appium server Programmatically<br>AppiumDriverLocalService service = new AppiumServiceBuilder().withAppiumJS(new File(“//usr//local//lib//node_modules//appium//build//lib//main.js”))<br>.withIPAddress(“127.0.0.1”).usingPort(4723).build();<br>service.start();<br>//Create object of iOS driver<br>XCUITestOptions options = new XCUITestOptions();<br>//Device Name<br>options.setDeviceName(“iPhone 12”);<br>options.setApp(“Location_of_UIKitCatalog.app”);<br>//Version of iOS in which we are automating<br>options.setPlatformVersion(“15.0”);<br>//Wait — because in ios,webdriver agent will first install in your phone and this will further lets you automate ios apps, however in android it is not required<br>options.setAvdLaunchTimeout(Duration.ofSeconds(20));<br>IOSDriver driver = new IOSDriver(new URL(“http://127.0.0.1:4723&quot;), options);<br>//Click on Buttons<br>driver.findElement(AppiumBy.accessibilityId(&quot;Buttons&quot;)).click();<br>//Stop the Appium Server<br>service.stop();<br>driver.quit();<br>}<br>}</pre><p>Now run the above class by right-clicking on the class and select Run as “TestNG Test” and open and simulator. You will see WebDriverAgent will be downloaded on your iOS device, then the app will be opened and it clicks on Buttons.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/884/1*V3Jq6fbe6ROhn0LoFOPQrQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Bvcioefen5_30to9SapHMw.png" /></figure><p>For practice purposes you can use this app to automate test cases.</p><p>I hope you liked the article and thanks for reading!!</p><p>Previous articles:</p><p><a href="http://Appium Setup - Step by Step Guide for Mac/Windows">Appium Setup — Step by Step Guide for Mac/Windows</a></p><p><a href="https://medium.com/@sadaniruchee/run-your-1st-appium-script-b3352d0febbe">Writing your First Appium E2E test for Android devices</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60ab375bd08c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create and Run your First Appium Script in Android devices]]></title>
            <link>https://sadaniruchee.medium.com/run-your-1st-appium-script-b3352d0febbe?source=rss-97c87c7a8761------2</link>
            <guid isPermaLink="false">https://medium.com/p/b3352d0febbe</guid>
            <dc:creator><![CDATA[Sadaniruchee]]></dc:creator>
            <pubDate>Wed, 04 Jan 2023 06:20:04 GMT</pubDate>
            <atom:updated>2023-02-02T09:11:07.619Z</atom:updated>
            <content:encoded><![CDATA[<h3>Writing your First Appium E2E test for Android devices</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cnJq_Ygb4iToGw_GZDeJNw.png" /></figure><p>Hi guys welcome again, in my previous blog I have shown how to do appium setup for virtual devices, so if you have not already done the setup please click this <a href="https://medium.com/@sadaniruchee/appium-setup-step-by-step-guide-for-mac-windows-db05acbf4617"><strong>link</strong></a> to do the setup as this is the prerequisite for running appium scripts. So in this blog we will write our first mobile automation script in Android devices using Appium.</p><ol><li>Open Eclipse and create a new Maven project</li><li>In your new Maven project screen we need to select Artifact id as <strong><em>maven-archetype-quickstart</em></strong> and click on next</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*e6MSkjgfRSqriBGJ" /></figure><p>3. Add GroupId and Artifact Id. <br>Group Id: &lt;Package name&gt;, Artifact id: &lt;Project Name&gt; and click on finish</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wtFr5FoyN5MhgV6P" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*g6GZbZEbGV5XUFVD" /></figure><p>4. Once you finish the setup the project structure will look something like below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*A4gGeZ66LSOB64Uc" /></figure><p>5. Go to mvnrepository.com and search for appium Java client library and copy the dependency and paste it in pom.xml file</p><pre>&lt;! — https://mvnrepository.com/artifact/io.appium/java-client --&gt;<br>&lt;dependency&gt;<br>&lt;groupId&gt;io.appium&lt;/groupId&gt;<br>&lt;artifactId&gt;java-client&lt;/artifactId&gt;<br>&lt;version&gt;8.3.0&lt;/version&gt;<br>&lt;/dependency&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jAPbnWSrfWWca2Ed" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ludmUp3A3p-ehJCg" /></figure><p>6. In this particular blog we will be using the TestNG framework, so we will be using the TestNG maven repository dependency and adding it to our project in the same way as we did for the Java client above.</p><pre>&lt;! — https://mvnrepository.com/artifact/org.testng/testng --&gt;<br>&lt;dependency&gt;<br> &lt;groupId&gt;org.testng&lt;/groupId&gt;<br> &lt;artifactId&gt;testng&lt;/artifactId&gt;<br> &lt;version&gt;7.7.0&lt;/version&gt;<br> &lt;scope&gt;test&lt;/scope&gt;<br>&lt;/dependency&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qbrkJ5aXbe3RQg4E" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FfQXQXzrCMYNgzHd" /></figure><p>7. Then save pom.xml file and wait for the project to be built completely. All the dependencies will be downloaded and their will be a folder called Maven Dependencies in your project and you can see all the dependencies downloaded in your folder</p><p>8. In eclipse Go to Help → Eclipse marketplace and search for TestNG and install TestNG for Eclipse plugin</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*j78XDm2si87vvO_9" /></figure><p>9. Once the installation is completed you will be asked to restart your eclipse.</p><p>10. Install the drivers for android and iOS.</p><p>On your terminal type below commands:</p><ul><li><strong><em>appium driver list </em></strong>— This command will show you all the list of drivers and whether they are installed or not</li><li><strong><em>appium driver install uiautomator2 — </em></strong>This command will install ui automator2 driver</li><li><strong><em>appium driver install xcuitest </em></strong>— This command will install xcuitest</li></ul><p>Similarly you can install other drivers. See below screenshot for your reference</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/956/0*PSmInod7hdy7-adf" /></figure><p>11. Open Android Studio and Configure Emulator</p><p><strong>Note</strong>: We have already configured this in my previous <a href="https://medium.com/@sadaniruchee/appium-setup-step-by-step-guide-for-mac-windows-db05acbf4617">article</a>. You can skip this step if you have already configured android studio.</p><ul><li>Open Android Studio</li><li>Click on New project → Select Basic Activity → Click on next → Click on Finish and wait until the whole project is loaded and built</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hWrhJPMapGfo7Cm9.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aKc7dhdhzFjRhJnc.png" /></figure><ul><li>Go to Tools → Device Manager</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CFyXMR17ecis4i4s.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JUqrPcgrl_OhKrBS.png" /></figure><ul><li>Click on Create device and select the device which you want to use for automation and click on next and download the system image(download the system image compatible with the apk file otherwise your script will fail) and wait for it to get downloaded, once its downloaded select the same system image and Click on Next , then set the AVD name (you can set any name) and click Finish</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CG_oeVGa4cxeyoL9.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*J7M9VHYv2aIqWibI.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LGMy-QUgZPHkxQK0.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*41JT_T6GIW_3hAlaWk19-w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5cohdQ72nkJjzGOQ.png" /></figure><p>12. Now go to the project created in eclipse</p><ul><li>Under src/test/java create a new folder called resource and add the apk file of the app that you want to automate. You can download ApiDemos-debug.apk file from following location <a href="https://github.com/appium-boneyard/sample-code/blob/master/sample-code/apps/ApiDemos/bin/ApiDemos-debug.apk">https://github.com/appium-boneyard/sample-code/blob/master/sample-code/apps/ApiDemos/bin/ApiDemos-debug.apk</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*d_nqVlZPWS-UP96HhDpswQ.png" /></figure><ul><li>Under src/test/java create a new class named AppiumBasics</li><li>Create a method with @Test annotation</li></ul><pre>@Test<br>public void AppiumTest() throws MalformedURLException {<br>//Create object of Android driver<br>UiAutomator2Options options = new UiAutomator2Options();<br>//Device Name<br>options.setDeviceName(&quot;RucheeTest&quot;);<br>//Which App<br>options.setApp(&quot;Your apk file location&quot;);<br>//Create an instace of android driver <br>AndroidDriver driver = new AndroidDriver(new URL(&quot;http://127.0.0.1:4723&quot;), options);<br>}</pre><ul><li>You need to create an object of Android/iOS driver and this driver will help you automate android/iOS device respectively, for this blog we will use Android driver.</li><li>The AndroidDriver takes 2 argument, the 1st argument is the url where your appium server is running and 2nd argument is Capabilities to setup parameters like — Which platform you want to use iOS/Android, Version number, Device name, information about your app. In the above code we have set 2 capabilities Device name and apk file path</li><li>Go to your terminal and start the appium server by writing the following command: <strong><em>Appium. </em></strong>Now go to eclipse and run the class by right clicking on the class and select run as TestNG Test. Now go to android studio and check if the app was launched or not. For me the app below got launched.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/0*1YugU3c4E5ucZL6N" /></figure><p>Note: For demo purpose we are going to automate test case for changing the Wifi name of the above app</p><p>13. How to inspect elements through Appium Inspector ?</p><ul><li>After running the script that we created above for the 1st time, the app will be installed in the emulator. In order to locate the elements we need to download Appium Inspector which is developed by appium. Download Appium Inspector from <a href="https://github.com/appium/appium-inspector/releases">https://github.com/appium/appium-inspector/releases</a></li><li>Appium supports following locators Xpath, id, accessibilityId, class name and androidUIAutomator.</li><li>Open terminal and start the appium session by giving command <strong><em>appium</em></strong></li><li>Open Appium Inspector</li><li>Now in order for Appium Inspector to open the app we need to set the desired capabilities like device name, platform name, app, driver(android/iOS) in appium inspector as shown in below screenshot. Add Name and value of the capability. You can click on + to add more capabilities</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8sMFqL2OC3T7p_UTAYQysQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*s4ibnTSj22PYNQJ5" /></figure><ul><li>Click on Start Session</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YzYEeenq_E4kizaFxwOZOQ.png" /></figure><ul><li>A window will open where you will see the app and on right hand side you will see the locators which developer have defined. In order to see the properties of any element click on the element.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7NriuTCa2471SNbl" /></figure><ul><li>In order to find locators of Preference, click on it and you will find all the locators defined for Preference on right hand side. Below is the line of code that will click on Preference. Run the script and you will see that Preference is getting clicked</li></ul><p>//Click on Preference<br><strong><em>driver.findElement(AppiumBy.accessibilityId(“Preference”)).click();</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HZ5SPg76zydYghofnd_fog.png" /></figure><p>14. How to start and stop appium server Programmatically using AppiumServiceBuilder?</p><p>When we are running our test cases through CI/CD it is not possible to start the appium server before each execution manually. So, we will write a code that will start and stop the appium server programmatically and you don’t have to run the appium command from the command line before each execution. To trigger appium server programmatically, appium has provided AppiumServiceBuilder class, to this class we need to give the path of main.js and tell the server on which IP and which port do we need to run the server. You can find main.js in below locations:</p><p><strong><em>Windows: <br>C:\Users\Hp\AppData\Roaming\npm\node_modules\appium\build\lib\main.js</em></strong></p><p><strong><em>MAC:<br>/usr/local/lib/node_modules/appium/build/lib/main.js</em></strong></p><pre>//Starting Appium server Programmatically<br>AppiumDriverLocalService service = new AppiumServiceBuilder().withAppiumJS(new File (&quot;//usr//local//lib//node_modules//appium//build//lib//main.js&quot;))<br>.withIPAddress(&quot;127.0.0.1&quot;).usingPort(4723).build();<br>service.start();<br><br>//Stop the Appium Server<br>service.stop();</pre><p>So your code will look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JlMFWlVZHI8MM6oD" /></figure><p>Now run the above class by right clicking on the class and select Run as “TestNG Test” and open Android Studio. You will be able to see that the app has opened on the device and clicked on Preference. So lets automate the test case where you will click on Preference &gt; Click on Preferences Dependencies &gt; Click on Wifi checkbox &gt; Click on Wifi Settings &gt; Assert if WiFi settings title is displayed &gt; Enter the Wifi name &gt; Click on Ok button. So below is the code for the same.</p><pre>public class AppiumBasics {<br>@Test<br>public void AppiumTest() throws MalformedURLException {<br>//Starting Appium server Programmatically<br>AppiumDriverLocalService service = new AppiumServiceBuilder().withAppiumJS(new File(&quot;//usr//local//lib//node_modules//appium//build//lib//main.js&quot;))<br>.withIPAddress(&quot;127.0.0.1&quot;).usingPort(4723).build();<br>service.start();<br>//Create object of Android driver<br>UiAutomator2Options options = new UiAutomator2Options();<br>//Device Name<br>options.setDeviceName(&quot;RucheeTest&quot;);<br>//App<br>options.setApp(&quot;//Users//rucheesadani//Desktop//Appium Project//Appiumtests//src//test//java//resources//ApiDemos-debug.apk&quot;);<br>//Initializing the driver<br>AndroidDriver driver = new AndroidDriver(new URL(&quot;http://127.0.0.1:4723&quot;), options);<br>//Click on Preference<br>driver.findElement(AppiumBy.accessibilityId(&quot;Preference&quot;)).click();<br>//Click on Preference dependencies <br>driver.findElement(By.xpath(&quot;//android.widget.TextView[@content-desc=’3. Preference dependencies’]&quot;)).click();<br>//Click on Wifi checkbox <br>driver.findElement(By.id(&quot;android:id/checkbox&quot;)).click();<br>//Click on Wifi Settings <br>driver.findElement(By.xpath(&quot;(//android.widget.RelativeLayout)[2]&quot;)).click();<br>//Asserting if Wifi settings title is displayed or not<br>String wifiTitle= driver.findElement(By.id(&quot;android:id/alertTitle&quot;)).getText();<br>//Type the Wifi name<br>driver.findElement(By.id(&quot;android:id/edit&quot;)).sendKeys(&quot;Test Wifi&quot;);<br>//Click on Ok button <br>driver.findElement(By.id(&quot;android:id/button1&quot;)).click();<br>//Stop the Appium Server<br>service.stop();<br>driver.quit();<br>}<br>}</pre><p>Now run the above class by right clicking on the class and select Run as “TestNG Test” and open Android Studio, you will see the test is getting passed successfully. You can also add selenium waits if your script is failing, in my case it was failing on windows machine and after adding waits the test case was passed successfully. Now you have created your first Appium script. For practice purpose you can automate more test cases similarly.</p><p>I hope you liked the article and thanks for reading!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b3352d0febbe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Appium]]></title>
            <link>https://sadaniruchee.medium.com/appium-a82226186de?source=rss-97c87c7a8761------2</link>
            <guid isPermaLink="false">https://medium.com/p/a82226186de</guid>
            <dc:creator><![CDATA[Sadaniruchee]]></dc:creator>
            <pubDate>Tue, 20 Dec 2022 07:57:42 GMT</pubDate>
            <atom:updated>2023-01-07T15:21:59.894Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t07XwbJwgX5v1cO8-_mk5g.png" /></figure><p><strong>What is Appium?</strong></p><p>Appium is an open source, cross-platform test automation tool for native, hybrid and mobile web apps that allows tester to conduct automated app testing on different platforms like Android, iOS and Windows. It can be tested on simulators (iOS, FirefoxOS), emulators (Android), and real devices (iOS, Android, FirefoxOS).</p><p><strong>Supported Platforms:</strong></p><ul><li>iOS</li><li>Android</li><li>FirefoxOS</li></ul><p><strong>Appium Architecture :</strong></p><p>How does Appium work?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HJmBH1B9z90n829z" /></figure><p><strong>Appium Client Code:</strong> Appium client code is where you actually write your code. Appium wraps the code in JSON file and send it to the server</p><p><strong>Appium Server :</strong> Appium Server will listen to the client code received in Json format from Client. It has the capability to interpret the JSON file and perform all the actions on your android/iOS devices. You need to start your server on your local machine before executing Appium code, so this server will start in port 4723 and in your client code also you will redirect it to port 4723. The Appium server reads the JSON file and identifies whether this needs to be executed on iOS device or Android device.</p><p><strong>UIAutomator2:</strong> This is a test framework provided by Android to perform automation of Android apps</p><p><strong>XCUITest:</strong> This is a test framework provided by iOS to perform automation of iOS apps</p><p><strong>Advantages of Appium:</strong></p><ol><li>Appium is open source framework</li><li>It supports both native, Hybrid and mobile web applications</li><li>Supports iOS, Android and Windows apps</li><li>It supports many programming languages like Java, Python, Kotlin, C# etc.</li><li>You can test across hundreds of combinations of device types and operating systems (given you have the right plug-ins)</li></ol><p>I hope you liked the article and thanks for reading!!</p><p>Next Article: <a href="https://medium.com/@sadaniruchee/appium-setup-step-by-step-guide-for-mac-windows-db05acbf4617">Appium Setup Step by Step Guide for Mac/Windows</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a82226186de" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Appium Setup - Step by Step Guide for Mac/Windows]]></title>
            <link>https://sadaniruchee.medium.com/appium-setup-step-by-step-guide-for-mac-windows-db05acbf4617?source=rss-97c87c7a8761------2</link>
            <guid isPermaLink="false">https://medium.com/p/db05acbf4617</guid>
            <dc:creator><![CDATA[Sadaniruchee]]></dc:creator>
            <pubDate>Tue, 20 Dec 2022 07:57:17 GMT</pubDate>
            <atom:updated>2023-03-03T12:44:55.449Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MfU1_IxpMxQQNnMTAlLF2Q.png" /></figure><p>In this blog I am going to talk about how you can setup Appium in your Mac and Windows. Many of us face issues with the setup. So this is a step by step guide for your Mac and Windows setup. Most of the installations and setup in windows and mac are the same, only the path to set the system variables are different. It’s said that 70% of the work lies in your Appium setup itself so you really don’t need to bother much about it.</p><h3>Appium Setup for Windows</h3><p>Note: If you are a MAC user you can skip this section</p><blockquote><strong>1. Download and Install latest Java.</strong></blockquote><p><a href="https://www.oracle.com/ae/java/technologies/downloads/">https://www.oracle.com/ae/java/technologies/downloads/</a></p><p>You can find java in C:\Program Files\Java</p><p>Note: Before installing Java just check in Program Files if you see the folder Java and jdk inside it and open jdk folder and copy the path to be used in next step</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ahYcZpzBJeUq1H-EaoW2ng.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3GYZPTEmQ7po4Jjg6Gt5Iw.png" /></figure><blockquote><strong>2. Add environment Variable</strong></blockquote><ul><li>Right click on ‘This PC’ → Click on Properties → Click on Advanced system Settings → Click on Environment variables</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*33W8k_KRtIUA67KS-3InTg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_RgRKXSl_IQAAdPny9Pc3w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*rWCBDiYgDiI3K0cqYSkZJg.png" /></figure><ul><li>Under system variable click on ‘New’ and add Variable name as JAVA_HOME and Variable value will be the Java path that we copied in step 1 and click on OK</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/877/1*tHnSRmVN6v_P9W31xY-okA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/965/1*XYMXNcyNIYMW8uetgh2YtQ.png" /></figure><blockquote><strong>3. Download Android Studio</strong></blockquote><ul><li>To download Android Studio go to their official site : <a href="https://developer.android.com/studio">https://developer.android.com/studio</a>. An exe file will be downloaded</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eBynXB_tSXwERXl9j4eISw.png" /></figure><ul><li>Install Android Studio</li></ul><blockquote><strong>4. Download Node</strong></blockquote><p>You can download node from their official website <a href="https://nodejs.org/en/download/">https://nodejs.org/en/download/</a></p><p>For windows install Windows Installer (.msi) 32/64 bit based on your system configuration. After the download is done install node in your system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cmtKzIAF_RjokF6Y" /></figure><p>Once download is completed double click on the package and it will install node in your system</p><p>To verify if node is successfully installed on your system open terminal and type <strong><em>node -v</em></strong>. You will be able to see the node version that was installed, in my case it is v18.13.0</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*XgZlbMyhx8Hgpj6He5--SA.png" /></figure><blockquote><strong>5. Set(Java, Android SDK &amp; Node) Home Paths variables</strong></blockquote><ul><li>Go to C:\Users\HP\AppData to find where Android SDK has been downloaded<br>Note: The AppData might be hidden, in order to see it go to Open <strong>File Explorer </strong>from the taskbar →Select <strong>View </strong>→ Check the <strong>Hidden items </strong>checkbox.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S070gHdEpafpiE5ciP6tdA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*74inePzNcVEUnuy09HweCw.png" /></figure><ul><li>Under AppData go to Local → Android → SDK</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K1B2vlQZrqlFfyXvT4wXEA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hOhSCHWCIL7pVhnSJPZeJA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*LYEOyvaLQTVbGIy7uUX_wg.png" /></figure><ul><li>Copy the path till sdk and go back to env variable and set path of sdk just as you set the environment variable for JAVA. Click on new System Variable and set the path by giving variable name as ANDROID_HOME and in variable value paste the sdk path that we copied just now. Click on OKs</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6BBLZ0fMaivl7fVH_RQFBw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*33W8k_KRtIUA67KS-3InTg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_RgRKXSl_IQAAdPny9Pc3w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*rWCBDiYgDiI3K0cqYSkZJg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/882/1*7c3a2E26Feraq1HaTV5nCw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*GWLmEboysDwWVhGtmFUFbQ.png" /></figure><ul><li>Set below environment variables, Under system variables → Select Path variable → click on edit → Click on new in order to add tools, bin and platform-tools under Path variable in System variables<br><strong><em>C:\Users\Hp\appdata\Local\Android\SDK\tools\bin<br>C:\Users\Hp\appdata\Local\Android\SDK\tools<br>C:\Users\Hp\appdata\Local\Android\SDK\platform-tools</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xhpIH1wr4SxRlFkL663Q9w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*elpGmJtxXHSlgs0mgq4PVg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P1x632liUFEHtRYQntvRBA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/1*l87EH-HGWNgEe_aHuk6kRg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/887/1*hQO_X2rPpjiZ4Q3yjXdvbw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/885/1*jwivOug91Zq4fhpkIpIN4w.png" /></figure><ul><li>Set node home — Download nodejs from their official site <a href="https://nodejs.org/en/download/">https://nodejs.org/en/download/</a> and in Program files you will see a folder nodejs.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HaRPidGCW1bvQi24S4VvWg.png" /></figure><ul><li>Copy the nodejs path and paste it under environment variables by navigating to System variables → Select Path variable → Click on Edit → Click on new and add “<strong><em>C:\Program Files\nodejs”</em></strong> and click on ok</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/893/1*sp4lkTIS--ZY6gqRtygLYg.png" /></figure><ul><li>Also copy the npm bin folder under System variables → Select Path variable → Click on Edit → Click on new and add<br><strong><em>C:\Program Files\nodejs\node_modules\npm\bin</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HaRPidGCW1bvQi24S4VvWg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-XN--ztY9ZDqllfjnkZy2A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bmYX67qu_mcTaihYrJt_Qg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ey4gZwQDg7X-8FEg9PwZkw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9asx34cwkIzTZtIkVKMmIg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/887/1*xYctEzAgAtQbLsfYbLI8xg.png" /></figure><blockquote><strong>6. Open Android Studio and Configure Emulator</strong></blockquote><ul><li>Open Android Studio</li><li>Click on New project → Select Basic Activity → Click on next → Click on Finish and wait until the whole project is loaded and built</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p3L4MZ5hFaovpTkzIh5-Vg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dsPZRtSaXS3-wPgAsO1wsg.png" /></figure><ul><li>Go to Tools → Device Manager</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yz4kO0_6E1n2ME5qqOpVGQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pBubPBS1boDlVoOxVZKfuQ.png" /></figure><ul><li>Click on Create device and select the device which you want to use for automation and click on next and download the system image(download the system image compatible with the apk file otherwise your script will fail) and wait for it to get downloaded, once its downloaded select the same system image and Click on Next , then set the AVD name (you can set any name) and click Finish</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vqmpUTExdouNw31zPuCACA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r5n06bMvIHNfTJs2kpBRJw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3DfpBO7c_VDHqrD9xRPh-Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*41JT_T6GIW_3hAlaWk19-w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y_qsXsLc161lxu_Ke04SOw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1VVJQk6C3jficdWH4cP5RQ.png" /></figure><p>Now you can start using the emulator</p><blockquote><strong>7. Install and start Appium Server via node</strong></blockquote><ul><li>On your terminal run below command : <br><strong><em>sudo</em></strong> <strong><em>npm install -g appium@next</em></strong></li><li>Provide your system password and this will help you to install appium.</li><li>To make sure it is installed in your system type below command</li></ul><p><strong><em>appium</em></strong></p><p>This command will give you logs just like below screenshot and that’s what confirms that your appium is installed correctly</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pmgs2lQQKL0tZYvVQw_4gw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RQkzlNHNT7oKI9uJjbLf0A.png" /></figure><blockquote><strong>8. Install eclipse / any other editor of your choice</strong></blockquote><ul><li>Download Eclipse IDE for Java Developers from their website <a href="https://www.eclipse.org/downloads/packages/">https://www.eclipse.org/downloads/packages/</a></li></ul><p>If you have followed the above steps your appium setup is ready! Now you can start creating your first script</p><p><strong><em>At this point your Windows setup is done!!</em></strong></p><h3>Appium Setup for MAC</h3><p>Note: If you are a Windows user you can skip this section</p><blockquote><strong>1. Download and Install Java</strong></blockquote><p>Before installing check if is present in your machine by running following command in you terminal<br>java --version</p><p>If it’s not installed download java from their official site:<br><a href="https://www.oracle.com/ae/java/technologies/downloads/">https://www.oracle.com/ae/java/technologies/downloads/</a></p><blockquote><strong>2. Download Android Studio</strong></blockquote><ul><li>To download Android Studio go to their official site : <a href="https://developer.android.com/studio">https://developer.android.com/studio</a> <br><strong>A</strong> .dmg file will be downloaded as below screenshot</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R3SOJ5CoU_3kc-NyFUI_GA.png" /></figure><ul><li>Install Android Studio</li></ul><blockquote><strong>3. Download Node</strong></blockquote><p>You can download node from their official website <a href="https://nodejs.org/en/download/">https://nodejs.org/en/download/</a></p><p>For mac install macOS Binary(.pkg)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NSNO1K3S_UStaHWX" /></figure><p>Once download is completed double click on the package and it will install node in your system</p><p>To verify if node is successfully installed on your system open terminal and type node -v. You will be able to see the node version that was installed, in my case it is v16.16.0</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*toN11vAO6GjdFcjmyzJrMg.png" /></figure><blockquote><strong>4. Set(Java, Android SDK &amp; Node) Home Paths in MAC OS System Variables</strong></blockquote><ul><li>To check java_home on your mac device run command <em>“</em><strong><em>Open /usr/libexec</em></strong>” in the terminal and it will open the respective folder and search for java_home.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pZ9J-LVn16e20tH5u8yPJQ.png" /></figure><ul><li>To check the ANDROID_HOME path run below command in the terminal</li></ul><p><strong><em>Open /users/&lt;yourusername&gt;/library/android</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BNJwib5ua9i-hG65kLrxnA.png" /></figure><p>On your terminal type “<strong><em>vi ~/.bash_profile</em></strong>” command to open bash profile</p><ul><li>To insert press <strong>i</strong> key on your keyboard and add below commands</li></ul><p><strong><em>export JAVA_HOME=$(/usr/libexec/java_home)</em></strong></p><p><strong><em>export ANDROID_HOME=/users/&lt;yourUsername&gt;/Library/Android/sdk</em></strong></p><p><strong><em>export PATH=$PATH:/usr/local/bin:</em></strong></p><p><strong><em>export PATH=$PATH:$ANDROID_HOME/platform-tools</em></strong></p><p><strong><em>export PATH=$PATH:$ANDROID_HOME/tools</em></strong></p><p><strong><em>export PATH=$PATH:$ANDROID_HOME/tools/bin</em></strong></p><p><strong><em>export PATH=$PATH:$ANDROID_HOME/emulator</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3mBzgzDMVQkQiFeQBQHSww.png" /></figure><p>Now save and exit by pressing escape and type <strong>:wq</strong></p><ul><li>To save the above path we need to run the below command and it’s a mandatory step otherwise when you close the terminal all the path that you set above will get reset.</li></ul><p><strong><em>source ~/.bash_profile</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_96N6z9D6U_JGrbA" /></figure><ul><li>To confirm if it is set correctly type</li></ul><p><strong><em>echo $JAVA_HOME</em></strong></p><p>It should return below path<br><em>/Library/Java/JavaVirtualMachines/1.8.xx.jdk/Contents/Home</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B9KfWvzaGlteXj3i2RC1-Q.png" /></figure><ul><li>To confirm Android_Home path type<strong><em> echo $ANDROID_HOME</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rps9O9DkUcSnQP1jE-GPrQ.png" /></figure><ul><li>To confirm PATH type <strong><em>echo $PATH</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1UX9kTzuznkY6MT3XELf9A.png" /></figure><p><strong>Note</strong>: Sometimes <strong><em>source ~/.bash_profile </em></strong>command to save the environment variables might not work and when you run echo $JAVA_HOME it might return null, so to fix this open terminal → Preferences→ Profile→ Shell and check the Run command checkbox and type <strong><em>source ~/.bash_profile</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eVT14Qn3reraNFi0w0_MNQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PNQm9nWQV_0wIU41vBW4kw.png" /></figure><blockquote><strong>7. Open Android Studio and Configure Emulator</strong></blockquote><ul><li>Open Android Studio</li><li>Click on New project → Select Basic Activity → Click on next → Click on Finish and wait until the whole project is loaded and built</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p3L4MZ5hFaovpTkzIh5-Vg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dsPZRtSaXS3-wPgAsO1wsg.png" /></figure><ul><li>Go to Tools → Device Manager</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yz4kO0_6E1n2ME5qqOpVGQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pBubPBS1boDlVoOxVZKfuQ.png" /></figure><ul><li>Go to Tools → Device Manager</li><li>Click on Create device and select the device which you want to use for automation and click on next and download the system image (download the system image compatible with the apk file otherwise your script will fail) and wait for it to get downloaded, once its downloaded select the same system image and Click on Next , then set the AVD name (you can set any name) and click Finish</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k6LLItaHQP8_R92G3f_plQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d_vM-Xa82BtzlFstws874w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2nlkaUAyw0NSwDxAMZT_vw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*phAp2aOJ8WcyAoHTHK1BKQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yv9Gh2SvpQqbWr6Bh9owmw.png" /></figure><p>Now you can start using the emulator</p><blockquote><strong>8. Install and start Appium Server via node</strong></blockquote><ul><li>On your terminal run below command : <br><strong><em>sudo</em></strong> <strong><em>npm install -g appium@next</em></strong></li><li>Provide your system password and this will help you to install appium.</li><li>To make sure it is installed in your system type below command</li></ul><p><strong><em>appium</em></strong></p><p>This command will give you logs just like below screenshot and that’s what confirms that your appium is installed correctly</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gnPPYBXKzvkiCbIa" /></figure><blockquote><strong>9. Install eclipse / any other editor of your choice</strong></blockquote><ul><li>Download Eclipse IDE for Java Developers from their website <a href="https://www.eclipse.org/downloads/packages/">https://www.eclipse.org/downloads/packages/</a></li></ul><p>If you have followed the above steps your appium setup is ready! Now you can start creating your first script</p><p>I hope you liked the article and thanks for reading!!</p><p>Next article : <a href="https://medium.com/@sadaniruchee/run-your-1st-appium-script-b3352d0febbe">https://medium.com/@sadaniruchee/run-your-1st-appium-script-b3352d0febbe</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=db05acbf4617" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>