Appium

Setting up Protractor on mobile devices

To run protractor on mobile devices Appium is used as server,

Pre-Requs:
Appium server should be up and running 
Protractor server should be running
Device(Android/iOS) should be connected to PC and accessible through adb

Its above all is Ok, only few changes in conf.js of protractor are required to point its requests appium,

  seleniumAddress: ‘http://localhost:4723/wd/hub’,
    capabilities: {
    platformName: ‘android’,
    deviceName: ‘galaxy s4’,
    browserName: ‘chrome’,
    newCommandTimeout: 60
      },
    baseUrl: ‘http://10.0.2.2:’ + (process.env.HTTP_PORT || ‘8000’),

Some points to understand, 
1. Selenium use port 4444 but to use Appium it should be port 4723 instead of 4444
2. platformName: should be name of env where script will execute, like Andorid/iOS
3. deviceName: should be name of device like s4/iphone 5
4. browserName: should be chrome/safari
5. baseUrl is 10.0.2.2 instead of localhost because it is used to access the localhost of the host machine in the android emulator/device

Sources:
https://github.com/angular/protractor/issues/361
https://github.com/angular/protractor/issues/697
https://github.com/angular/protractor/blob/master/docs/browser-setup.md

Selenium WebDriver – AdvanceUserInteractions API – Move and click on specific coordinates

Moving mouse over specific coordinates and clicking on it.

Actions vActions = new Actions(vDriver);
vActions.moveByOffset(16, 320);
vActions.click();
Action vClickAction = vActions.build();
vClickAction.perform();

  • Working on Desktop Browsers(mostly known) using Selenium WebDriver
  • Working on Mobile Browsers(ChromeDriver, SafariDriver) using Appium 

Selenium WebDriver – Executing JavaScript

If we need to execute javaScript on Selenium WebDriver,

Clicking on WebElement
JavascriptExecutor js = (JavascriptExecutor) vDriver;
js.executeScript(“var InputElements = document.getElementsByTagName(‘button’);”
               + “InputElements[1].click();”);

Another way:
js.executeScript(“var InputElements = document.getElementsByTagName(‘button’);”
                              + “for (i=0; i                              + “{“
                              + “if(InputElements[i].value == ‘‘)” 
                              + “{“
                              + “InputElements[i].click();”
                              + “}”
                              + “}”
                              + “InputElements[1].click();” );

Scrolling to specific WebElement
js.executeScript(“window.scrollTo(“+vElementsList.get(1).getLocation().getX()+”,             “+vElementsList.get(1).getLocation().getY()+”)”);

Loading Alert Pop-up
js.executeScript(“alert(‘hello world’)”);
  • Working on Desktop Browsers(mostly known) using Selenium WebDriver
  • Working on Mobile Browsers(ChromeDriver, SafariDriver) using Appium