Run Selenium automation tests on LambdaTest cloud grid
Perform automation testing on 3000+ real desktop and mobile devices online.
package com.seleliumDemo;
import java.io.File;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
public class SeleniumAmazon {
private File pathToBinary;
private FirefoxBinary firefoxBinary;
private FirefoxProfile firefoxProfile;
private WebDriver driver;
@SuppressWarnings("deprecation")
public SeleniumAmazon() {
System.setProperty("webdriver.gecko.driver", "D:\\install\\webdriver\\geckodriver.exe");
// å®è£
è·¯å¾
this.pathToBinary = new File("D:\\Mozilla Firefox\\firefox.exe");
this.firefoxBinary = new FirefoxBinary(pathToBinary);
this.firefoxProfile = new FirefoxProfile();
this.driver = new FirefoxDriver(firefoxBinary, firefoxProfile);
}
public static void main(String[] args) {
String url = "https://login.aliexpress.com/?flag=1&return_url=http%3A%2F%2Fmyae.aliexpress.com%2Fseller%2Findex.htm%3Fspm%3D2114.11010108.1000001.4.464431423RBRaD";
new SeleniumAmazon().getTest(url);
}
public void getTest(String url) {
driver.get(url);
WebElement jfram = driver.findElement(By.tagName("iframe"));
//WebElement name = driver.findElement(By.tagName("iframe")).findElement(By.xpath("//input[@id='fm-login-id']"));
System.out.println(jfram.toString());
driver.close();
}
}
package com.test.firefox;
import java.io.File;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
public class selerun {
public WebDriver globalDriver;
public void tc1_selenium() {
try {
String driverPath = "E:\\AllInstallablesEXE\\OpenSource\\AutomationTesting\\Selenium\\geckodriver-v0.18.0-win32\\";
File file = new File("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
FirefoxBinary fbinary = new FirefoxBinary(file);
ProfilesIni profiles = new ProfilesIni();
FirefoxProfile fp = profiles.getProfile("Selenium");
System.setProperty("webdriver.gecko.driver", driverPath + "geckodriver.exe");
globalDriver = new FirefoxDriver(fbinary, fp);
globalDriver.manage().window().maximize();
globalDriver.get("https://dev23478.service-now.com/");
} catch (Exception e) {
System.out.println("Failure in initializing Firefox Driver: " + e.toString());
}
}
}
package Scraper;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import org.joda.time.DateTime;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import Property.PropertyStructure;
public class HolidayLettingScraper {
WebDriver driver;
PropertyStructure property;
public HolidayLettingScraper(PropertyStructure property){
this.property = property;
}
public void scrape() throws Exception{
if (property.holidayletting_name==null || property.holidayletting_name.equals(""))
return;
scrapeCalendarData();
updateAvailablity();
}
private void scrapeCalendarData() throws Exception {
try{
ProfilesIni profilesIni = new ProfilesIni();
FirefoxProfile profile = profilesIni.getProfile("default");
profile.setAssumeUntrustedCertificateIssuer(false);
// final File firefoxPath = new File(System.getProperty(
// "lmportal.deploy.firefox.path", "/usr/bin/firefox"));
//
// if (firefoxPath.exists()){
// String Xport = System.getProperty(
// "lmportal.xvfb.id", ":1");
// FirefoxBinary firefoxBinary = new FirefoxBinary(firefoxPath);
// firefoxBinary.setEnvironmentProperty("DISPLAY", Xport);
// this.driver = new FirefoxDriver(firefoxBinary, profile);
// } else{
this.driver = new FirefoxDriver(profile);
// }
// this.driver = new HtmlUnitDriver();
String baseUrl = "https://www.holidaylettings.co.uk/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get(baseUrl + "/");
driver.get(baseUrl + "content/login");
// driver.findElement(By.xpath("(//a[contains(text(),'Owner login')])[2]")).click();
driver.findElement(By.id("ownerId")).clear();
driver.findElement(By.id("ownerId")).sendKeys("[email protected]");
driver.findElement(By.id("ownerPassword")).clear();
driver.findElement(By.id("ownerPassword")).sendKeys("samiul123");
driver.findElement(By.xpath("//div[@id='ownerLoginForm']/button")).click();
Thread.sleep(5000);
driver.findElement(By.linkText("Properties")).click();
Thread.sleep(1000);
driver.findElement(By.linkText("Update calendar")).click();
driver.findElement(By.id("calendarContainer"));
int randomtry = new Random().nextInt((10 - 5) + 1) + 5;
for (int i =0; i <randomtry; i++){
driver.findElement(By.cssSelector("span.ui-selectmenu-status")).click();
driver.findElement(By.xpath("//a[contains(text(),'"+property.holidayletting_name+"')]")).click();
Thread.sleep(5000);
}
driver.findElement(By.id("calendarContainer"));
printToFile(driver.getPageSource());
driver.quit();
} catch (Exception e){
e.printStackTrace();
driver.quit();
throw new Exception();
}
}
private void printToFile(String s) throws IOException{
String localFileName = "/tmp/holidayletting.data";
File f = new File(localFileName);
if (f.exists()) f.delete();
FileWriter fw = new FileWriter(localFileName);
PrintWriter pw = new PrintWriter(fw);
String[] tmp = s.split("\\n");
for (int i =0; i < tmp.length;i++){
if (tmp[i].contains("data-cell-date")){
String p1 = tmp[i].split("class=")[0];
p1 = p1.split("\"")[1];
p1 = p1.trim();
String p2 = tmp[i].split("class=")[1];
p2 = p2.split(">")[0];
p2 = p2.replace("\"", "");
p2 = p2.trim();
if (p2.equals("ab") || p2.equals("ah") || p2.equals("b") || p2.equals("h") || p2.equals("rb") || p2.equals("rh") || p2.equals("hb") || p2.equals("bh") )
pw.println(p1 + " " + p2);
}
}
pw.close();
fw.close();
}
private void updateAvailablity() throws IOException, ParseException{
FileReader fr = new FileReader("/tmp/holidayletting.data");
BufferedReader br = new BufferedReader(fr);
String line = "";
while ((line = br.readLine())!= null){
line = line.split(" ")[0];
SimpleDateFormat dt = new SimpleDateFormat("dd/MM/yyyy");
Date d = dt.parse(line);
DateTime date = new DateTime(d);
if (!(date.plusDays(1)).isBefore(System.currentTimeMillis())){
property.add_HolidayLetting_Availablity(date.toString().split("T")[0]);
System.out.println(date.toString().split("T")[0]);
}
}
br.close();
fr.close();
}
}
Accelerate Your Automation Test Cycles With LambdaTest
Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.