Monday, May 25, 2020

How to run Selenium automation script on Mac Machine Chrome Browser


How to run Selenium automation script on Mac Machine Chrome Browser


Lets understand how to run selenium script on Mac machine chrome browser:


Running selenium script on Mac chrome browser and Windows chrome browser, there is difference in assigning the chromedrive path in script.


in Mac, we need to store the chromedriver in /usr/local/bin and no need to assign the path in system.setproperty command.


However, in Windows we need to assign the path of the chromedriver in system.setproperty command then only it works other wise we will see the chromedriver not found exception


Prerequisites:

 

Create maven project. In case you are new to maven project creation follow this post How to create maven project for automation

 

Note: in the above post I’m using Maven project just to make easy for adding selenium decencies. you are free to follow your own approach

 

Steps:

 

 1. Open the below link

 

           http://chromedriver.storage.googleapis.com/index.html

 

 2. Click on the latest version of chromedriver

 

 3. Click on chromedriver_mac64.zip link and It will download to your  machine

 

 4. Unzip the chromedriver_mac64.zip file

 

 5. Add chromedriver to /usr/local/bin location on your mac



 

 6. Open the terminal and enter below command:

 

    cp chromedriver /usr/local/bin

 

 7. Use below code in your eclipse and execute it

 

package Appium.MobileAutomation;

 

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.testng.annotations.AfterClass;

import org.testng.annotations.BeforeClass;

import org.testng.annotations.Test;

 

public class Example {

 

 public WebDriver driver;

 

  @Test

  public void openMyBlog() throws InterruptedException {

 driver.get("https://mahantesh-hadimani.blogspot.com/");

 driver.findElement(By.xpath("//li/a[contains(text(),'Appium Tutorial')]")).click();

 Thread.sleep(50000);

 

  }

 

  @BeforeClass

  public void beforeClass() {

  

    driver = new ChromeDriver();

  

  }

 

  @AfterClass

  public void afterClass() {

   driver.quit();

  }

 

}


Console Log output:


 WARNING: An illegal reflective access operation has occurred

WARNING: Illegal reflective access by org.testng.xml.XMLParser (file:/Users/mahanteshhadimani/.m2/repository/org/testng/testng/6.9.13.6/testng-6.9.13.6.jar) to constructor com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl()

WARNING: Please consider reporting this to the maintainers of org.testng.xml.XMLParser

WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations

WARNING: All illegal access operations will be denied in a future release

[TestNG] Running:

  /private/var/folders/28/bnw3p1vs3kx08zs6bq84sj3w0000gn/T/testng-eclipse-1490184378/testng-customsuite.xml


Starting ChromeDriver 83.0.4103.39 (ccbf011cb2d2b19b506d844400483861342c20cd-refs/branch-heads/4103@{#416}) on port 25393

Only local connections are allowed.

Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.

ChromeDriver was started successfully.

May 25, 2020 2:25:12 PM org.openqa.selenium.remote.ProtocolHandshake createSession

INFO: Detected dialect: W3C

[Utils] Attempting to create /Users/mahanteshhadimani/Appium/MobileAutomation/test-output/Default suite/Default test.xml

[Utils]   Directory /Users/mahanteshhadimani/Appium/MobileAutomation/test-output/Default suite exists: true

[Utils] Attempting to create /Users/mahanteshhadimani/Appium/MobileAutomation/test-output/Default suite/Default test0.xml

[Utils]   Directory /Users/mahanteshhadimani/Appium/MobileAutomation/test-output/Default suite exists: true

PASSED: openMyBlog


===============================================

    Default test

    Tests run: 1, Failures: 0, Skips: 0

===============================================



===============================================

Default suite

Total tests run: 1, Failures: 0, Skips: 0


 

 

 

 

No comments:

Post a Comment

If any suggestions or issue, please provide