Wednesday, October 26, 2016

Running Mobile Web Tests on iOS 10 Device (Simulator) using Appium iOS driver, backed by Apple XCUITest (Xcode 8)


Requirements:
- OS X El Capitan (10.11.6)
- Xcode 8 (with command line tools)
- JDK 1.8
- Node.js v6.5.0 (brew install node)
- appium 1.6.0 (npm install -g appium)
Other appium node_modules (appium-doctor, appium-xcuitest-driver)


As a background and for those familiar with appium, UIAutomation - which was being used by Appium for its previous version of running tests against iOS devices - is already deprecated by Apple.

With version 1.6.0,  Appium has added support to target Apple's new XCUITest framework, which includes support for iOS 10 / Xcode 8.

Here's the github link for appium-xcuitest-driver.

Steps:

- Verify appium installation/setup using the ff command:
$ appium-doctor --ios




- Start appium using the ff command:
$ appium --default-capabilities ios.json

where ios.json:
{
"app":"safari",
"newCommandTimeout":600
}





- Run the following code:

import java.net.MalformedURLException;
import java.net.URL;

import org.apache.log4j.Logger;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

public class AppiumIOS {
 private final static Logger logger = Logger.getLogger(AppiumIOS.class);
 static WebDriver driver;
 
 public static void main(String[] args) throws MalformedURLException, InterruptedException {
  String hubUrl = "http://127.0.0.1:4723/wd/hub";
  String iOSBrowserName = "Safari";
  String iOSDeviceName = "iPhone Simulator";
  String iOSVersion = "10.0";

  DesiredCapabilities capabilities = new DesiredCapabilities();
  capabilities.setCapability("deviceName", iOSDeviceName);
  capabilities.setCapability("platformName", "iOS");
  capabilities.setCapability("platformVersion", iOSVersion);
  capabilities.setCapability("browserName", iOSBrowserName);
  capabilities.setCapability("automationName", "XCUITest");
  driver = new RemoteWebDriver(new URL(hubUrl), capabilities);
  
  String[] searchTerms = new String[] { 
   "Bernard Lago Blogspot", 
   "Bernard Lago Youtube",
   "Bernard Lago Google Plus" 
  };

  for (int i = 0; i < searchTerms.length; i++) {
   googleSearch(searchTerms[i]);
   Thread.sleep(3000);
   getInfoUsingResultIndex(1);  // 1 for the first link, 2 for 2nd etc...
  }
  
  driver.quit();

 }
 
 public static void googleSearch(String searchString) {
  logger.info("Search term: " + searchString);
  driver.navigate().to("https://www.google.com.ph/#q=" + searchString);
 }

 public static void getInfoUsingResultIndex(int index) {
  String firstLinkLocator = String.format("div.g:nth-child(%s) h3.r a", index);
  String firstCiteLocator = String.format("div.g:nth-child(%s) cite", index);
  WebElement firstLink = driver.findElement(By.cssSelector(firstLinkLocator));
  logger.info("First Link URL: "+ driver.findElement(By.cssSelector(firstCiteLocator)).getText());
  logger.info("First link Page Title: " + firstLink.getText());
 }

}

Here's the screenshot of the actual execution.



That's it. Thanks for visiting!

Friday, October 7, 2016

Analyzing free proxies from public websites


Recently,  I've been scraping free proxies from public websites like hidemyass and incloak.

I added another source to the scraper to pull proxies from my-proxy.com and stored the proxies to my local MySQL database.

Here's the table structure:

+------------------+--------------+------+-----+-------------------+----------------+
| Field            | Type         | Null | Key | Default           | Extra          |
+------------------+--------------+------+-----+-------------------+----------------+
| id               | int(11)      | NO   | PRI | NULL              | auto_increment |
| scrape_timestamp | datetime     | YES  |     | CURRENT_TIMESTAMP |                |
| last_update      | varchar(255) | YES  |     | NULL              |                |
| ip_address       | varchar(255) | YES  |     | NULL              |                |
| port             | varchar(255) | YES  |     | NULL              |                |
| country          | varchar(255) | YES  |     | NULL              |                |
| speed            | int(11)      | YES  |     | NULL              |                |
| connection_time  | int(11)      | YES  |     | NULL              |                |
| type             | varchar(255) | YES  |     | NULL              |                |
| anonymity        | varchar(255) | YES  |     | NULL              |                |
| source           | varchar(255) | YES  |     | NULL              |                |
| tested           | tinyint(1)   | YES  |     | NULL              |                |
| verified         | tinyint(1)   | YES  |     | NULL              |                |
| used             | tinyint(1)   | YES  |     | NULL              |                |
| date_used        | datetime     | YES  |     | NULL              |                |
+------------------+--------------+------+-----+-------------------+----------------+

Here's the data gathered after using whatismyipaddress.com for verifying the list.

SELECT t1.source,
       t2.total,
       t1.verified,
       (SELECT Truncate(( t1.verified / t2.total * 100 ) + 0.06, 0)) AS
       percent_working
FROM   (SELECT source,
               Count(*) AS verified
        FROM   proxies
        WHERE  verified = 1
        GROUP  BY source) AS t1
       LEFT JOIN (SELECT source,
                         Count(*) AS total
                  FROM   proxies
                  GROUP  BY source) AS t2
              ON t1.source = t2.source; 



+-----------+-------+----------+-----------------+
| source    | total | verified | percent_working |
+-----------+-------+----------+-----------------+
| hidemyass |   309 |       74 |              24 |
| incloak   |   436 |       78 |              17 |
| my-proxy  |   900 |       55 |               6 |
+-----------+-------+----------+-----------------+

Graph generated here: https://jsfiddle.net/L3vnuyx6/


my-proxy has the highest number of free proxies. It also has the lowest number of verified working proxies.

hidemyass has the highest percentage (verified / total)

incloak has the highest number of verified proxies in terms of count.