Skip to main content
deleted 13 characters in body
Source Link
protected static WebDriver driver;

@Test
public static void ChromeTestLighning() throwInterruptedException {
    
    //basic setup steps to kick off URL in  Chrome
    driver =  new ChromeDriver();
    driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS );
    driver.manage().timeouts().pageLoadTimeout(100, TimeUnit.SECONDS);
    driver.get("https://login.salesforce.com");
    driver.manage().window().maximize();
    
    //login to Salesforce
    driver.findElement(By.cssSelector("#username")).sendKeys("[email protected]""yourusername");
    driver.findElement(By.cssSelector("#password")).sendKeys("Ashish_123""yourpassword");
    driver.findElement(By.cssSelector("#Login")).click();
    
    // Basic clicks in new navigation to Salesforce Lightning
    driver.findElement(By.xpath("//nav[contains(@class,'appLauncher')]//button")).click();
    ((JavascriptExecutor) driver).executeScript(     "arguments[0].click();",     driver.findElement(By.xpath("//button[text()='View All']")));
    ((JavascriptExecutor) driver).executeScript(     "arguments[0].click();",     driver.findElement(By.xpath("//a[@data-label='Opportunities']")));
    ((JavascriptExecutor) driver).executeScript(     "arguments[0].click();",     driver.findElement(By.xpath("//span[@class='slds-truncate'][contains(text(),'Opportunities')]")));
    ((JavascriptExecutor) driver).executeScript(     "arguments[0].click();",     driver.findElement(By.xpath("//div[@class='slds-truncate']")) );
   
    // Opportunity creation in Lightning
    driver.findElement(By.cssSelector("input[id$='a']")).sendKeys("23");
    driver.findElement(By.xpath("//div[@class='uiInput uiInputCheckbox uiInput--default uiInput--checkbox']//input")).click();
    driver.findElement(By.xpath("//a[@class='datePicker-openIcon display']")).click();
    driver.findElement(By.xpath("//button[@class='today slds-button slds-align_absolute-center slds-text-link']")).click();
    driver.findElement(By.xpath("//div[contains(@class,'full forcePageBlock forceRecordLayout')]//div[1]//div[1]//div[1]//div[3]//div[1]//div[1]//div[1]//div[1]//input[1]")).sendKeys("Third Opp");
    driver.findElement(By.xpath("//div[@class='uiMenu uiInput uiInputSelect forceInputPicklist uiInput--default uiInput--select']//div[@class='uiPopupTrigger']//div//div//a[@class='select']")).click();
    driver.findElement(By.xpath("//a[contains(text(),'Negotiation')]")).click();
    driver.findElement(By.xpath("//button[@class='slds-button slds-button--neutral uiButton--brand uiButton forceActionButton']//span[contains(@class,'label bBody')]")).click();
    String str = driver.getCurrentUrl();
    System.out.println(str);
    
    //Stop the browser to close before you can see things went fine.
    Thread.sleep(20000);
    driver.quit();         
}
protected static WebDriver driver;

@Test
public static void ChromeTestLighning() throwInterruptedException {
    
    //basic setup steps to kick off URL in  Chrome
    driver =  new ChromeDriver();
    driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS );
    driver.manage().timeouts().pageLoadTimeout(100, TimeUnit.SECONDS);
    driver.get("https://login.salesforce.com");
    driver.manage().window().maximize();
    
    //login to Salesforce
    driver.findElement(By.cssSelector("#username")).sendKeys("[email protected]");
    driver.findElement(By.cssSelector("#password")).sendKeys("Ashish_123");
    driver.findElement(By.cssSelector("#Login")).click();
    
    // Basic clicks in new navigation to Salesforce Lightning
    driver.findElement(By.xpath("//nav[contains(@class,'appLauncher')]//button")).click();
    ((JavascriptExecutor) driver).executeScript(     "arguments[0].click();",     driver.findElement(By.xpath("//button[text()='View All']")));
    ((JavascriptExecutor) driver).executeScript(     "arguments[0].click();",     driver.findElement(By.xpath("//a[@data-label='Opportunities']")));
    ((JavascriptExecutor) driver).executeScript(     "arguments[0].click();",     driver.findElement(By.xpath("//span[@class='slds-truncate'][contains(text(),'Opportunities')]")));
    ((JavascriptExecutor) driver).executeScript(     "arguments[0].click();",     driver.findElement(By.xpath("//div[@class='slds-truncate']")) );
   
    // Opportunity creation in Lightning
    driver.findElement(By.cssSelector("input[id$='a']")).sendKeys("23");
    driver.findElement(By.xpath("//div[@class='uiInput uiInputCheckbox uiInput--default uiInput--checkbox']//input")).click();
    driver.findElement(By.xpath("//a[@class='datePicker-openIcon display']")).click();
    driver.findElement(By.xpath("//button[@class='today slds-button slds-align_absolute-center slds-text-link']")).click();
    driver.findElement(By.xpath("//div[contains(@class,'full forcePageBlock forceRecordLayout')]//div[1]//div[1]//div[1]//div[3]//div[1]//div[1]//div[1]//div[1]//input[1]")).sendKeys("Third Opp");
    driver.findElement(By.xpath("//div[@class='uiMenu uiInput uiInputSelect forceInputPicklist uiInput--default uiInput--select']//div[@class='uiPopupTrigger']//div//div//a[@class='select']")).click();
    driver.findElement(By.xpath("//a[contains(text(),'Negotiation')]")).click();
    driver.findElement(By.xpath("//button[@class='slds-button slds-button--neutral uiButton--brand uiButton forceActionButton']//span[contains(@class,'label bBody')]")).click();
    String str = driver.getCurrentUrl();
    System.out.println(str);
    
    //Stop the browser to close before you can see things went fine.
    Thread.sleep(20000);
    driver.quit();         
}
protected static WebDriver driver;

@Test
public static void ChromeTestLighning() throwInterruptedException {
    
    //basic setup steps to kick off URL in  Chrome
    driver =  new ChromeDriver();
    driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS );
    driver.manage().timeouts().pageLoadTimeout(100, TimeUnit.SECONDS);
    driver.get("https://login.salesforce.com");
    driver.manage().window().maximize();
    
    //login to Salesforce
    driver.findElement(By.cssSelector("#username")).sendKeys("yourusername");
    driver.findElement(By.cssSelector("#password")).sendKeys("yourpassword");
    driver.findElement(By.cssSelector("#Login")).click();
    
    // Basic clicks in new navigation to Salesforce Lightning
    driver.findElement(By.xpath("//nav[contains(@class,'appLauncher')]//button")).click();
    ((JavascriptExecutor) driver).executeScript(     "arguments[0].click();",     driver.findElement(By.xpath("//button[text()='View All']")));
    ((JavascriptExecutor) driver).executeScript(     "arguments[0].click();",     driver.findElement(By.xpath("//a[@data-label='Opportunities']")));
    ((JavascriptExecutor) driver).executeScript(     "arguments[0].click();",     driver.findElement(By.xpath("//span[@class='slds-truncate'][contains(text(),'Opportunities')]")));
    ((JavascriptExecutor) driver).executeScript(     "arguments[0].click();",     driver.findElement(By.xpath("//div[@class='slds-truncate']")) );
   
    // Opportunity creation in Lightning
    driver.findElement(By.cssSelector("input[id$='a']")).sendKeys("23");
    driver.findElement(By.xpath("//div[@class='uiInput uiInputCheckbox uiInput--default uiInput--checkbox']//input")).click();
    driver.findElement(By.xpath("//a[@class='datePicker-openIcon display']")).click();
    driver.findElement(By.xpath("//button[@class='today slds-button slds-align_absolute-center slds-text-link']")).click();
    driver.findElement(By.xpath("//div[contains(@class,'full forcePageBlock forceRecordLayout')]//div[1]//div[1]//div[1]//div[3]//div[1]//div[1]//div[1]//div[1]//input[1]")).sendKeys("Third Opp");
    driver.findElement(By.xpath("//div[@class='uiMenu uiInput uiInputSelect forceInputPicklist uiInput--default uiInput--select']//div[@class='uiPopupTrigger']//div//div//a[@class='select']")).click();
    driver.findElement(By.xpath("//a[contains(text(),'Negotiation')]")).click();
    driver.findElement(By.xpath("//button[@class='slds-button slds-button--neutral uiButton--brand uiButton forceActionButton']//span[contains(@class,'label bBody')]")).click();
    String str = driver.getCurrentUrl();
    System.out.println(str);
    
    //Stop the browser to close before you can see things went fine.
    Thread.sleep(20000);
    driver.quit();         
}
Source Link

Below sharing a script that creates an opportunity in Salesforce lightning. I used some places JavascriptExecutor to click some components in here.

package BaseScripts; import org.testng.annotations.Test; import org.testng.annotations.; import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.; import javax.swing.text.html.HTMLDocument.Iterator; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.ie.InternetExplorerDriver; import org.testng.annotations.Test; import org.testng.annotations.; import org.testng.annotations.;

public class LightningTest {

protected static WebDriver driver;

@Test
public static void ChromeTestLighning() throwInterruptedException {
    
    //basic setup steps to kick off URL in  Chrome
    driver =  new ChromeDriver();
    driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS );
    driver.manage().timeouts().pageLoadTimeout(100, TimeUnit.SECONDS);
    driver.get("https://login.salesforce.com");
    driver.manage().window().maximize();
    
    //login to Salesforce
    driver.findElement(By.cssSelector("#username")).sendKeys("[email protected]");
    driver.findElement(By.cssSelector("#password")).sendKeys("Ashish_123");
    driver.findElement(By.cssSelector("#Login")).click();
    
    // Basic clicks in new navigation to Salesforce Lightning
    driver.findElement(By.xpath("//nav[contains(@class,'appLauncher')]//button")).click();
    ((JavascriptExecutor) driver).executeScript(     "arguments[0].click();",     driver.findElement(By.xpath("//button[text()='View All']")));
    ((JavascriptExecutor) driver).executeScript(     "arguments[0].click();",     driver.findElement(By.xpath("//a[@data-label='Opportunities']")));
    ((JavascriptExecutor) driver).executeScript(     "arguments[0].click();",     driver.findElement(By.xpath("//span[@class='slds-truncate'][contains(text(),'Opportunities')]")));
    ((JavascriptExecutor) driver).executeScript(     "arguments[0].click();",     driver.findElement(By.xpath("//div[@class='slds-truncate']")) );
   
    // Opportunity creation in Lightning
    driver.findElement(By.cssSelector("input[id$='a']")).sendKeys("23");
    driver.findElement(By.xpath("//div[@class='uiInput uiInputCheckbox uiInput--default uiInput--checkbox']//input")).click();
    driver.findElement(By.xpath("//a[@class='datePicker-openIcon display']")).click();
    driver.findElement(By.xpath("//button[@class='today slds-button slds-align_absolute-center slds-text-link']")).click();
    driver.findElement(By.xpath("//div[contains(@class,'full forcePageBlock forceRecordLayout')]//div[1]//div[1]//div[1]//div[3]//div[1]//div[1]//div[1]//div[1]//input[1]")).sendKeys("Third Opp");
    driver.findElement(By.xpath("//div[@class='uiMenu uiInput uiInputSelect forceInputPicklist uiInput--default uiInput--select']//div[@class='uiPopupTrigger']//div//div//a[@class='select']")).click();
    driver.findElement(By.xpath("//a[contains(text(),'Negotiation')]")).click();
    driver.findElement(By.xpath("//button[@class='slds-button slds-button--neutral uiButton--brand uiButton forceActionButton']//span[contains(@class,'label bBody')]")).click();
    String str = driver.getCurrentUrl();
    System.out.println(str);
    
    //Stop the browser to close before you can see things went fine.
    Thread.sleep(20000);
    driver.quit();         
}

}