Ejemplo n.º 1
0
def login():
    '''
    Fonction permettant se récupérer le cookie de session après une connexion via selenium
    '''

    firefoxOptions = FirefoxOptions()
    #firefoxOptions.addArguments("--window-size=1920,1080")
    #firefoxOptions.addArguments("--disable-gpu")
    #firefoxOptions.addArguments("--disable-extensions")
    #firefoxOptions.addArguments("--proxy-server='direct://'")
    #firefoxOptions.addArguments("--proxy-bypass-list=*")
    #firefoxOptions.addArguments("--start-maximized")
    firefoxOptions.addArguments("--headless")
    webDriver = FirefoxDriver(firefoxOptions)

    webDriver.get(URL_LOGIN)

    timeOut = 3
    waiter = WebDriverWait(webDriver, timeOut)

    waiter.until(ExpectedConditions.visibilityOfElement(By.id("login-form")))
    webDriver.findElement(By.name("email")).sendKeys("*****@*****.**")
    webDriver.findElement(By.name("pass")).sendKeys("123")
    webDriver.findElement(By.name("login-button")).click()

    waiter.until(ExpectedConditions.visibilityOfElement(By.id("welcome-page")))

    GlobalVariables.setGlobalCustomVar(
        COOKIE, str(webDriver.manage().getCookieNamed(COOKIE_NAME).getValue()))
Ejemplo n.º 2
0
 def __init__(self, queue):
     super(DriverThread, self).__init__()
     self.queue = queue
     proxyServer = 'localhost:8080'
     proxy = Proxy()
     proxy.setHttpProxy(proxyServer)
     proxy.setSslProxy(proxyServer)
     capabilities = DesiredCapabilities()
     capabilities.setCapability(CapabilityType.PROXY, proxy)
     self.driver = FirefoxDriver(capabilities)
Ejemplo n.º 3
0
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public


class Book {
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
System.setProperty("webdriver.gecko.driver", "E:\\Automation\\sagar\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("http://nepalinn.com/search/result");

Thread.sleep(5000);

driver.findElement(By.xpath("//*[@name = 'submit_search']")).click();

Thread.sleep(4000);

WebElement text1 = driver.findElement(By.xpath(".//*[text()='Hotel New Solitary Lodge']"));

String text2 = driver.findElement(By.xpath(".//*[text()='Hotel New Solitary Lodge']")).getText();
System.out.println(text2);
String Hotel_name = "HOTEL NEW SOLITARY LODGE";
if (text2.equals(Hotel_name))
{

driver.findElement(By.xpath("//*[@href= 'http://nepalinn.com/hotel_new_solitary_lodge']//button[text()='Book']")).click();
Ejemplo n.º 4
0
 def open_browser(self, url, browser):
     #self._logger.error('open_browser(' + url + ', ' + browser +')')
     self.__firefoxDriver=FirefoxDriver()
     self.__firefoxDriver.get(url)
def doLogin(helper):
    firefoxOptions = FirefoxOptions()
    firefoxOptions.addArguments("--window-size=1920,1080");
    firefoxOptions.addArguments("--disable-gpu");
    firefoxOptions.addArguments("--disable-extensions");		
    firefoxOptions.addArguments("--proxy-server='direct://'");
    firefoxOptions.addArguments("--proxy-bypass-list=*");
    firefoxOptions.addArguments("--start-maximized");
    firefoxOptions.addArguments("--headless");
    webDriver = FirefoxDriver(firefoxOptions);

    # generate state and nonce
    state = generateRandomAlphanumericString(20);
    nonce = generateRandomAlphanumericString(20);
    print "state:"+state;
    print "nonce:"+nonce;    

    #------------getting login page from keycloak------------
    loginUrl = KEYCLOAK_BASE_URL+"/realms/"+KEYCLOAK_REALM+"/protocol/openid-connect/auth?client_id=app-angular2&redirect_uri="+ENCODED_APP_ANGULAR_URL+"%2F&state="+state+"&nonce="+nonce+"&response_mode=fragment&response_type=code&scope=openid";
    print("loginUrl:"+loginUrl);
    webDriver.get(loginUrl);

    # we wait until the username element is visible
    timeoutInSeconds = 10;
    wait = WebDriverWait(webDriver, timeoutInSeconds); 
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("username")));

    loginEle = webDriver.findElement(By.name("username"));
    formEle = webDriver.findElement(By.id("kc-form-login"));

    # gathering all the information to make the next http request
    formActionUrl = formEle.getAttribute("action");
    formBody = "username="******"&password="******"&credentialId="
    
    authSessionIdLegacyCookieValue = webDriver.manage().getCookieNamed(AUTH_SESSION_ID_LEGACY_COOKIE_NAME).getValue();
    print "authSessionIdLegacyCookieValue: " + authSessionIdLegacyCookieValue;
    kcRestartCookieValue = webDriver.manage().getCookieNamed(KC_RESTART_COOKIE_NAME).getValue();
    print "kcRestartCookieValue: " + kcRestartCookieValue;
    
    authSessionIdLegacyCookie = HttpCookie(AUTH_SESSION_ID_LEGACY_COOKIE_NAME, authSessionIdLegacyCookieValue);
    kcRestartCookie = HttpCookie(KC_RESTART_COOKIE_NAME, kcRestartCookieValue);
    cookies = [authSessionIdLegacyCookie, kcRestartCookie];
    #-----------------------------------------------------

    #------------submitting login credentials to keycloak------------
    returnedMsg = callPost(formActionUrl, formBody, {}, cookies, "application/x-www-form-urlencoded", helper);
    
    keyCloakIdentityLegacyCookieValue = returnedMsg.getResponseHeader().getHeader(KEYCLOAK_IDENTITY_LEGACY_COOKIE_NAME)
    keyCloakSessionLegacyCookieValue = returnedMsg.getResponseHeader().getHeader(KEYCLOAK_SESSION_LEGACY_COOKIE_NAME);

    # we will get a redirect response whose url in the 'location' header we will need to call manually below to get the token
    # we cannot use selenium at this stage as it will do auto redirect and we will miss the information returned by the redirect response
    location = returnedMsg.getResponseHeader().getHeader("Location");
    print "location: " + location;
    codeQueryParamValue = getUrlQueryParamValue(location, "code");
    print("code:" + codeQueryParamValue);
    
    tokenUrl = KEYCLOAK_BASE_URL+"/realms/"+KEYCLOAK_REALM+"/protocol/openid-connect/token"
    formBody = "code="+codeQueryParamValue+"&grant_type=authorization_code&client_id=app-angular2&redirect_uri="+ENCODED_APP_ANGULAR_URL+"%2F";
    keyCloakIdentityLegacyCookie = HttpCookie(KEYCLOAK_IDENTITY_LEGACY_COOKIE_NAME, keyCloakIdentityLegacyCookieValue);
    keyCloakSessionLegacyCookie = HttpCookie(KEYCLOAK_SESSION_LEGACY_COOKIE_NAME, keyCloakSessionLegacyCookieValue);
    cookies = [authSessionIdLegacyCookie, keyCloakIdentityLegacyCookie, keyCloakSessionLegacyCookie];
    #-----------------------------------------------------

    #-----------calling the url in the 'location' header to get the access token-----------
    returnedMsg = callPost(tokenUrl, formBody, {}, cookies, "application/x-www-form-urlencoded", helper);
    
    authenticatedJsonResponseObject = json.loads(str(returnedMsg.getResponseBody()));
    accessToken = authenticatedJsonResponseObject.get("access_token");
    accessTokenExpiryInSeconds = authenticatedJsonResponseObject.get("expires_in");
    print "accessToken:"+str(accessToken);
    print "accessTokenExpiryInSeconds:"+str(accessTokenExpiryInSeconds);
    return dict({"accessToken": accessToken, "accessTokenExpiryInSeconds": accessTokenExpiryInSeconds})
Ejemplo n.º 6
0
def getFirefox():
    try:    
        driver = FirefoxDriver()
    except:
        driver = None;
    return driver
Ejemplo n.º 7
0
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class SSLExample {
	
	private WebDriver driver;

	@BeforeClass
	public void setUp() {
		//Creating new Firefox profile
		FirefoxProfile profile = new FirefoxProfile();
		profile.setAcceptUntrustedCertificates(true); 
		profile.setAssumeUntrustedCertificateIssuer(false);
		driver = new FirefoxDriver(profile); 
		driver.manage().window().maximize();
	}
	
	@Test
	public void openApplication() {
		System.out.println("Navigating application");
		driver.get("https://cacert.org/");
		WebElement headingEle = driver.findElement(By.cssSelector(".story h3"));
		//Validate heading after accepting untrusted connection
		String expectedHeading = "Are you new to CAcert?";
		Assert.assertEquals(headingEle.getText(), expectedHeading);
	}
	
	@AfterClass
	public void tearDown() {