diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..21d0c8a --- /dev/null +++ b/Gemfile @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +# gem "rails" + +gem "appium_lib", "~> 16.1" + +gem "selenium-webdriver", "~> 4.40" + +gem "test-unit", "~> 3.7" diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..226ec7c --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,66 @@ +GEM + remote: https://rubygems.org/ + specs: + appium_lib (16.1.1) + appium_lib_core (>= 9.2.1, < 12.0) + nokogiri (~> 1.8, >= 1.8.1) + tomlrb (>= 1.1, < 3.0) + appium_lib_core (11.2.0) + faye-websocket (>= 0.11, < 0.13) + selenium-webdriver (~> 4.21) + base64 (0.3.0) + eventmachine (1.2.7) + faye-websocket (0.12.0) + eventmachine (>= 0.12.0) + websocket-driver (>= 0.8.0) + logger (1.7.0) + nokogiri (1.19.0-x64-mingw-ucrt) + racc (~> 1.4) + power_assert (3.0.1) + racc (1.8.1) + rexml (3.4.4) + rubyzip (3.2.2) + selenium-webdriver (4.40.0) + base64 (~> 0.2) + logger (~> 1.4) + rexml (~> 3.2, >= 3.2.5) + rubyzip (>= 1.2.2, < 4.0) + websocket (~> 1.0) + test-unit (3.7.7) + power_assert + tomlrb (2.0.4) + websocket (1.2.11) + websocket-driver (0.8.0) + base64 + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.5) + +PLATFORMS + x64-mingw-ucrt + +DEPENDENCIES + appium_lib (~> 16.1) + selenium-webdriver (~> 4.40) + test-unit (~> 3.7) + +CHECKSUMS + appium_lib (16.1.1) sha256=d53402b41846c1e1431ed44ba49cb7c9ff8f56f2a51c433b57f167b68afe9cb7 + appium_lib_core (11.2.0) sha256=677040cceb7ff5e07276df55791106fee398101b69e82edf9e382a6609d18a70 + base64 (0.3.0) sha256=27337aeabad6ffae05c265c450490628ef3ebd4b67be58257393227588f5a97b + eventmachine (1.2.7) sha256=994016e42aa041477ba9cff45cbe50de2047f25dd418eba003e84f0d16560972 + faye-websocket (0.12.0) sha256=ad9f7dfcd0306d0a13baeee450729657661129af15bb5f38716c242484ab42e1 + logger (1.7.0) sha256=196edec7cc44b66cfb40f9755ce11b392f21f7967696af15d274dde7edff0203 + nokogiri (1.19.0-x64-mingw-ucrt) sha256=05d7ed2d95731edc9bef2811522dc396df3e476ef0d9c76793a9fca81cab056b + power_assert (3.0.1) sha256=8ce9876716cc74e863fcd4cdcdc52d792bd983598d1af3447083a3a9a4d34103 + racc (1.8.1) sha256=4a7f6929691dbec8b5209a0b373bc2614882b55fc5d2e447a21aaa691303d62f + rexml (3.4.4) sha256=19e0a2c3425dfbf2d4fc1189747bdb2f849b6c5e74180401b15734bc97b5d142 + rubyzip (3.2.2) sha256=c0ed99385f0625415c8f05bcae33fe649ed2952894a95ff8b08f26ca57ea5b3c + selenium-webdriver (4.40.0) sha256=16ef7aa9853c1d4b9d52eac45aafa916e3934c5c83cb4facb03f250adfd15e5b + test-unit (3.7.7) sha256=3c89d5ff0690a16bef9946156c4624390402b9d54dfcf4ce9cbd5b06bead1e45 + tomlrb (2.0.4) sha256=262f77947ac3ac9b3366a0a5940ecd238300c553e2e14f22009e2afcd2181b99 + websocket (1.2.11) sha256=b7e7a74e2410b5e85c25858b26b3322f29161e300935f70a0e0d3c35e0462737 + websocket-driver (0.8.0) sha256=ed0dba4b943c22f17f9a734817e808bc84cdce6a7e22045f5315aa57676d4962 + websocket-extensions (0.1.5) sha256=1c6ba63092cda343eb53fc657110c71c754c56484aad42578495227d717a8241 + +BUNDLED WITH + 4.0.5 diff --git a/README.md b/README.md index 5985e43..06711a2 100644 --- a/README.md +++ b/README.md @@ -17,280 +17,217 @@   ⋅   YouTube

-  -  -  *Appium is a tool for automating native, mobile web, and hybrid applications on iOS, Android, and Windows platforms. It supports iOS native apps written in Objective-C or Swift and Android native apps written in Java or Kotlin. It also supports mobile web apps accessed using a mobile browser (Appium supports Safari on iOS and Chrome or the built-in 'Browser' app on Android). Perform Appium automation tests on [LambdaTest's online cloud](https://www.lambdatest.com/appium-mobile-testing).* -*Learn the basics of [Appium testing on the LambdaTest platform](https://www.lambdatest.com/support/docs/getting-started-with-appium-testing/).* +Learn the basics of [Appium testing on the LambdaTest platform](https://www.lambdatest.com/support/docs/getting-started-with-appium-testing/). [](https://accounts.lambdatest.com/register) ## Table of Contents * [Pre-requisites](#pre-requisites) +* [Setting Up Your Authentication](#setting-up-your-authentication) +* [Upload Your Application](#upload-your-application) * [Run Your First Test](#run-your-first-test) * [Executing The Tests](#executing-the-tests) +* [Troubleshooting](#troubleshooting) +* [About LambdaTest](#about-lambdatest) + +--- ## Pre-requisites Before you can start performing Ruby automation testing with Appium, you would need to: -- Install **Ruby** on your local system. Follow these instructions to install on different operating systems. - - - For **Windows**, you can download from the [official website](https://rubyinstaller.org/downloads/). - - For **Linux** or **Ubuntu**, you can run a simple apt command like below: - - ```bash - sudo apt-get install ruby-full - ``` - - - For **macOS**, you can run a [Homebrew](https://brew.sh/) command like this: +1. Install **Ruby**: Ensure you have Ruby 3.4+ installed. - ```bash - brew install ruby - ``` + - For **Windows**, download from [RubyInstaller](https://rubyinstaller.org/downloads/). + - For **macOS**, run `brew install ruby`. + - For **Linux** or **Ubuntu**, you can run a simple apt command like below: + sudo apt-get install ruby-full - -### Clone The Sample Project - -Clone the LambdaTest’s [LT_Ruby_Appium](https://github.com/LambdaTest/LT_Ruby_Appium) and navigate to the code directory as shown below: +2. **Clone The Sample Project**: ```bash -git clone https://github.com/LambdaTest/LT_Ruby_Appium -cd LT_Ruby_Appium +git clone [https://github.com/Priya2224/LT-appium-ruby.git](https://github.com/Priya2224/LT-appium-ruby.git) +cd LT-appium-ruby + ``` -### Setting Up Your Authentication +## Setting Up Your Authentication -Make sure you have your LambdaTest credentials with you to run test automation scripts on LambdaTest. To obtain your access credentials, [purchase a plan](https://billing.lambdatest.com/billing/plans) or access the [Automation Dashboard](https://appautomation.lambdatest.com/). +Make sure you have your LambdaTest credentials with you to run test automation scripts. To obtain your access credentials, purchase a plan or access the access the [App Automation Dashboard](https://appautomation.lambdatest.com/) -Set LambdaTest `Username` and `Access Key` in environment variables. +Set LambdaTest Username and Access Key in environment variables. -**For Linux/macOS:** +For Linux/macOS: -```js -export LT_USERNAME=YOUR_LAMBDATEST_USERNAME \ +```bash +export LT_USERNAME=YOUR_LAMBDATEST_USERNAME export LT_ACCESS_KEY=YOUR_LAMBDATEST_ACCESS_KEY ``` - -**For Windows:** - -```js -set LT_USERNAME=YOUR_LAMBDATEST_USERNAME ` + +For Windows: + +```bash +set LT_USERNAME=YOUR_LAMBDATEST_USERNAME set LT_ACCESS_KEY=YOUR_LAMBDATEST_ACCESS_KEY ``` - -### Upload Your Application -Upload your **_iOS_** application (.ipa file) or **_android_** application (.apk file) to the LambdaTest servers using our **REST API**. You need to provide your **Username** and **AccessKey** in the format `Username:AccessKey` in the **cURL** command for authentication. Make sure to add the path of the **appFile** in the cURL request. Here is an example cURL request to upload your app using our REST API: +## Upload Your Application + +Upload your iOS application (.ipa file) or android application (.apk file) to the LambdaTest servers using our REST API. You need to provide your Username and AccessKey in the format Username:AccessKey in the cURL command for authentication. Make sure to add the path of the appFile in the cURL request. Here is an example cURL request to upload your app using our REST API: -**Using App File:** +Using App File: -**For Linux/macOS:** +For Linux/macOS: -```js +```bash curl -u "YOUR_LAMBDATEST_USERNAME:YOUR_LAMBDATEST_ACCESS_KEY" \ --location --request POST 'https://manual-api.lambdatest.com/app/upload/realDevice' \ --form 'name="Android_App"' \ ---form 'appFile=@"/Users/macuser/Downloads/proverbial_android.apk"' +--form 'appFile=@"/Users/macuser/Downloads/proverbial_android.apk"' ``` -**For Windows:** +For Windows: -```js -curl -u "YOUR_LAMBDATEST_USERNAME:YOUR_LAMBDATEST_ACCESS_KEY" -X POST "https://manual-api.lambdatest.com/app/upload/realDevice" -F "appFile=@"/Users/macuser/Downloads/proverbial_android.apk"" +```bash +curl -u "USER:KEY" -X POST "https://manual-api.lambdatest.com/app/upload/realDevice" -F "appFile=@"C:/path/to/proverbial_android.apk"" ``` -**Using App URL:** +Using App URL: -**For Linux/macOS:** +For Linux/macOS: -```js +```bash curl -u "YOUR_LAMBDATEST_USERNAME:YOUR_LAMBDATEST_ACCESS_KEY" \ --location --request POST 'https://manual-api.lambdatest.com/app/upload/realDevice' \ --form 'name="Android_App"' \ --form 'url="https://prod-mobile-artefacts.lambdatest.com/assets/docs/proverbial_android.apk"' ``` -**For Windows:** +For Windows: -```js +```bash curl -u "YOUR_LAMBDATEST_USERNAME:YOUR_LAMBDATEST_ACCESS_KEY" -X POST "https://manual-api.lambdatest.com/app/upload/realDevice" -d "{"url":"https://prod-mobile-artefacts.lambdatest.com/assets/docs/proverbial_android.apk","name":"sample.apk"}" ``` -**Tip:** +Tip: -- If you do not have any **.apk** or **.ipa** file, you can run your sample tests on LambdaTest by using our sample :link: [Android app](https://prod-mobile-artefacts.lambdatest.com/assets/docs/proverbial_android.apk) or sample :link: [iOS app](https://prod-mobile-artefacts.lambdatest.com/assets/docs/proverbial_ios.ipa). -- Response of above cURL will be a **JSON** object containing the `App URL` of the format - and will be used in the next step. +1. If you do not have any .apk or .ipa file, you can run your sample tests on LambdaTest by using our sample 🔗 [Android App](https://prod-mobile-artefacts.lambdatest.com/assets/docs/proverbial_android.apk) or sample 🔗 [iOS App](https://prod-mobile-artefacts.lambdatest.com/assets/docs/proverbial_ios.ipa). +2. Response of above cURL will be a JSON object containing the App URL of the format - lt://APP123456789123456789 and will be used in the next step. ## Run Your First Test Once you are done with the above-mentioned steps, you can initiate your first Ruby test on LambdaTest. -**Test Scenario:** Check out [Android.rb](https://github.com/LambdaTest/LT-appium-ruby/blob/master/android/android-sample.rb) file to view the sample test script for android and [iOS.rb](https://github.com/LambdaTest/LT-appium-ruby/blob/master/ios/ios-sample.rb) for iOS. +Test Scenario: Check out [Android.rb](https://github.com/LambdaTest/LT-appium-ruby/blob/master/android/android-sample.rb) file to view the sample test script for android and [iOS.rb](https://github.com/LambdaTest/LT-appium-ruby/blob/master/ios/ios-sample.rb) for iOS. -### Configuring Your Test Capabilities +### Configuring Your Test Capabilities (Ruby 3.4/W3C Fix) +Update the caps object in your scripts. For Ruby 3.4, keys must be Symbols. -You can update your custom capabilities in test scripts. In this sample project, we are passing platform name, platform version, device name and app url (generated earlier) along with other capabilities like build name and test name via capabilities object. The capabilities object in the sample code are defined as: +Android Configuration -**Info Note:** - -- In case you're using the Capabilities using the JSON Wire Protocol, then please use appium_lib version 10.6.0 and below. -- Install it using ```gem install appium_lib -v 10.6.0``` command. - - - - - -```ruby title="iOS(.ipa)" - caps = { - "LT:Options" => { - :deviceName => "iPhone 13 Pro", - :platformName => "iOS", - :platformVersion => "15", - :build => "Ruby Vanilla - iOS", - :name => "Ruby iOS Test", - :isRealMobile => true, - :app => "YOUR_APP_URL", #Enter the App (.ipa) URL here - :w3c => true, - } } +```bash +caps = { + "lt:options" => { + :deviceName => "Galaxy S24", + :platformName => "Android", + :platformVersion => "14", + :isRealMobile => true, + :app => "YOUR_APP_URL", + :w3c => true + }, + :platformName => "Android" +} ``` - - +iOS Configuration -```ruby title="Android(.apk)" +```bash caps = { - "LT:Options" => { - :deviceName => "OnePlus 7", - :platformName => "Android", - :platformVersion => "9", - :build => "Ruby Vanilla - Android", - :name => "Ruby Android Test", - :isRealMobile => true, - :app => "YOUR_APP_URL", #Enter the App (.apk) URL here - :w3c => true, - } } + "lt:options" => { + :deviceName => "iPhone 17 Pro", + :platformName => "iOS", + :platformVersion => "26", + :isRealMobile => true, + :app => "YOUR_APP_URL", + :w3c => true + }, + :platformName => "iOS" +} ``` - - - +Info Note: -**Info Note:** - -- You must add the generated **APP_URL** to the `"app"` capability in the config file. -- You can generate capabilities for your test requirements with the help of our inbuilt **[Capabilities Generator tool](https://www.lambdatest.com/capabilities-generator/)**. A more Detailed Capability Guide is available [here](https://www.lambdatest.com/support/docs/desired-capabilities-in-appium/). +1. You must add the generated APP_URL to the "app" capability in the config file. +2. You can generate capabilities for your test requirements with the help of our inbuilt [Capabilities Generator tool](https://www.lambdatest.com/capabilities-generator/). A more Detailed Capability Guide is available [here](https://www.lambdatest.com/support/docs/desired-capabilities-in-appium/). ## Executing The Tests - +1. Install dependencies: + +```bash +bundle install +``` - +2. Run the scripts: -If you are using an **iOS** app, the cURL command will generate an app URL for the corresponding iOS app and install the same for running the tests. You can either use our sample :link: [iOS app](https://prod-mobile-artefacts.lambdatest.com/assets/docs/proverbial_ios.ipa) or upload your own app as discussed earlier. +Running on Android Navigate to the corresponding directory based on your app. ```bash -cd ios +cd android ``` Execute the following command to run your test on LambdaTest platform: ```bash -ruby ios-sample.rb +ruby android-sample.rb ``` - - - - -If you are using an **android** app, the cURL command will generate an app URL for the corresponding Android app and install the same for running the tests. You can either use our sample :link: [Android app](https://prod-mobile-artefacts.lambdatest.com/assets/docs/proverbial_android.apk) or upload your own app as discussed earlier. +Running on iOS Navigate to the corresponding directory based on your app. ```bash -cd android +cd ios ``` Execute the following command to run your test on LambdaTest platform: ```bash -ruby android-sample.rb +ruby ios-sample.rb ``` - - - - -**Info Note** -In case of Windows, if you get any error message. Please try this method: +Note: Ensure you have updated the YOUR_APP_URL in each respective file before running these commands. Your test results will be displayed on the terminal and can also be viewed in detail on the [App Automation Dashboard](https://appautomation.lambdatest.com/). -1. Navigate to the corresponding directory based on your app. +## Troubleshooting -```bash -cd android -``` -2. Refresh the gem bundles through given command +1. Ruby 3.4 ArgumentError (String to Symbol) -```bash -gem uninstall -aIx -``` -3. Re-install the gems required + If you encounter an ArgumentError stating "String cannot be converted to Symbol," it is because Ruby 3.4 requires explicit symbols for the driver initialization keys. Update your initialization to include the :caps and :appium_lib symbols exactly as shown below: ```bash -gem install appium_lib -v 10.6.0 -gem install ffi +@appium_driver = Appium::Driver.new({ + :caps => caps, + :appium_lib => { :server_url => server_url } +}, true) ``` -4. Now try running the corresponding automation script for your app. -```bash -ruby android-sample.rb -``` +2. Gem Installation Issues -**Info:** Your test results would be displayed on the test console (or command-line interface if you are using terminal/cmd) and on the :link: [LambdaTest App Automation Dashboard](https://appautomation.lambdatest.com/build). + If you encounter an error like No such file or directory @ rb_sysopen during gem installation, you can resolve it by using administrator privileges or ensuring the directory exists: + + - macOS/Linux: Use sudo gem install appium_lib -v 10.6.0. -### Troubleshooting + - Windows: Open Command Prompt as Administrator and run gem install appium_lib -v 10.6.0. -If you encounter an issue where the gem installation fails with an error like `No such file or directory @ rb_sysopen`, you can resolve it by creating the required directory, setting up a custom gem path, or installing with administrator privileges. +3. W3C Protocol Compatibility -#### Option 1: Create the Missing Directory - -**macOS/Linux:** -Run the following command to create the required directory structure: -```bash -mkdir -p ~/.local/share/gem/ruby//cache -``` -**Windows:** -```bash -mkdir -p %USERPROFILE%\.gem\ruby\\cache -``` -#### Option 2: Set a Custom GEM Path -**macOS/Linux:** -```bash -export GEM_HOME=$HOME/gems -export PATH=$HOME/gems/bin:$PATH -gem install appium_lib -v 10.6.0 -``` -**Windows:** -```bash -set GEM_HOME=%USERPROFILE%\gems -set PATH=%USERPROFILE%\gems\bin;%PATH% -gem install appium_lib -v 10.6.0 -``` -#### Option 3: Install with Administrator Privileges -**macOS/Linux:** -```bash -sudo gem install appium_lib -v 10.6.0 -``` -**Windows:** -Run Command Prompt as Administrator, then: -```bash -gem install appium_lib -v 10.6.0 -``` + Ensure your capabilities object includes the :w3c => true option and wraps custom LambdaTest options inside the "lt:options" key to stay compatible with modern Appium standards. ## Additional Links @@ -298,13 +235,13 @@ gem install appium_lib -v 10.6.0 - [How to test locally hosted apps](https://www.lambdatest.com/support/docs/testing-locally-hosted-pages/) - [How to integrate LambdaTest with CI/CD](https://www.lambdatest.com/support/docs/integrations-with-ci-cd-tools/) -## Documentation & Resources :books: - +## Documentation & Resources 📚 + Visit the following links to learn more about LambdaTest's features, setup and tutorials around test automation, mobile app testing, responsive testing, and manual testing. -* [LambdaTest Documentation](https://www.lambdatest.com/support/docs/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-ruby) -* [LambdaTest Blog](https://www.lambdatest.com/blog/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-ruby) -* [LambdaTest Learning Hub](https://www.lambdatest.com/learning-hub/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-ruby) + - [LambdaTest Documentation](https://www.lambdatest.com/support/docs/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-ruby) + - [LambdaTest Blog](https://www.lambdatest.com/blog/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-ruby) + - [LambdaTest Learning Hub](https://www.lambdatest.com/learning-hub/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-ruby) ## LambdaTest Community :busts_in_silhouette: diff --git a/android/android-sample.rb b/android/android-sample.rb index a9d787a..6c04813 100644 --- a/android/android-sample.rb +++ b/android/android-sample.rb @@ -1,51 +1,51 @@ require 'rubygems' require 'appium_lib' -username= ENV["LT_USERNAME"] || "LT_Username" #Enter your username here -accessToken= ENV["LT_ACCESS_KEY"] || "LT_AccessKey" #Enter your Access Key here +username= ENV["LT_USERNAME"] || "LT_Username" # Enter your username here +accessToken= ENV["LT_ACCESS_KEY"] || "LT_AccessKey" # Enter your Access Key here -caps = { - "lt:options" => { - :deviceName => "Pixel 6", +caps = { + "lt:options" => { + :deviceName => "Galaxy S24", :platformName => "Android", - :platformVersion => "13", + :platformVersion => "14", :build => "Ruby Vanilla - Android", :name => "Ruby Android Test", :isRealMobile => true, :queueTimeout => 300, - :app => "lt://proverbial-android", #Enter the App URL here + :app => "lt://proverbial-android", # Enter the App URL here :w3c => true }, :platformName => "Android" } +# The fix is here: Changed 'caps' to :caps and 'appium_lib' to :appium_lib appium_driver = Appium::Driver.new({ - 'caps' => caps, - 'appium_lib' => { + :caps => caps, + :appium_lib => { :server_url => "https://"+username+":"+accessToken+"@mobile-hub.lambdatest.com/wd/hub" - }},true) + }}, true) - driver = appium_driver.start_driver +driver = appium_driver.start_driver - wait = Selenium::WebDriver::Wait.new(:timeout => 30) - el1 = driver.find_element(:id, "com.lambdatest.proverbial:id/color") - el1.click - el2 = driver.find_element(:id, "com.lambdatest.proverbial:id/geoLocation") - el2.click - sleep(5) - driver.back - el3 = driver.find_element(:id, "com.lambdatest.proverbial:id/Text") - el3.click - el4 = driver.find_element(:id, "com.lambdatest.proverbial:id/notification") - el4.click - el5 = driver.find_element(:id, "com.lambdatest.proverbial:id/toast") - el5.click - el6 = driver.find_element(:id, "com.lambdatest.proverbial:id/speedTest") - el6.click - sleep(10) - driver.back - - puts "Found results - Test Passed" +wait = Selenium::WebDriver::Wait.new(:timeout => 30) +el1 = driver.find_element(:id, "com.lambdatest.proverbial:id/color") +el1.click +el2 = driver.find_element(:id, "com.lambdatest.proverbial:id/geoLocation") +el2.click +sleep(5) +driver.back +el3 = driver.find_element(:id, "com.lambdatest.proverbial:id/Text") +el3.click +el4 = driver.find_element(:id, "com.lambdatest.proverbial:id/notification") +el4.click +el5 = driver.find_element(:id, "com.lambdatest.proverbial:id/toast") +el5.click +el6 = driver.find_element(:id, "com.lambdatest.proverbial:id/speedTest") +el6.click +sleep(10) +driver.back - - driver.quit +puts "Found results - Test Passed" + +driver.quit \ No newline at end of file