So now that we have a basic understanding of Appium and what Appium is. We can go ahead and get started on setting ourselves up to be able to run Appium scripts. In this lesson, we're going to focus on the language Java as well as primarily focusing on Mac operating systems.

So how to set up your environment on a mac OS? We'll be installing Java, we'll be installing your ide of choice mine is Visual Studio code, and we will also be installing Appium along with a Java project, oh I'm sorry, a Java tool that really helps facilitate Java projects, which is called Maven. So with that, we can go ahead and get started.

First thing I'm going to do is actually download Java. So I have here this outline that will help us kind of go step by step on setting ourselves up. And again, first thing we'll do is install Java. So if I navigate to this website here, it'll take us to Java downloads. Java currently has released Java 18 and Java 17 is available as well. If you're familiar with Java, there are previous versions of Java such as Java 8, Java 11, and these versions have now been archived. So I'm going to make use of the latest version of Java, which is Java 18. On Oracle's site in Java downloads, you are going to just download the version that works best for you. So with that we have arm64 or x64.

If you're not sure the difference of what your Mac operating system is making use of, so x64 is making use of previous MAC models that still included had the intel processor, the Intel CPU. And then recently Mac has made a move to make use of their own CPU processors their own chips. You might see that as like the M1 chip that is where the ARM would support. Or A-R-M how do you want to say that. So if you're not sure exactly which CPU your computer is making use of. On the Mac itself, you can always go to the apple. The top left go to about this Mac and I see that my computer has an intel core i5 so making use of Intel's CPU, it might say M1 chip.

So M1 chip you'd want to use ARM and then intel CPUs. You want to use the x64. So with that and the x64 dmg installer will going to install Java 18. All right. I'm going to click into this and we'll go through the installation process.

Once again, just navigate through the installation process you would like and it will prompt you for your username and password. Awesome. Here we have java installed. I'll hit close in move to trash.

After Java installed, we can quickly confirm that installation by actually pulling up the terminal. So you can either search for a terminal or have it already, save within your system. And what we'll do is we can just type in Java version. And I can confirm that the Java version is 18, which I just installed. So that is correct. So we can move forward. So we have java installed.

Next, we want to install your ide of choice. So my ide of choice is Visual Studio code. I just find that Visual Studio code has a lot of great features and functionality to help and development and scripting, such as having a terminal window right within your project, as well as having really great robust plugins and extensions to once again help facilitate any development and coding projects.

So I already have Visual Studio code downloaded onto my environment. But if you'd like to use the same, you can navigate to this download link here. And but of course, there are other ides that you can choose. So there is Eclipse, IntelliJ, Android studio code, a lot of great other ides to make use of as well.

So again, whatever works best for you or whatever you might be familiar with, you can make use of that ide. I want to quickly make a note that this lesson is going to make use of Kobiton Appium script export and with that export we will actually be running it on Kobiton's real devices.

So in this lesson, we will not be setting up any sort of emulators or any packages of that sort because once again, we'll be making use of real devices. So moving on now it is time to make use of NodeJs. And with NodeJs we can actually. Also install NPM. So you would just navigate, there are a couple of different ways you could go about installing NodeJS. So we do have the terminal route if you so choose. I did realize upon doing that you might run into some permission issues. So if that's the case, that's all good. We can actually use this run this command to change the ownership or change the permissions of the path that you're looking to write into. To install Node modules. But I always find that it's actually easiest just to navigate to which I have here. And then you can install it for it will actually check your environment. And so here it's actually already check that we're going to download on the X64 for my environment again making use of the intel chip. So with that, you could actually just download straight from here. And it will also take you through an installation package. So installing the package and the respective directories. And we will continue agreeing to license. The destination, installation type and we can hit install. So I have also previously already installed NodeJS so I will not move forward and installing. I'm actually just going to exit out of this package. But to quickly check the version to ensure that your installation was complete, we can pull back up terminal and we can simply go node version. Here I have Node version 16.15.5 And the same for NPM. We have 8.11.0.

So we'll be using NPM to install Appium and then we'll actually install an additional dependency called a Homebrew. We'll use Homebrew to install Maven.

So Maven is a tool that can be used for building and managing Java-based projects. And since we'll be making use of the Java language for the Appium script to run, we will be utilizing Maven as well. So we installed NPM or NodeJS to install Appium and then we'll also install Homebrew. That way we can install Maven there after. So to install Appium via NPM, we would run the command NPM, install and dash to use more at the global level and will install Appium. All right. And just double-check that everything has been installed correctly. There are no issues or anything. I think with this there are a few vulnerabilities brought to my attention, but otherwise, Appium has been installed on my environment.

We can also quickly check by going Appium dash v (-v). So I am running Appium 1.22.3. So from here, you can make use of the command Appium to run a lot of commands as is via command line. Or you could also download Appium desktop, which that is more of a GUI so more of a UI you can make use of instead of having to start Appium or run any Appium scripts via command line. So Appium server or excuse me Appium desktop is available as well to make use of.

Okay. So moving on, we are going to install Homebrew once again by installing Homebrew here we can install Maven, so Homebrew makes it really easy for you to install. You could simply go to a and then they have a quick easy to copy how to install a command-line here. They can then paste into your terminal. Put in your password. It's going to let you know where it's running into. You can enter it. Hit enter once, actually good hit, enter once more. It is going through its findings. Want to give it a moment as it installs, and I'll be back once it's complete. Okay. So Homebrew has successfully installed within my environment. I will know it did take a couple of minutes.

So if you see it kind of hanging on installing command for Xcode and it's been a couple of a minute or two, just hang tight, wait for a solid five, seven, 10 minutes and then ensure that that installed. So again, it did take a couple of minutes.

Okay. So now we have homebrew installed in our environment on our machine. We can go ahead and move forward. So now we will be installing Maven. And so once again, Maven is a tool that we can use to help Goto manage our Java-based Appium project. And we can do that via Brew or excuse me, the command brew and you are able to install Maven via NPM. So I know we have installed two packages here, npm and homebrew.

I just found that it's easier to install via brew because the NPM installation would then further need an actual NPM wrapper to make use of the maven mvn command. So anytime you're running a Maven command, you would start with mvm, and that is just easier with brew versus having to do an additional step of placing in that wrapper via the NPM installation. So with that, we're going to go brew install Maven.

All right. So actually, before installing Maven, I did run that command and I found that through an error. And so I wasn't entirely sure if through this error of Maven wrong number of arguments. So looking a bit further, I realized that installing Homebrew did come with its own error message, such as Homebrew Core as a shallow clone as well as Homebrew Cask is a shallow clone and homebrew that developers at Homebrew even gave us a little note saying apologies for any inconvenience.

It's kind of they're kind of restricted being GitHub of why you're only downloading the if you will I guess the latest commit of homebrew. But they do provide the solution for kind of unshallowing the repo essentially. So once you install Homebrew, you will then further just copy these commands that they do provide for you. So copy the command here for Homebrew Core as well as Homebrew Cask. And just run those commands. I will note that the reason essentially what's happening is that by running those commands, you're installing the entire repository, including all the different revisions and commits of it. It's not just the latest commit. And so with that homebrew being a very popular tool to make use of, it is a little lengthy in time.

So when you run these commands, it might take a couple of minutes. I think for Home Brew Core, it took a solid five-ish five or more minutes. So be patient with it. The first time I did it, I thought it was hanging, so I actually kind of quit out of it. So run the command, give it a moment up to 10 minutes. And that way you are installing the entirety of Homebrew. So then now we can make use of the brew install maven. So let's continue and we can do just that. So brew install maven. And here we have we're installing Maven versus getting that error previously. I'll make sure that this is also noted within the outline as well.

So it's still doing its thing. It has let me know that there might be an outdated formula within the cask. I'm going to just instead of doing a brew upgrade, I'm just going to continue with the brew that I have just freshly installed as I imagine that is the latest homebrew version. And here it is pouring maven. So. Love the naming convention. And we are complete. To double check that maven has been installed.

We can simply go the command for Maven is mvn so we can run mvn dash dash version (--version). And here we have the maven version available that is relevant to the Java version installed on the device, excuse me, the maven version is right here. 3.8.6. Okay. Awesome. So we have Java installed, we have NPM installed to install Appium, we have homebrew installed to install Maven and now we can continue setting up our environments. I'm actually going to clear out of this.

So the next thing we need to do, there are the environment variables that need to be defined, essentially, that have the direct path of these variables relevant to your environment. So what we can start with is one, double-checking what shell you're using. In terminal, you are making use of a shell. And for previous Mac OS versions.

So before Big Sur, the default shell was bash. So there is a specific file to create your environment variables and relevant to bash the bash shell. And then for OS versions that are later coming out of the box essentially is later than Big Sur. Out of the box is they make use of the default Z shell. So once again, each Shell is going to have their own respective file that we want to create and write into to define our the direct path of our environment variables to make use in our environment and our local machine to be able to run our Appium scripts.

So if you're not sure which shell you're using, you can simply go echo shell in return either bin Z Shell or bin bash. So if you are using Bash Shell, then you'll be making use of the file bash profile. Maybe you are the Z shell making use of the Z shell rc. So since I am Z shell, I'm going to make use of that Z shell, the files are relevant to the Z shell that Z shell RC.

By default, this file is not existing. So what we need to do is we need to create the file and then further we need to write into that file. We can save that file and edit that at any other time. So one way to create the file is by making use of the command vim. You can also use the command touch or a nano or other sort of options to create a file and write into a file. But with this lesson I'll be making use of vim. So ensure that you're in the director, you want to be so user / your user. And then what we can do is write vim (~ /) curly bracket backspace ZHRC that creates the file in that directory. And now we can actually write into this file. So with this editor open, we can hit I for insert. And then what we want to do is actually start again defining our environment variables and the direct path that we're making use of.

So with this. Open and ready to edit. We want to first define our Java home environment variable so we can start typing out exporting the variable itself and to where and the directory that it's in. And then at the same time exporting the path of that variable within our bin, within our local directory.

So again, ensuring that that path is defined so that no matter what tool you're using, that tool knows where this variable is, know that the direct path is and knows where to pull relevant, I would say, not information but relevant resources within that. So such as for example, the Java home variable will give the direct path of the Java JDK that you're making use of.

So if I pull a Visual Studio code, if I pull up IntelliJ, if I pull up any ide or making use of any tooling software or excuse me, anything like use of development software with this environment variable defined in that direct path defined, no matter which tool I'm opening and using, it will know exactly where the JDK file is and resources are to make use of in your project. So we'll be doing this for Java home and we'll be doing this for Maven as well.

So to get started for Java, so we're going to do export and this is copy and paste but just to kind of get you familiar with writing into a file again. Make sure you press I for insert. We can start typing this out. So Java home equals. I'm going to stop there and I'm just going to copy and paste. So just double-checking, make sure I paste that incorrectly with the directory that it's in and then also define that path. With that, we can actually hit escape.

So taking out insert mode colon and then going wq to save and quit. So now we've created that file as well as edited that file to include our environment variable Java home. If we need to check to ensure this is set up correctly, there might be some issues, not issues, but some. I would more or less say disconnect.

Once again, we can just double-check ourselves by going Echo Java home and make sure I wrote that. If you are running Java Home or running Echo and it's coming up blank. What you might need to do is simply go source and the file we just created. So that's just reminding the terminal that this file is a source file to make use of. And then now if we run Java home, we should have the path returned back to us.

Once again, double-check. The expectation is that we want it in this Java virtual machine, JDK make sure it's the correct version as well that we downloaded earlier. There might be a scenario where you're actually getting something that looks like an applet or a plug-in or something. So you're not getting this virtual machine return. You're actually getting a different location. You can change Java home by simply running this command. And now. They'll move your JDK to the directory that you want to move it to, to make use and the apps in the direct path.

All right. So we have our Java home variable defined. We can move forward with our MAVEN environment variable. What a Maven environment variable you can do the exact same thing. We're gonna open back up that file. So in command line and stuff to rewrite everything, you can actually show up space and that will return previous commands back into this file. What do I for insert move down a row. And now we will export to find the MAVEN home environment variable. Oh. B.

Efore I do that, remember when I checked the version of Maven, it did return to the version within the version that you have. So we do need to make quick note of that to set that in our environment variable. And let me exit out of this. We did. It's going to be Maven dash dash version here. The version. Was that 3.8.6. So make note of that 3.8.6. Back into our file. Where we'll go either insert. And I'm going to paste this there just for a second. Just make sure I have it. I don't lose it. And then now we're getting back here. Copy this. Paste in there. And then where we have the MAVEN version, we will input the MAVEN version that we know that we have in our environment and remove this which we don't have any other.

All right, so hit escape colon WQ for save quit. I'm going to go out and just run the source command once more just to ensure that the file is now the source file. And then if we were to do echo Maven home, we should find that it is in that directory that returns that directory, which we see that it does.

Okay. Fantastic. Well, that is it.

We have set our environment variables to make use of. So as I pull up Visual Studio code, Visual Studio code will kind of scan my environment and will find that environment variable. And then with finding that environment variable, making use of the file we just created will know exactly where to find the JDK as well as the Maven tool to make use of Visual Studio Code or any other IDE once again. So. 

Enter your text here...

Comments are closed.

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}